Remove warnings and refactor some code
This commit is contained in:
@@ -140,7 +140,7 @@ fn main() {
|
||||
|
||||
chart
|
||||
.plotting_area()
|
||||
.draw(&Polygon::new(band, &color.mix(0.15)))
|
||||
.draw(&Polygon::new(band, color.mix(0.15)))
|
||||
.unwrap();
|
||||
|
||||
chart
|
||||
@@ -152,8 +152,8 @@ fn main() {
|
||||
|
||||
chart
|
||||
.configure_series_labels()
|
||||
.background_style(&WHITE.mix(0.8))
|
||||
.border_style(&BLACK)
|
||||
.background_style(WHITE.mix(0.8))
|
||||
.border_style(BLACK)
|
||||
.draw()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
22
src/batch.rs
22
src/batch.rs
@@ -81,7 +81,7 @@ impl Event {
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
fn within_priors(
|
||||
pub(crate) fn within_priors(
|
||||
&self,
|
||||
online: bool,
|
||||
forward: bool,
|
||||
@@ -283,26 +283,6 @@ impl Batch {
|
||||
.collect::<HashMap<_, _>>()
|
||||
}
|
||||
|
||||
// TODO(anders): Remove this function.
|
||||
pub(crate) fn within_priors(
|
||||
&self,
|
||||
event: usize,
|
||||
online: bool,
|
||||
forward: bool,
|
||||
agents: &HashMap<Index, Agent>,
|
||||
) -> Vec<Vec<Player>> {
|
||||
self.events[event]
|
||||
.teams
|
||||
.iter()
|
||||
.map(|team| {
|
||||
team.items
|
||||
.iter()
|
||||
.map(|item| item.within_prior(online, forward, &self.skills, agents))
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub(crate) fn iteration(&mut self, from: usize, agents: &HashMap<Index, Agent>) {
|
||||
for event in self.events.iter_mut().skip(from) {
|
||||
let teams = event.within_priors(false, false, &self.skills, agents);
|
||||
|
||||
@@ -128,12 +128,12 @@ impl History {
|
||||
for j in (0..self.batches.len() - 1).rev() {
|
||||
for agent in self.batches[j + 1].skills.keys() {
|
||||
self.agents.get_mut(agent).unwrap().message =
|
||||
self.batches[j + 1].backward_prior_out(agent, &mut self.agents);
|
||||
self.batches[j + 1].backward_prior_out(agent, &self.agents);
|
||||
}
|
||||
|
||||
let old = self.batches[j].posteriors();
|
||||
|
||||
self.batches[j].new_backward_info(&mut self.agents);
|
||||
self.batches[j].new_backward_info(&self.agents);
|
||||
|
||||
let new = self.batches[j].posteriors();
|
||||
|
||||
@@ -152,7 +152,7 @@ impl History {
|
||||
|
||||
let old = self.batches[j].posteriors();
|
||||
|
||||
self.batches[j].new_forward_info(&mut self.agents);
|
||||
self.batches[j].new_forward_info(&self.agents);
|
||||
|
||||
let new = self.batches[j].posteriors();
|
||||
|
||||
@@ -164,7 +164,7 @@ impl History {
|
||||
if self.batches.len() == 1 {
|
||||
let old = self.batches[0].posteriors();
|
||||
|
||||
self.batches[0].iteration(0, &mut self.agents);
|
||||
self.batches[0].iteration(0, &self.agents);
|
||||
|
||||
let new = self.batches[0].posteriors();
|
||||
|
||||
@@ -314,7 +314,7 @@ impl History {
|
||||
let b = &mut self.batches[k];
|
||||
|
||||
if k > 0 {
|
||||
b.new_forward_info(&mut self.agents);
|
||||
b.new_forward_info(&self.agents);
|
||||
}
|
||||
|
||||
let intersect = this_agent
|
||||
@@ -363,14 +363,7 @@ impl History {
|
||||
agent.message = b.forward_prior_out(a);
|
||||
}
|
||||
} else {
|
||||
let b = Batch::new(
|
||||
composition,
|
||||
results,
|
||||
weights,
|
||||
t,
|
||||
self.p_draw,
|
||||
&mut self.agents,
|
||||
);
|
||||
let b = Batch::new(composition, results, weights, t, self.p_draw, &self.agents);
|
||||
|
||||
self.batches.insert(k, b);
|
||||
|
||||
@@ -392,7 +385,7 @@ impl History {
|
||||
while self.time && self.batches.len() > k {
|
||||
let b = &mut self.batches[k];
|
||||
|
||||
b.new_forward_info(&mut self.agents);
|
||||
b.new_forward_info(&self.agents);
|
||||
|
||||
let intersect = this_agent
|
||||
.iter()
|
||||
@@ -463,14 +456,14 @@ mod tests {
|
||||
|
||||
let observed = h.batches[1].skills[&a].forward.sigma;
|
||||
let gamma: f64 = 0.15 * 25.0 / 3.0;
|
||||
let expected = (gamma.powi(2) + h.batches[0].posterior(a).sigma.powi(2)).sqrt();
|
||||
let expected = (gamma.powi(2) + h.batches[0].skills[&a].posterior().sigma.powi(2)).sqrt();
|
||||
|
||||
assert_ulps_eq!(observed, expected, epsilon = 0.000001);
|
||||
|
||||
let observed = h.batches[1].posterior(a);
|
||||
|
||||
let p = Game::new(
|
||||
h.batches[1].within_priors(0, false, false, &mut h.agents),
|
||||
h.batches[1].events[0].within_priors(false, false, &h.batches[1].skills, &h.agents),
|
||||
vec![0.0, 1.0],
|
||||
vec![],
|
||||
P_DRAW,
|
||||
|
||||
Reference in New Issue
Block a user