Fixes, upgrade, and stuff
This commit is contained in:
@@ -11,7 +11,7 @@ ndarray = { version = "0.15", features = ["approx", "blas"] }
|
||||
|
||||
[dev-dependencies]
|
||||
approx = "0.4"
|
||||
rand = "0.8"
|
||||
time = "0.2"
|
||||
blas-src = { version = "0.8", features = ["openblas"] }
|
||||
openblas-src = { version = "0.10", features = ["cblas", "system"] }
|
||||
rand = "0.8"
|
||||
time = { version = "0.3", features = ["parsing", "macros"] }
|
||||
|
||||
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Kickscore
|
||||
|
||||
Rust port of kickscore.
|
||||
|
||||
## Todo
|
||||
|
||||
- [ ] Add all kernels
|
||||
@@ -6,7 +6,7 @@ use std::fs;
|
||||
use std::io::{self, BufRead};
|
||||
|
||||
use kickscore as ks;
|
||||
use time::Date;
|
||||
use time::{macros::date, Date};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let reader = fs::File::open("data/nba.csv").map(io::BufReader::new)?;
|
||||
@@ -14,7 +14,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut teams = HashSet::new();
|
||||
let mut observations = Vec::new();
|
||||
|
||||
let cutoff = time::date!(2019 - 06 - 01);
|
||||
let cutoff = date!(2019 - 06 - 01);
|
||||
let format = time::format_description::parse("[year]-[month]-[day]").unwrap();
|
||||
|
||||
for line in reader.lines().skip(1) {
|
||||
let line = line?;
|
||||
@@ -22,7 +23,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
assert!(data.len() == 5);
|
||||
|
||||
let t = Date::parse(data[0], "%F")?;
|
||||
let t = Date::parse(data[0], &format)?;
|
||||
|
||||
if t > cutoff {
|
||||
break;
|
||||
@@ -73,9 +74,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Probability that CHI beats BOS...");
|
||||
|
||||
let (p_win, _) = model.probabilities(
|
||||
&[&"CHI"],
|
||||
&[&"BOS"],
|
||||
time::date!(1996 - 01 - 01)
|
||||
&["CHI"],
|
||||
&["BOS"],
|
||||
date!(1996 - 01 - 01)
|
||||
.midnight()
|
||||
.assume_utc()
|
||||
.unix_timestamp() as f64,
|
||||
@@ -83,9 +84,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!(" ... in 1996: {:.2}%", 100.0 * p_win);
|
||||
|
||||
let (p_win, _) = model.probabilities(
|
||||
&[&"CHI"],
|
||||
&[&"BOS"],
|
||||
time::date!(2001 - 01 - 01)
|
||||
&["CHI"],
|
||||
&["BOS"],
|
||||
date!(2001 - 01 - 01)
|
||||
.midnight()
|
||||
.assume_utc()
|
||||
.unix_timestamp() as f64,
|
||||
@@ -93,9 +94,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!(" ... in 2001: {:.2}%", 100.0 * p_win);
|
||||
|
||||
let (p_win, _) = model.probabilities(
|
||||
&[&"CHI"],
|
||||
&[&"BOS"],
|
||||
time::date!(2020 - 01 - 01)
|
||||
&["CHI"],
|
||||
&["BOS"],
|
||||
date!(2020 - 01 - 01)
|
||||
.midnight()
|
||||
.assume_utc()
|
||||
.unix_timestamp() as f64,
|
||||
|
||||
@@ -154,7 +154,7 @@ impl BinaryModel {
|
||||
fn process_items(&self, items: &[&str], sign: f64) -> Vec<(usize, f64)> {
|
||||
items
|
||||
.iter()
|
||||
.map(|key| (self.storage.get_id(&key), sign))
|
||||
.map(|key| (self.storage.get_id(key), sign))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ impl DifferenceModel {
|
||||
fn process_items(&self, items: &[&str], sign: f64) -> Vec<(usize, f64)> {
|
||||
items
|
||||
.iter()
|
||||
.map(|key| (self.storage.get_id(&key), sign))
|
||||
.map(|key| (self.storage.get_id(key), sign))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ impl TernaryModel {
|
||||
fn process_items(&self, items: &[&str], sign: f64) -> Vec<(usize, f64)> {
|
||||
items
|
||||
.iter()
|
||||
.map(|key| (self.storage.get_id(&key), sign))
|
||||
.map(|key| (self.storage.get_id(key), sign))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ impl ProbitWinObservation {
|
||||
}
|
||||
|
||||
pub fn probability(storage: &Storage, elems: &[(usize, f64)], t: f64, margin: f64) -> f64 {
|
||||
let (m, v) = f_params(&elems, t, &storage);
|
||||
let (m, v) = f_params(elems, t, storage);
|
||||
let (logpart, _, _) = mm_probit_win(m - margin, v);
|
||||
|
||||
logpart.exp()
|
||||
@@ -188,7 +188,7 @@ impl ProbitTieObservation {
|
||||
}
|
||||
|
||||
pub fn probability(storage: &Storage, elems: &[(usize, f64)], t: f64, margin: f64) -> f64 {
|
||||
let (m, v) = f_params(&elems, t, &storage);
|
||||
let (m, v) = f_params(elems, t, storage);
|
||||
let (logpart, _, _) = mm_probit_tie(m, v, margin);
|
||||
|
||||
logpart.exp()
|
||||
|
||||
@@ -31,15 +31,15 @@ fn kickscore_basic() {
|
||||
|
||||
model.fit();
|
||||
|
||||
let (p_win, _p_los) = model.probabilities(&[&"Jerry"], &[&"Tom"], 4.0);
|
||||
let (p_win, _p_los) = model.probabilities(&["Jerry"], &["Tom"], 4.0);
|
||||
|
||||
assert_abs_diff_eq!(p_win, 0.7299975928462964, epsilon = f64::EPSILON);
|
||||
|
||||
let (p_win, _p_los) = model.probabilities(&[&"Jerry"], &[&"Tom"], 2.0);
|
||||
let (p_win, _p_los) = model.probabilities(&["Jerry"], &["Tom"], 2.0);
|
||||
|
||||
assert_abs_diff_eq!(p_win, 0.4455095363120037, epsilon = f64::EPSILON);
|
||||
|
||||
let (p_win, _p_los) = model.probabilities(&[&"Jerry"], &[&"Tom"], -1.0);
|
||||
let (p_win, _p_los) = model.probabilities(&["Jerry"], &["Tom"], -1.0);
|
||||
|
||||
assert_abs_diff_eq!(p_win, 0.9037560799725326, epsilon = f64::EPSILON);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::io::{self, BufRead};
|
||||
|
||||
use approx::assert_abs_diff_eq;
|
||||
use kickscore as ks;
|
||||
use time::Date;
|
||||
use time::{macros::date, Date};
|
||||
|
||||
#[test]
|
||||
fn nba_history() {
|
||||
@@ -18,7 +18,8 @@ fn nba_history() {
|
||||
let mut teams = HashSet::new();
|
||||
let mut observations = Vec::new();
|
||||
|
||||
let cutoff = time::date!(2019 - 06 - 01);
|
||||
let cutoff = date!(2019 - 06 - 01);
|
||||
let format = time::format_description::parse("[year]-[month]-[day]").unwrap();
|
||||
|
||||
for line in reader.lines().skip(1) {
|
||||
let line = line.unwrap();
|
||||
@@ -26,7 +27,7 @@ fn nba_history() {
|
||||
|
||||
assert!(data.len() == 5);
|
||||
|
||||
let t = Date::parse(data[0], "%F").unwrap();
|
||||
let t = Date::parse(data[0], &format).unwrap();
|
||||
|
||||
if t > cutoff {
|
||||
break;
|
||||
@@ -75,9 +76,9 @@ fn nba_history() {
|
||||
model.fit();
|
||||
|
||||
let (p_win, _) = model.probabilities(
|
||||
&[&"CHI"],
|
||||
&[&"BOS"],
|
||||
time::date!(1996 - 01 - 01)
|
||||
&["CHI"],
|
||||
&["BOS"],
|
||||
date!(1996 - 01 - 01)
|
||||
.midnight()
|
||||
.assume_utc()
|
||||
.unix_timestamp() as f64,
|
||||
@@ -86,9 +87,9 @@ fn nba_history() {
|
||||
assert_abs_diff_eq!(p_win, 0.9002599772490479, epsilon = f64::EPSILON);
|
||||
|
||||
let (p_win, _) = model.probabilities(
|
||||
&[&"CHI"],
|
||||
&[&"BOS"],
|
||||
time::date!(2001 - 01 - 01)
|
||||
&["CHI"],
|
||||
&["BOS"],
|
||||
date!(2001 - 01 - 01)
|
||||
.midnight()
|
||||
.assume_utc()
|
||||
.unix_timestamp() as f64,
|
||||
@@ -97,9 +98,9 @@ fn nba_history() {
|
||||
assert_abs_diff_eq!(p_win, 0.22837870685441986, epsilon = f64::EPSILON);
|
||||
|
||||
let (p_win, _) = model.probabilities(
|
||||
&[&"CHI"],
|
||||
&[&"BOS"],
|
||||
time::date!(2020 - 01 - 01)
|
||||
&["CHI"],
|
||||
&["BOS"],
|
||||
date!(2020 - 01 - 01)
|
||||
.midnight()
|
||||
.assume_utc()
|
||||
.unix_timestamp() as f64,
|
||||
|
||||
Reference in New Issue
Block a user