From 2bdd3d9b896932499ed3e496637b6f22f7c0ef57 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Fri, 16 Dec 2022 19:46:01 +0100 Subject: [PATCH] Remove warnings and refactor some code --- examples/atp.rs | 6 +++--- src/batch.rs | 22 +--------------------- src/history.rs | 25 +++++++++---------------- 3 files changed, 13 insertions(+), 40 deletions(-) diff --git a/examples/atp.rs b/examples/atp.rs index 02a1f19..e4027dc 100644 --- a/examples/atp.rs +++ b/examples/atp.rs @@ -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(); } diff --git a/src/batch.rs b/src/batch.rs index 43872c0..9a0db6a 100644 --- a/src/batch.rs +++ b/src/batch.rs @@ -81,7 +81,7 @@ impl Event { .collect::>() } - fn within_priors( + pub(crate) fn within_priors( &self, online: bool, forward: bool, @@ -283,26 +283,6 @@ impl Batch { .collect::>() } - // TODO(anders): Remove this function. - pub(crate) fn within_priors( - &self, - event: usize, - online: bool, - forward: bool, - agents: &HashMap, - ) -> Vec> { - self.events[event] - .teams - .iter() - .map(|team| { - team.items - .iter() - .map(|item| item.within_prior(online, forward, &self.skills, agents)) - .collect::>() - }) - .collect::>() - } - pub(crate) fn iteration(&mut self, from: usize, agents: &HashMap) { for event in self.events.iter_mut().skip(from) { let teams = event.within_priors(false, false, &self.skills, agents); diff --git a/src/history.rs b/src/history.rs index b746b4f..78da71b 100644 --- a/src/history.rs +++ b/src/history.rs @@ -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,