Initial commit. Basic structure in place, need to implement logic.
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/target
|
||||||
|
**/*.rs.bk
|
||||||
|
Cargo.lock
|
||||||
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
[package]
|
||||||
|
name = "kickscore"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Anders Olsson <anders.e.olsson@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
ndarray = "0.13"
|
||||||
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
|
||||||
|
);
|
||||||
|
}
|
||||||
11
src/kernel.rs
Normal file
11
src/kernel.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
mod constant;
|
||||||
|
mod exponential;
|
||||||
|
mod matern52;
|
||||||
|
|
||||||
|
pub use constant::Constant;
|
||||||
|
pub use exponential::Exponential;
|
||||||
|
pub use matern52::Matern52;
|
||||||
|
|
||||||
|
pub trait Kernel {}
|
||||||
|
|
||||||
|
impl Kernel for Vec<Box<dyn Kernel>> {}
|
||||||
13
src/kernel/constant.rs
Normal file
13
src/kernel/constant.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use super::Kernel;
|
||||||
|
|
||||||
|
pub struct Constant {
|
||||||
|
var: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Constant {
|
||||||
|
pub fn new(var: f64) -> Self {
|
||||||
|
Constant { var }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Kernel for Constant {}
|
||||||
14
src/kernel/exponential.rs
Normal file
14
src/kernel/exponential.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
use super::Kernel;
|
||||||
|
|
||||||
|
pub struct Exponential {
|
||||||
|
var: f64,
|
||||||
|
l_scale: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Exponential {
|
||||||
|
pub fn new(var: f64, l_scale: f64) -> Self {
|
||||||
|
Exponential { var, l_scale }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Kernel for Exponential {}
|
||||||
14
src/kernel/matern52.rs
Normal file
14
src/kernel/matern52.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
use super::Kernel;
|
||||||
|
|
||||||
|
pub struct Matern52 {
|
||||||
|
var: f64,
|
||||||
|
l_scale: f64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Matern52 {
|
||||||
|
pub fn new(var: f64, l_scale: f64) -> Self {
|
||||||
|
Matern52 { var, l_scale }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Kernel for Matern52 {}
|
||||||
6
src/lib.rs
Normal file
6
src/lib.rs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
// https://github.com/lucasmaystre/kickscore/tree/master/kickscore
|
||||||
|
pub mod kernel;
|
||||||
|
mod model;
|
||||||
|
|
||||||
|
pub use kernel::Kernel;
|
||||||
|
pub use model::*;
|
||||||
23
src/model.rs
Normal file
23
src/model.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
use crate::kernel::Kernel;
|
||||||
|
|
||||||
|
pub struct BinaryModel {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BinaryModel {
|
||||||
|
pub fn add_item(&mut self, name: &str, kernel: impl Kernel) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn observe(&mut self, winners: &[&str], losers: &[&str], t: f64) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fit(&mut self, verbose: bool) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn probabilities(&mut self, team1: &[&str], team2: &[&str], t: f64) -> (f64, f64) {
|
||||||
|
(0.0, 0.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user