Initial commit. Basic structure in place, need to implement logic.
This commit is contained in:
56
examples/basic.rs
Normal file
56
examples/basic.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use kickscore as ks;
|
||||
|
||||
fn main() {
|
||||
let mut model = ks::BinaryModel {};
|
||||
|
||||
// Spike's skill does not change over time.
|
||||
let k_spike = ks::kernel::Constant::new(0.5);
|
||||
|
||||
// Tom's skill changes over time, with "jagged" (non-smooth) dynamics.
|
||||
let k_tom = ks::kernel::Exponential::new(1.0, 1.0);
|
||||
|
||||
// Jerry's skill has a constant offset and smooth dynamics.
|
||||
let k_jerry: Vec<Box<dyn ks::Kernel>> = vec![
|
||||
Box::new(ks::kernel::Constant::new(1.0)),
|
||||
Box::new(ks::kernel::Matern52::new(0.5, 1.0)),
|
||||
];
|
||||
|
||||
// Now we are ready to add the items in the model.
|
||||
model.add_item("Spike", k_spike);
|
||||
model.add_item("Tom", k_tom);
|
||||
model.add_item("Jerry", k_jerry);
|
||||
|
||||
// At first, Jerry beats Tom a couple of times.
|
||||
model.observe(&["Jerry"], &["Tom"], 0.0);
|
||||
model.observe(&["Jerry"], &["Tom"], 0.9);
|
||||
|
||||
// Then, Tom beats Spike, and then Jerry.
|
||||
model.observe(&["Tom"], &["Spike"], 1.7);
|
||||
model.observe(&["Tom"], &["Jerry"], 2.1);
|
||||
|
||||
// Finally, Jerry beats Tom, and then Tom + Spike.
|
||||
model.observe(&["Jerry"], &["Tom"], 3.0);
|
||||
model.observe(&["Jerry"], &["Tom", "Spike"], 3.5);
|
||||
|
||||
model.fit(true);
|
||||
|
||||
// We can predict a future outcome...
|
||||
let (p_win, p_los) = model.probabilities(&[&"Jerry"], &[&"Tom"], 4.0);
|
||||
println!(
|
||||
"Chances that Jerry beats Tom at t = 4.0: {:.1}%",
|
||||
100.0 * p_win
|
||||
);
|
||||
|
||||
// ... or simulate what could have happened in the past.
|
||||
let (p_win, p_los) = model.probabilities(&[&"Jerry"], &[&"Tom"], 2.0);
|
||||
println!(
|
||||
"Chances that Jerry beats Tom at t = 2.0: {:.1}%",
|
||||
100.0 * p_win
|
||||
);
|
||||
|
||||
let (p_win, p_los) = model.probabilities(&[&"Jerry"], &[&"Tom"], -1.0);
|
||||
println!(
|
||||
"Chances that Jerry beats Tom at t = -1.0: {:.1}%",
|
||||
100.0 * p_win
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user