Update example so now it works, and thats, well, good

This commit is contained in:
2022-06-27 10:22:26 +02:00
parent cd1079a811
commit 0633c766a5

View File

@@ -1,29 +1,5 @@
/*
use std::collections::HashMap;
use time::Date; use time::Date;
use trueskill_tt::{History, IndexMap};
use trueskill_tt::{History, PlayerIndex, BETA, MU, P_DRAW};
struct Players(HashMap<String, PlayerIndex>);
impl Players {
fn new() -> Self {
Self(HashMap::new())
}
fn get(&mut self, name: &str) -> PlayerIndex {
if let Some(idx) = self.0.get(name) {
*idx
} else {
let idx = PlayerIndex::new(self.0.len());
self.0.insert(name.to_string(), idx);
idx
}
}
}
fn main() { fn main() {
let mut csv = csv::Reader::open("examples/atp.csv").unwrap(); let mut csv = csv::Reader::open("examples/atp.csv").unwrap();
@@ -34,26 +10,26 @@ fn main() {
let time_format = time::format_description::parse("[year]-[month]-[day]").unwrap(); let time_format = time::format_description::parse("[year]-[month]-[day]").unwrap();
let mut players = Players::new(); let mut index_map = IndexMap::new();
for row in csv.records() { for row in csv.records() {
if &row["double"] == "t" { if &row["double"] == "t" {
let w1_id = players.get(&row["w1_id"]); let w1_id = index_map.get_or_create(&row["w1_id"]);
let w2_id = players.get(&row["w2_id"]); let w2_id = index_map.get_or_create(&row["w2_id"]);
let l1_id = players.get(&row["l1_id"]); let l1_id = index_map.get_or_create(&row["l1_id"]);
let l2_id = players.get(&row["l2_id"]); let l2_id = index_map.get_or_create(&row["l2_id"]);
composition.push(vec![vec![w1_id, w2_id], vec![l1_id, l2_id]]); composition.push(vec![vec![w1_id, w2_id], vec![l1_id, l2_id]]);
} else { } else {
let w1_id = players.get(&row["w1_id"]); let w1_id = index_map.get_or_create(&row["w1_id"]);
let l1_id = players.get(&row["l1_id"]); let l1_id = index_map.get_or_create(&row["l1_id"]);
composition.push(vec![vec![w1_id], vec![l1_id]]); composition.push(vec![vec![w1_id], vec![l1_id]]);
} }
results.push(vec![1, 0]); results.push(vec![1.0, 0.0]);
let time = Date::parse(&row["time_start"], &time_format) let time = Date::parse(&row["time_start"], &time_format)
.unwrap() .unwrap()
@@ -61,68 +37,13 @@ fn main() {
.assume_utc() .assume_utc()
.unix_timestamp(); .unix_timestamp();
times.push(time as f64 / (60 * 60 * 24) as f64); times.push(time as u64 / (60 * 60 * 24));
} }
/* let mut hist = History::builder().sigma(1.6).gamma(0.036).build();
let mut history = History::builder()
.sigma(1.6)
.gamma(0.036)
.priors(priors)
.build::<Time>();
history.add_event(teams: [[a, b], [c]], result: [1, 0], 0.0); hist.add_events(composition, results, times, vec![]);
hist.convergence(10, 0.01, true);
let mut history = History::builder()
.sigma(1.6)
.gamma(0.036)
.priors(priors)
.build::<NoTime>();
history.add_event(teams: [[a, b], [c]], result: [1, 0]);
history.convergence(Ctx::default());
history.convergence(Ctx { epsilon: 1.6, ..Default::default() });
history.convergence(Ctx { epsilon: 1.6, iterations: 10 });
history.convergence().run();
history
.convergence()
.epsilon(1.6)
.run();
history
.convergence()
.epsilon(1.6)
.iterations(10)
.run();
history
.convergence()
.epsilon(1.6)
.iterations(10)
.inspect(|step, i| println!("Iteration {}: step={:?}", i, step))
.run();
*/
let mut h = History::new(
&composition,
&results,
&times,
HashMap::new(),
MU,
1.6,
BETA,
0.036,
P_DRAW,
);
h.epsilon = 0.01;
h.iterations = 10;
h.convergence();
} }
mod csv { mod csv {
@@ -194,8 +115,3 @@ mod csv {
} }
} }
} }
*/
fn main() {
//
}