Fix warnings.

This commit is contained in:
2020-04-17 20:39:01 +02:00
parent 81ed582e59
commit 5aaada0c05
11 changed files with 76 additions and 112 deletions

View File

@@ -6,7 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
cblas = "0.2" cblas = "0.2"
derivative = "1.0" derivative = "2.1"
expm = "0.1" expm = "0.1"
lapacke = "0.2" lapacke = "0.2"
ndarray = "0.13" ndarray = "0.13"

View File

@@ -34,7 +34,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
continue; 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_1: u16 = data[3].parse()?;
let score_2: u16 = data[4].parse()?; let score_2: u16 = data[4].parse()?;
@@ -72,21 +72,30 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let (p_win, _) = model.probabilities( let (p_win, _) = model.probabilities(
&[&"CHI"], &[&"CHI"],
&[&"BOS"], &[&"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); println!(" ... in 1996: {:.2}%", 100.0 * p_win);
let (p_win, _) = model.probabilities( let (p_win, _) = model.probabilities(
&[&"CHI"], &[&"CHI"],
&[&"BOS"], &[&"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); println!(" ... in 2001: {:.2}%", 100.0 * p_win);
let (p_win, _) = model.probabilities( let (p_win, _) = model.probabilities(
&[&"CHI"], &[&"CHI"],
&[&"BOS"], &[&"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); println!(" ... in 2020: {:.2}%", 100.0 * p_win);

View File

@@ -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<f64>, 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<f64>, 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<f64>], 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`. /// 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 /// Panics if matrices `a` and `b` have different shape and strides, or if either underlying array is

View File

@@ -29,7 +29,7 @@ pub trait Kernel {
b b
} }
fn noise_cov(&self, t0: f64, t1: f64) -> Array2<f64> { fn noise_cov(&self, _t0: f64, _t1: f64) -> Array2<f64> {
/* /*
mat = self.noise_effect.dot(self.noise_density).dot(self.noise_effect.T) mat = self.noise_effect.dot(self.noise_density).dot(self.noise_effect.T)
#print(g) #print(g)

View File

@@ -21,11 +21,11 @@ impl Kernel for Constant {
1 1
} }
fn state_mean(&self, t: f64) -> Array1<f64> { fn state_mean(&self, _t: f64) -> Array1<f64> {
Array1::zeros(1) Array1::zeros(1)
} }
fn state_cov(&self, t: f64) -> Array2<f64> { fn state_cov(&self, _t: f64) -> Array2<f64> {
array![[1.0]] * self.var array![[1.0]] * self.var
} }
@@ -37,11 +37,11 @@ impl Kernel for Constant {
array![[0.0]] array![[0.0]]
} }
fn transition(&self, t0: f64, t1: f64) -> Array2<f64> { fn transition(&self, _t0: f64, _t1: f64) -> Array2<f64> {
array![[1.0]] array![[1.0]]
} }
fn noise_cov(&self, t0: f64, t1: f64) -> Array2<f64> { fn noise_cov(&self, _t0: f64, _t1: f64) -> Array2<f64> {
array![[0.0]] array![[0.0]]
} }
} }

View File

@@ -22,11 +22,11 @@ impl Kernel for Exponential {
1 1
} }
fn state_mean(&self, t: f64) -> Array1<f64> { fn state_mean(&self, _t: f64) -> Array1<f64> {
Array1::zeros(1) Array1::zeros(1)
} }
fn state_cov(&self, t: f64) -> Array2<f64> { fn state_cov(&self, _t: f64) -> Array2<f64> {
array![[1.0]] * self.var array![[1.0]] * self.var
} }

View File

@@ -28,11 +28,11 @@ impl Kernel for Matern32 {
2 2
} }
fn state_mean(&self, t: f64) -> Array1<f64> { fn state_mean(&self, _t: f64) -> Array1<f64> {
Array1::zeros(2) Array1::zeros(2)
} }
fn state_cov(&self, t: f64) -> Array2<f64> { fn state_cov(&self, _t: f64) -> Array2<f64> {
let a = self.lambda; let a = self.lambda;
array![[1.0, 0.0], [0.0, a * a]] * self.var array![[1.0, 0.0], [0.0, a * a]] * self.var

View File

@@ -4,7 +4,7 @@ use super::Kernel;
pub struct Matern52 { pub struct Matern52 {
var: f64, var: f64,
l_scale: f64, _l_scale: f64,
lambda: f64, lambda: f64,
} }
@@ -12,7 +12,7 @@ impl Matern52 {
pub fn new(var: f64, l_scale: f64) -> Self { pub fn new(var: f64, l_scale: f64) -> Self {
Matern52 { Matern52 {
var, var,
l_scale, _l_scale: l_scale,
lambda: 5.0f64.sqrt() / l_scale, lambda: 5.0f64.sqrt() / l_scale,
} }
} }
@@ -27,11 +27,11 @@ impl Kernel for Matern52 {
3 3
} }
fn state_mean(&self, t: f64) -> Array1<f64> { fn state_mean(&self, _t: f64) -> Array1<f64> {
Array1::zeros(3) Array1::zeros(3)
} }
fn state_cov(&self, t: f64) -> Array2<f64> { fn state_cov(&self, _t: f64) -> Array2<f64> {
let a = self.lambda; let a = self.lambda;
array![ array![

View File

@@ -16,7 +16,7 @@ pub struct DifferenceModel {
storage: Storage, storage: Storage,
last_t: f64, last_t: f64,
observations: Vec<GaussianObservation>, observations: Vec<GaussianObservation>,
last_method: Option<DifferenceModelFitMethod>, _last_method: Option<DifferenceModelFitMethod>,
var: f64, var: f64,
} }
@@ -26,7 +26,7 @@ impl DifferenceModel {
storage: Storage::new(), storage: Storage::new(),
last_t: f64::NEG_INFINITY, last_t: f64::NEG_INFINITY,
observations: Vec::new(), observations: Vec::new(),
last_method: None, _last_method: None,
var, // default = 1.0 var, // default = 1.0
} }
} }
@@ -83,10 +83,10 @@ impl DifferenceModel {
pub fn probabilities( pub fn probabilities(
&mut self, &mut self,
team_1: &[&str], _team_1: &[&str],
team_2: &[&str], _team_2: &[&str],
t: f64, _t: f64,
margin: Option<f64>, _margin: Option<f64>,
) -> (f64, f64, f64) { ) -> (f64, f64, f64) {
unimplemented!(); unimplemented!();
} }

View File

@@ -3,6 +3,7 @@ use crate::storage::Storage;
use super::Observation; use super::Observation;
pub struct GaussianObservation { pub struct GaussianObservation {
/*
m: usize, m: usize,
items: Vec<usize>, items: Vec<usize>,
coeffs: Vec<f64>, coeffs: Vec<f64>,
@@ -13,24 +14,30 @@ pub struct GaussianObservation {
logpart: f64, logpart: f64,
exp_ll: usize, exp_ll: usize,
margin: f64, margin: f64,
} */}
impl GaussianObservation { 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!(); unimplemented!();
} }
} }
impl Observation for GaussianObservation { 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!(); unimplemented!();
} }
fn ep_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { fn ep_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 {
unimplemented!(); unimplemented!();
} }
fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 {
unimplemented!(); unimplemented!();
} }
} }

View File

@@ -32,9 +32,9 @@ pub struct ProbitWinObservation {
indices: Vec<usize>, indices: Vec<usize>,
ns_cav: Vec<f64>, ns_cav: Vec<f64>,
xs_cav: Vec<f64>, xs_cav: Vec<f64>,
t: f64, _t: f64,
logpart: f64, logpart: f64,
exp_ll: usize, _exp_ll: usize,
margin: f64, margin: f64,
} }
@@ -54,9 +54,9 @@ impl ProbitWinObservation {
.collect(), .collect(),
ns_cav: (0..elems.len()).map(|_| 0.0).collect(), ns_cav: (0..elems.len()).map(|_| 0.0).collect(),
xs_cav: (0..elems.len()).map(|_| 0.0).collect(), xs_cav: (0..elems.len()).map(|_| 0.0).collect(),
t, _t: t,
logpart: 0.0, logpart: 0.0,
exp_ll: 0, _exp_ll: 0,
margin, margin,
} }
} }
@@ -119,7 +119,7 @@ impl Observation for ProbitWinObservation {
diff diff
} }
fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 {
todo!(); todo!();
} }
} }
@@ -129,30 +129,30 @@ pub struct LogitWinObservation {
} }
impl 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!(); todo!();
} }
} }
impl Observation for LogitWinObservation { 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!(); todo!();
} }
fn ep_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { fn ep_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 {
todo!(); todo!();
} }
fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 {
todo!(); todo!();
} }
} }
pub fn probit_tie_observation( pub fn probit_tie_observation(
elems: &[(usize, f64)], _elems: &[(usize, f64)],
t: f64, _t: f64,
margin: f64, _margin: f64,
storage: &Storage, _storage: &Storage,
) -> f64 { ) -> f64 {
unimplemented!(); unimplemented!();
} }
@@ -162,21 +162,21 @@ pub struct ProbitTieObservation {
} }
impl 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!(); todo!();
} }
} }
impl Observation for ProbitTieObservation { 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!(); todo!();
} }
fn ep_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { fn ep_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 {
todo!(); todo!();
} }
fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 {
todo!(); todo!();
} }
} }
@@ -186,21 +186,21 @@ pub struct LogitTieObservation {
} }
impl 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!(); todo!();
} }
} }
impl Observation for LogitTieObservation { 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!(); todo!();
} }
fn ep_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { fn ep_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 {
todo!(); todo!();
} }
fn kl_update(&mut self, lr: f64, storage: &mut Storage) -> f64 { fn kl_update(&mut self, _lr: f64, _storage: &mut Storage) -> f64 {
todo!(); todo!();
} }
} }