From d52895f8048e31d5abf451aa37fdcb3c9035d828 Mon Sep 17 00:00:00 2001 From: Anders Olsson Date: Thu, 23 Jun 2022 07:48:44 +0200 Subject: [PATCH] Remove unused code --- src/history.rs | 181 +------------------------------------------------ 1 file changed, 2 insertions(+), 179 deletions(-) diff --git a/src/history.rs b/src/history.rs index c591532..badb85b 100644 --- a/src/history.rs +++ b/src/history.rs @@ -5,7 +5,7 @@ use crate::{ batch::{self, Batch}, gaussian::Gaussian, player::Player, - sort_time, tuple_gt, tuple_max, BETA, EPSILON, GAMMA, ITERATIONS, MU, P_DRAW, SIGMA, + sort_time, tuple_gt, tuple_max, BETA, GAMMA, MU, P_DRAW, SIGMA, }; #[derive(Clone)] @@ -17,8 +17,6 @@ pub struct HistoryBuilder { gamma: f64, p_draw: f64, online: bool, - epsilon: f64, - iterations: usize, } impl HistoryBuilder { @@ -57,16 +55,6 @@ impl HistoryBuilder { self } - pub fn epsilon(mut self, epsilon: f64) -> Self { - self.epsilon = epsilon; - self - } - - pub fn iterations(mut self, iterations: usize) -> Self { - self.iterations = iterations; - self - } - pub fn build(self) -> History { History { size: 0, @@ -79,8 +67,6 @@ impl HistoryBuilder { gamma: self.gamma, p_draw: self.p_draw, online: self.online, - epsilon: self.epsilon, - iterations: self.iterations, } } } @@ -95,8 +81,6 @@ impl Default for HistoryBuilder { gamma: GAMMA, p_draw: P_DRAW, online: false, - epsilon: EPSILON, - iterations: ITERATIONS, } } } @@ -112,8 +96,6 @@ pub struct History { gamma: f64, p_draw: f64, online: bool, - epsilon: f64, - iterations: usize, } impl Default for History { @@ -129,8 +111,6 @@ impl Default for History { gamma: GAMMA, p_draw: P_DRAW, online: false, - epsilon: EPSILON, - iterations: ITERATIONS, } } } @@ -140,163 +120,6 @@ impl History { HistoryBuilder::default() } - pub fn new( - composition: Vec>>, - results: Vec>, - times: Vec, - weights: Vec>>, - priors: HashMap, - mu: f64, - sigma: f64, - beta: f64, - gamma: f64, - p_draw: f64, - online: bool, - ) -> Self { - assert!( - results.is_empty() || results.len() == composition.len(), - "(length(results) > 0) & (length(composition) != length(results))" - ); - assert!( - times.is_empty() || times.len() == composition.len(), - "length(times) > 0) & (length(composition) != length(times))" - ); - assert!( - weights.is_empty() || weights.len() == composition.len(), - "(length(weights) > 0) & (length(composition) != length(weights))" - ); - - let this_agent = composition - .iter() - .flatten() - .flatten() - .cloned() - .collect::>(); - - let agents = this_agent - .into_iter() - .map(|agent| { - let player = priors - .get(agent) - .cloned() - .unwrap_or_else(|| Player::new(Gaussian::new(mu, sigma), beta, gamma)); - - ( - agent.to_string(), - Agent { - player, - ..Default::default() - }, - ) - }) - .collect::>(); - - let mut this = Self { - size: composition.len(), - batches: Vec::new(), - agents, - time: !times.is_empty(), - mu, - sigma, - beta, - gamma, - p_draw, - online, - epsilon: 0.0, - iterations: 10, - }; - - this.trueskill(composition, results, times, weights, online); - - this - } - - fn trueskill( - &mut self, - composition: Vec>>, - results: Vec>, - times: Vec, - weights: Vec>>, - online: bool, - ) { - let o = if self.time { - sort_time(×, false) - } else { - (0..composition.len()).collect::>() - }; - - let mut i = 0; - let mut last = 0.0; - - while i < self.size { - let mut j = i + 1; - let t = if self.time { times[o[i]] } else { i as u64 + 1 }; - - while self.time && j < self.size && times[o[j]] == t { - j += 1; - } - - let composition = (i..j) - .map(|e| composition[o[e]].clone()) - .collect::>(); - - let results = if results.is_empty() { - Vec::new() - } else { - (i..j).map(|e| results[o[e]].clone()).collect::>() - }; - - let weights = if weights.is_empty() { - Vec::new() - } else { - (i..j).map(|e| weights[o[e]].clone()).collect::>() - }; - - let b = Batch::new( - composition, - results, - weights, - t, - self.p_draw, - &mut self.agents, - ); - - let idx = self.batches.len(); - - self.batches.push(b); - - if online { - let new = 100.0 * (i as f64 / self.size as f64); - - if new != last { - println!("{:.02}%", new); - last = new; - } - - for skill in self.batches[idx].skills.values_mut() { - skill.online = skill.forward; - } - - self.convergence(self.iterations, self.epsilon, false); - } - - let b = &mut self.batches[idx]; - - for a in b.skills.keys() { - let agent = self.agents.get_mut(a).unwrap(); - - agent.last_time = if self.time { t } else { u64::MAX }; - agent.message = b.forward_prior_out(a); - } - - i = j; - } - - if online { - println!("100.00%"); - } - } - fn iteration(&mut self) -> (f64, f64) { let mut step = (0.0, 0.0); @@ -588,7 +411,7 @@ impl History { mod tests { use approx::assert_ulps_eq; - use crate::{Game, Gaussian, Player, BETA, EPSILON, GAMMA, ITERATIONS, MU, P_DRAW, SIGMA}; + use crate::{Game, Gaussian, Player, EPSILON, ITERATIONS, P_DRAW}; use super::*;