2018 edition, and clippy fixes.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
name = "trueskill"
|
name = "trueskill"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Anders Olsson <anders.e.olsson@gmail.com>"]
|
authors = ["Anders Olsson <anders.e.olsson@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ use std::collections::HashMap;
|
|||||||
use std::f64;
|
use std::f64;
|
||||||
use std::ops;
|
use std::ops;
|
||||||
|
|
||||||
use gaussian::Gaussian;
|
use log::*;
|
||||||
use math;
|
|
||||||
|
use crate::gaussian::Gaussian;
|
||||||
|
use crate::math;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
pub struct VariableId {
|
pub struct VariableId {
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ impl ops::Mul<Gaussian> for Gaussian {
|
|||||||
type Output = Gaussian;
|
type Output = Gaussian;
|
||||||
|
|
||||||
fn mul(self, rhs: Gaussian) -> Gaussian {
|
fn mul(self, rhs: Gaussian) -> Gaussian {
|
||||||
|
#[allow(clippy::suspicious_arithmetic_impl)]
|
||||||
Gaussian::from_pi_tau(self.pi + rhs.pi, self.tau + rhs.tau)
|
Gaussian::from_pi_tau(self.pi + rhs.pi, self.tau + rhs.tau)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,6 +65,7 @@ impl ops::Div<Gaussian> for Gaussian {
|
|||||||
type Output = Gaussian;
|
type Output = Gaussian;
|
||||||
|
|
||||||
fn div(self, rhs: Gaussian) -> Gaussian {
|
fn div(self, rhs: Gaussian) -> Gaussian {
|
||||||
|
#[allow(clippy::suspicious_arithmetic_impl)]
|
||||||
Gaussian::from_pi_tau(self.pi - rhs.pi, self.tau - rhs.tau)
|
Gaussian::from_pi_tau(self.pi - rhs.pi, self.tau - rhs.tau)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/lib.rs
19
src/lib.rs
@@ -1,22 +1,11 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
extern crate statrs;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[macro_use]
|
|
||||||
extern crate approx;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
extern crate env_logger;
|
|
||||||
|
|
||||||
mod factor_graph;
|
mod factor_graph;
|
||||||
mod gaussian;
|
mod gaussian;
|
||||||
mod math;
|
mod math;
|
||||||
mod matrix;
|
mod matrix;
|
||||||
|
|
||||||
use factor_graph::*;
|
use crate::factor_graph::*;
|
||||||
use gaussian::Gaussian;
|
use crate::gaussian::Gaussian;
|
||||||
use matrix::Matrix;
|
use crate::matrix::Matrix;
|
||||||
|
|
||||||
/// Default initial mean of ratings.
|
/// Default initial mean of ratings.
|
||||||
pub const MU: f64 = 25.0;
|
pub const MU: f64 = 25.0;
|
||||||
@@ -376,7 +365,7 @@ impl Default for TrueSkill {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use approx::{AbsDiffEq, RelativeEq};
|
use approx::*;
|
||||||
use env_logger;
|
use env_logger;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::unreadable_literal, clippy::excessive_precision)]
|
||||||
|
|
||||||
use statrs::distribution::{Continuous, Normal, Univariate};
|
use statrs::distribution::{Continuous, Normal, Univariate};
|
||||||
|
|
||||||
const S2PI: f64 = 2.50662827463100050242_e0;
|
const S2PI: f64 = 2.50662827463100050242_e0;
|
||||||
@@ -99,7 +101,7 @@ fn ndtri(y0: f64) -> f64 {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if y > 0.13533528323661269189 {
|
if y > 0.13533528323661269189 {
|
||||||
y = y - 0.5;
|
y -= 0.5;
|
||||||
let y2 = y * y;
|
let y2 = y * y;
|
||||||
|
|
||||||
return (y + y * (y2 * polevl(y2, &P0, 4) / p1evl(y2, &Q0, 8))) * S2PI;
|
return (y + y * (y2 * polevl(y2, &P0, 4) / p1evl(y2, &Q0, 8))) * S2PI;
|
||||||
@@ -136,10 +138,12 @@ pub fn icdf(x: f64) -> f64 {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use approx::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cdf() {
|
fn test_cdf() {
|
||||||
assert_eq!(cdf(0.5), 0.6914624612740131);
|
assert_relative_eq!(cdf(0.5), 0.6914624612740131);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user