diff --git a/Cargo.toml b/Cargo.toml index 4dedad4..3923155 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] cblas = "0.2" -derivative = "1.0" +derivative = "2.1" expm = "0.1" lapacke = "0.2" ndarray = "0.13" diff --git a/examples/nba-history.rs b/examples/nba-history.rs index cc63a54..9d520f5 100644 --- a/examples/nba-history.rs +++ b/examples/nba-history.rs @@ -34,7 +34,7 @@ fn main() -> Result<(), Box> { continue; } - let t = t.midnight().timestamp() as f64; + let t = t.midnight().assume_utc().timestamp() as f64; let score_1: u16 = data[3].parse()?; let score_2: u16 = data[4].parse()?; @@ -72,21 +72,30 @@ fn main() -> Result<(), Box> { let (p_win, _) = model.probabilities( &[&"CHI"], &[&"BOS"], - time::date!(1996 - 01 - 01).midnight().timestamp() as f64, + time::date!(1996 - 01 - 01) + .midnight() + .assume_utc() + .timestamp() as f64, ); println!(" ... in 1996: {:.2}%", 100.0 * p_win); let (p_win, _) = model.probabilities( &[&"CHI"], &[&"BOS"], - time::date!(2001 - 01 - 01).midnight().timestamp() as f64, + time::date!(2001 - 01 - 01) + .midnight() + .assume_utc() + .timestamp() as f64, ); println!(" ... in 2001: {:.2}%", 100.0 * p_win); let (p_win, _) = model.probabilities( &[&"CHI"], &[&"BOS"], - time::date!(2020 - 01 - 01).midnight().timestamp() as f64, + time::date!(2020 - 01 - 01) + .midnight() + .assume_utc() + .timestamp() as f64, ); println!(" ... in 2020: {:.2}%", 100.0 * p_win); diff --git a/src/condest.rs b/src/condest.rs index 3539662..4c541d2 100644 --- a/src/condest.rs +++ b/src/condest.rs @@ -463,58 +463,6 @@ impl Normest1 { } } -/// Estimates the 1-norm of matrix `a`. -/// -/// The parameter `t` is the number of vectors that have to fulfill some bound. See [Higham, -/// Tisseur] for more information. `itmax` is the maximum number of sweeps permitted. -/// -/// **NOTE:** This function allocates on every call. If you want to repeatedly estimate the -/// 1-norm on matrices of the same size, construct a [`Normest1`] first, and call its methods. -/// -/// [Higham, Tisseur]: http://eprints.ma.man.ac.uk/321/1/covered/MIMS_ep2006_145.pdf -/// [`Normest1`]: struct.Normest1.html -pub fn normest1(a_matrix: &Array2, t: usize, itmax: usize) -> f64 { - // Assume the matrix is square and take the columns as n. If it's not square, the assertion in - // normest.calculate will fail. - let n = a_matrix.dim().1; - let mut normest1 = Normest1::new(n, t); - normest1.normest1(a_matrix, itmax) -} - -/// Estimates the 1-norm of a matrix `a` to the power `m`, `a^m`. -/// -/// The parameter `t` is the number of vectors that have to fulfill some bound. See [Higham, -/// Tisseur] for more information. `itmax` is the maximum number of sweeps permitted. -/// -/// **NOTE:** This function allocates on every call. If you want to repeatedly estimate the -/// 1-norm on matrices of the same size, construct a [`Normest1`] first, and call its methods. -/// -/// [Higham, Tisseur]: http://eprints.ma.man.ac.uk/321/1/covered/MIMS_ep2006_145.pdf -pub fn normest1_pow(a_matrix: &Array2, m: usize, t: usize, itmax: usize) -> f64 { - // Assume the matrix is square and take the columns as n. If it's not square, the assertion in - // normest.calculate will fail. - let n = a_matrix.dim().1; - let mut normest1 = Normest1::new(n, t); - normest1.normest1_pow(a_matrix, m, itmax) -} - -/// Estimates the 1-norm of a product of matrices `a1`, `a2`, ..., `an` passed in as a slice of -/// references. -/// -/// The parameter `t` is the number of vectors that have to fulfill some bound. See [Higham, -/// Tisseur] for more information. `itmax` is the maximum number of sweeps permitted. -/// -/// **NOTE:** This function allocates on every call. If you want to repeatedly estimate the -/// 1-norm on matrices of the same size, construct a [`Normest1`] first, and call its methods. -/// -/// [Higham, Tisseur]: http://eprints.ma.man.ac.uk/321/1/covered/MIMS_ep2006_145.pdf -pub fn normest1_prod(a_matrices: &[&Array2], t: usize, itmax: usize) -> f64 { - assert!(a_matrices.len() > 0); - let n = a_matrices[0].dim().1; - let mut normest1 = Normest1::new(n, t); - normest1.normest1_prod(a_matrices, itmax) -} - /// Assigns the sign of matrix `a` to matrix `b`. /// /// Panics if matrices `a` and `b` have different shape and strides, or if either underlying array is diff --git a/src/kernel.rs b/src/kernel.rs index 6cf58e1..2dc5983 100644 --- a/src/kernel.rs +++ b/src/kernel.rs @@ -29,7 +29,7 @@ pub trait Kernel { b } - fn noise_cov(&self, t0: f64, t1: f64) -> Array2 { + fn noise_cov(&self, _t0: f64, _t1: f64) -> Array2 { /* mat = self.noise_effect.dot(self.noise_density).dot(self.noise_effect.T) #print(g) diff --git a/src/kernel/constant.rs b/src/kernel/constant.rs index 6f6e32d..d8ff469 100644 --- a/src/kernel/constant.rs +++ b/src/kernel/constant.rs @@ -21,11 +21,11 @@ impl Kernel for Constant { 1 } - fn state_mean(&self, t: f64) -> Array1 { + fn state_mean(&self, _t: f64) -> Array1 { Array1::zeros(1) } - fn state_cov(&self, t: f64) -> Array2 { + fn state_cov(&self, _t: f64) -> Array2 { array![[1.0]] * self.var } @@ -37,11 +37,11 @@ impl Kernel for Constant { array![[0.0]] } - fn transition(&self, t0: f64, t1: f64) -> Array2 { + fn transition(&self, _t0: f64, _t1: f64) -> Array2 { array![[1.0]] } - fn noise_cov(&self, t0: f64, t1: f64) -> Array2 { + fn noise_cov(&self, _t0: f64, _t1: f64) -> Array2 { array![[0.0]] } } diff --git a/src/kernel/exponential.rs b/src/kernel/exponential.rs index 10e1d97..92ef02b 100644 --- a/src/kernel/exponential.rs +++ b/src/kernel/exponential.rs @@ -22,11 +22,11 @@ impl Kernel for Exponential { 1 } - fn state_mean(&self, t: f64) -> Array1 { + fn state_mean(&self, _t: f64) -> Array1 { Array1::zeros(1) } - fn state_cov(&self, t: f64) -> Array2 { + fn state_cov(&self, _t: f64) -> Array2 { array![[1.0]] * self.var } diff --git a/src/kernel/matern32.rs b/src/kernel/matern32.rs index deaae40..afe7df5 100644 --- a/src/kernel/matern32.rs +++ b/src/kernel/matern32.rs @@ -28,11 +28,11 @@ impl Kernel for Matern32 { 2 } - fn state_mean(&self, t: f64) -> Array1 { + fn state_mean(&self, _t: f64) -> Array1 { Array1::zeros(2) } - fn state_cov(&self, t: f64) -> Array2 { + fn state_cov(&self, _t: f64) -> Array2 { let a = self.lambda; array![[1.0, 0.0], [0.0, a * a]] * self.var diff --git a/src/kernel/matern52.rs b/src/kernel/matern52.rs index e23e043..9d0ff76 100644 --- a/src/kernel/matern52.rs +++ b/src/kernel/matern52.rs @@ -4,7 +4,7 @@ use super::Kernel; pub struct Matern52 { var: f64, - l_scale: f64, + _l_scale: f64, lambda: f64, } @@ -12,7 +12,7 @@ impl Matern52 { pub fn new(var: f64, l_scale: f64) -> Self { Matern52 { var, - l_scale, + _l_scale: l_scale, lambda: 5.0f64.sqrt() / l_scale, } } @@ -27,11 +27,11 @@ impl Kernel for Matern52 { 3 } - fn state_mean(&self, t: f64) -> Array1 { + fn state_mean(&self, _t: f64) -> Array1 { Array1::zeros(3) } - fn state_cov(&self, t: f64) -> Array2 { + fn state_cov(&self, _t: f64) -> Array2 { let a = self.lambda; array![ diff --git a/src/model/difference.rs b/src/model/difference.rs index 054a1e5..bff9584 100644 --- a/src/model/difference.rs +++ b/src/model/difference.rs @@ -16,7 +16,7 @@ pub struct DifferenceModel { storage: Storage, last_t: f64, observations: Vec, - last_method: Option, + _last_method: Option, var: f64, } @@ -26,7 +26,7 @@ impl DifferenceModel { storage: Storage::new(), last_t: f64::NEG_INFINITY, observations: Vec::new(), - last_method: None, + _last_method: None, var, // default = 1.0 } } @@ -83,10 +83,10 @@ impl DifferenceModel { pub fn probabilities( &mut self, - team_1: &[&str], - team_2: &[&str], - t: f64, - margin: Option, + _team_1: &[&str], + _team_2: &[&str], + _t: f64, + _margin: Option, ) -> (f64, f64, f64) { unimplemented!(); } diff --git a/src/observation/gaussian.rs b/src/observation/gaussian.rs index 38f470b..4d90892 100644 --- a/src/observation/gaussian.rs +++ b/src/observation/gaussian.rs @@ -3,34 +3,41 @@ use crate::storage::Storage; use super::Observation; pub struct GaussianObservation { - m: usize, - items: Vec, - coeffs: Vec, - indices: Vec, - ns_cav: Vec, - xs_cav: Vec, - t: f64, - logpart: f64, - exp_ll: usize, - margin: f64, -} + /* +m: usize, +items: Vec, +coeffs: Vec, +indices: Vec, +ns_cav: Vec, +xs_cav: Vec, +t: f64, +logpart: f64, +exp_ll: usize, +margin: f64, +*/} impl GaussianObservation { - pub fn new(storage: &mut Storage, elems: &[(usize, f64)], diff: f64, t: f64, var: f64) -> Self { + pub fn new( + _storage: &mut Storage, + _elems: &[(usize, f64)], + _diff: f64, + _t: f64, + _var: f64, + ) -> Self { unimplemented!(); } } impl Observation for GaussianObservation { - fn match_moments(&self, mean_cav: f64, cov_cav: f64) -> (f64, f64, f64) { + fn match_moments(&self, _mean_cav: f64, _cov_cav: f64) -> (f64, f64, f64) { unimplemented!(); } - fn ep_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { + fn ep_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 { unimplemented!(); } - fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { + fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 { unimplemented!(); } } diff --git a/src/observation/ordinal.rs b/src/observation/ordinal.rs index d79fc97..c57e5e0 100644 --- a/src/observation/ordinal.rs +++ b/src/observation/ordinal.rs @@ -32,9 +32,9 @@ pub struct ProbitWinObservation { indices: Vec, ns_cav: Vec, xs_cav: Vec, - t: f64, + _t: f64, logpart: f64, - exp_ll: usize, + _exp_ll: usize, margin: f64, } @@ -54,9 +54,9 @@ impl ProbitWinObservation { .collect(), ns_cav: (0..elems.len()).map(|_| 0.0).collect(), xs_cav: (0..elems.len()).map(|_| 0.0).collect(), - t, + _t: t, logpart: 0.0, - exp_ll: 0, + _exp_ll: 0, margin, } } @@ -119,7 +119,7 @@ impl Observation for ProbitWinObservation { diff } - fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { + fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 { todo!(); } } @@ -129,30 +129,30 @@ pub struct LogitWinObservation { } impl LogitWinObservation { - pub fn new(storage: &mut Storage, elems: &[(usize, f64)], t: f64, margin: f64) -> Self { + pub fn new(_storage: &mut Storage, _elems: &[(usize, f64)], _t: f64, _margin: f64) -> Self { todo!(); } } impl Observation for LogitWinObservation { - fn match_moments(&self, mean_cav: f64, cov_cav: f64) -> (f64, f64, f64) { + fn match_moments(&self, _mean_cav: f64, _cov_cav: f64) -> (f64, f64, f64) { todo!(); } - fn ep_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { + fn ep_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 { todo!(); } - fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { + fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 { todo!(); } } pub fn probit_tie_observation( - elems: &[(usize, f64)], - t: f64, - margin: f64, - storage: &Storage, + _elems: &[(usize, f64)], + _t: f64, + _margin: f64, + _storage: &Storage, ) -> f64 { unimplemented!(); } @@ -162,21 +162,21 @@ pub struct ProbitTieObservation { } impl ProbitTieObservation { - pub fn new(storage: &mut Storage, elems: &[(usize, f64)], t: f64, margin: f64) -> Self { + pub fn new(_storage: &mut Storage, _elems: &[(usize, f64)], _t: f64, _margin: f64) -> Self { todo!(); } } impl Observation for ProbitTieObservation { - fn match_moments(&self, mean_cav: f64, cov_cav: f64) -> (f64, f64, f64) { + fn match_moments(&self, _mean_cav: f64, _cov_cav: f64) -> (f64, f64, f64) { todo!(); } - fn ep_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { + fn ep_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 { todo!(); } - fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { + fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 { todo!(); } } @@ -186,21 +186,21 @@ pub struct LogitTieObservation { } impl LogitTieObservation { - pub fn new(storage: &mut Storage, elems: &[(usize, f64)], t: f64, margin: f64) -> Self { + pub fn new(_storage: &mut Storage, _elems: &[(usize, f64)], _t: f64, _margin: f64) -> Self { todo!(); } } impl Observation for LogitTieObservation { - fn match_moments(&self, mean_cav: f64, cov_cav: f64) -> (f64, f64, f64) { + fn match_moments(&self, _mean_cav: f64, _cov_cav: f64) -> (f64, f64, f64) { todo!(); } - fn ep_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { + fn ep_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 { todo!(); } - fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { + fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 { todo!(); } }