This commit is contained in:
2018-10-26 13:15:35 +02:00
parent 3424b5f45f
commit e3e6ced26f
3 changed files with 25 additions and 27 deletions

View File

@@ -234,16 +234,17 @@ impl SumFactor {
fy: Vec<Gaussian>,
a: &[f64],
) {
let (sum_pi, sum_tau) = a.iter()
.zip(y.iter().zip(fy.iter()))
.fold((0.0, 0.0f64), |(pi, tau), (a, (y, fy))| {
let x = *y / *fy;
let (sum_pi, sum_tau) =
a.iter()
.zip(y.iter().zip(fy.iter()))
.fold((0.0, 0.0f64), |(pi, tau), (a, (y, fy))| {
let x = *y / *fy;
let new_pi = a.powi(2) / x.pi();
let new_tau = a * x.mu();
let new_pi = a.powi(2) / x.pi();
let new_tau = a * x.mu();
(pi + new_pi, tau + new_tau)
});
(pi + new_pi, tau + new_tau)
});
let new_pi = 1.0 / sum_pi;
let new_tau = new_pi * sum_tau;
@@ -285,10 +286,12 @@ impl SumFactor {
.coeffs
.iter()
.enumerate()
.map(|(i, coeff)| if i == index {
1.0 / idx_coeff
} else {
-coeff / idx_coeff
.map(|(i, coeff)| {
if i == index {
1.0 / idx_coeff
} else {
-coeff / idx_coeff
}
})
.collect::<Vec<_>>();