Test with xp-offset.

This commit is contained in:
2018-10-28 21:15:17 +01:00
parent 712bcd9f42
commit 8f454db10f
2 changed files with 30 additions and 5 deletions

View File

@@ -139,6 +139,7 @@ pub struct LikelihoodFactor {
mean: VariableId,
value: VariableId,
variance: f64,
exp_offset: f64,
}
impl LikelihoodFactor {
@@ -148,6 +149,7 @@ impl LikelihoodFactor {
mean: VariableId,
value: VariableId,
variance: f64,
exp_offset: f64,
) -> LikelihoodFactor {
variable_arena[mean].attach_factor(id);
variable_arena[value].attach_factor(id);
@@ -157,6 +159,7 @@ impl LikelihoodFactor {
mean,
value,
variance,
exp_offset,
}
}
@@ -168,7 +171,10 @@ impl LikelihoodFactor {
};
let a = 1.0 / (1.0 + self.variance * (x.pi() - fx.pi()));
let gaussian = Gaussian::from_pi_tau(a * (x.pi() - fx.pi()), a * (x.tau() - fx.tau()));
let gaussian = Gaussian::from_pi_tau(
a * (x.pi() - fx.pi()) + self.exp_offset,
a * (x.tau() - fx.tau())
);
debug!(
"Likelihood::up var={:?}, value={:?}",

View File

@@ -39,6 +39,7 @@ pub const DELTA: f64 = 0.0001;
pub trait Rateable {
fn mu(&self) -> f64;
fn sigma(&self) -> f64;
fn experience(&self) -> usize;
fn skill(&self) -> f64 {
self.mu() - 3.0 * self.sigma()
@@ -54,11 +55,12 @@ pub trait RateableMut {
pub struct Rating {
pub mu: f64,
pub sigma: f64,
pub experience: usize,
}
impl Rating {
pub fn new(mu: f64, sigma: f64) -> Rating {
Rating { mu, sigma }
Rating { mu, sigma, experience: 0 }
}
}
@@ -70,6 +72,10 @@ impl Rateable for Rating {
fn sigma(&self) -> f64 {
self.sigma
}
fn experience(&self) -> usize {
self.experience
}
}
impl RateableMut for Rating {
@@ -96,7 +102,7 @@ pub struct TrueSkill {
}
impl TrueSkill {
pub fn rate<R>(&self, ratings: &[(R, u16)], ranks: &[u16], min_delta: f64) -> Vec<Rating>
pub fn rate<R>(&self, ratings: &[(R, u16)], ranks: &[u16], min_delta: f64, experience_map: &[f64]) -> Vec<Rating>
where
R: Rateable,
{
@@ -145,11 +151,23 @@ impl TrueSkill {
let perf_layer = rating_vars
.iter()
.zip(ratings.iter())
.zip(perf_vars.iter().map(|(variable, _)| variable))
.map(|(rating_var, perf)| {
.map(|((rating_var, (rating, _)), perf)| {
factor_id += 1;
LikelihoodFactor::new(&mut variable_arena, factor_id, *rating_var, *perf, beta_sqr)
let experience = if rating.experience() < experience_map.len() {
experience_map[rating.experience()]
} else {
0.0
};
LikelihoodFactor::new(&mut variable_arena,
factor_id,
*rating_var,
*perf,
beta_sqr,
experience)
})
.collect::<Vec<_>>();
@@ -265,6 +283,7 @@ impl TrueSkill {
.map(|value| Rating {
mu: value.mu(),
sigma: value.sigma(),
experience: 0,
})
.collect::<Vec<_>>()
}