This commit is contained in:
2018-10-25 21:41:23 +02:00
parent 4fc27841e9
commit 2367a8e47f
3 changed files with 37 additions and 33 deletions

View File

@@ -92,16 +92,20 @@ where
let rating_count = ratings.len();
let team_count = ranks.len();
let rating_vars = (0..rating_count).map(|_| variable_arena.create()).collect::<Vec<_>>();
let rating_vars = (0..rating_count)
.map(|_| variable_arena.create())
.collect::<Vec<_>>();
let perf_vars = ratings
.iter()
.map(|(_, team)| {
(variable_arena.create(), *team)
})
.map(|(_, team)| (variable_arena.create(), *team))
.collect::<Vec<_>>();
let team_perf_vars = (0..team_count).map(|_| variable_arena.create()).collect::<Vec<_>>();
let team_diff_vars = (0..team_count - 1).map(|_| variable_arena.create()).collect::<Vec<_>>();
let team_perf_vars = (0..team_count)
.map(|_| variable_arena.create())
.collect::<Vec<_>>();
let team_diff_vars = (0..team_count - 1)
.map(|_| variable_arena.create())
.collect::<Vec<_>>();
let mut factor_id = 0;
@@ -109,16 +113,12 @@ where
.iter()
.zip(ratings.iter().map(|(rating, _)| rating))
.map(|(rating_var, rating)| {
let gaussian = Gaussian::from_mu_sigma(rating.mu(), (rating.sigma().powi(2) + tau_sqr).sqrt());
let gaussian =
Gaussian::from_mu_sigma(rating.mu(), (rating.sigma().powi(2) + tau_sqr).sqrt());
factor_id += 1;
PriorFactor::new(
&mut variable_arena,
factor_id,
*rating_var,
gaussian,
)
PriorFactor::new(&mut variable_arena, factor_id, *rating_var, gaussian)
})
.collect::<Vec<_>>();
@@ -128,13 +128,7 @@ where
.map(|(rating_var, perf)| {
factor_id += 1;
LikelihoodFactor::new(
&mut variable_arena,
factor_id,
*rating_var,
*perf,
beta_sqr,
)
LikelihoodFactor::new(&mut variable_arena, factor_id, *rating_var, *perf, beta_sqr)
})
.collect::<Vec<_>>();
@@ -175,7 +169,6 @@ where
teams.to_vec(),
vec![1.0, -1.0],
)
})
.collect::<Vec<_>>();
@@ -197,7 +190,6 @@ where
draw_margin(DRAW_PROBABILITY, BETA, player_count as f64),
ranks[i] == ranks[i + 1],
)
})
.collect::<Vec<_>>();;
@@ -239,11 +231,9 @@ where
rating_vars
.iter()
.map(|variable| variable_arena.get(*variable).unwrap().get_value())
.map(|value| {
Rating {
mu: value.mu(),
sigma: value.sigma(),
}
.map(|value| Rating {
mu: value.mu(),
sigma: value.sigma(),
})
.collect::<Vec<_>>()
}
@@ -372,7 +362,10 @@ mod tests {
Rating::new(16.79337409436942, 6.348053083319977),
];
let ratings = rate(&[(alice, 0), (bob, 1), (chris, 2), (darren, 3)], &[0, 1, 2, 3]);
let ratings = rate(
&[(alice, 0), (bob, 1), (chris, 2), (darren, 3)],
&[0, 1, 2, 3],
);
for (rating, expected) in ratings.iter().zip(expected_ratings.iter()) {
assert_relative_eq!(rating, expected, epsilon = EPSILON);