Start working on factor graph.

This commit is contained in:
2018-10-22 07:29:18 +02:00
parent 14bb0e9bb8
commit d6ea5e3116
3 changed files with 99 additions and 0 deletions

54
src/factor_graph.rs Normal file
View File

@@ -0,0 +1,54 @@
use std::cmp;
use gaussian::Gaussian;
pub struct Variable {
gaussian: Gaussian,
}
impl Variable {
pub fn new() -> Variable {
Variable {
gaussian: Gaussian::new(0.0, 0.0),
}
}
fn delta(&self, other: &Variable) -> f32 {
let pi_delta = self.gaussian.pi - other.gaussian.pi;
if pi_delta.is_infinite() {
0.0
} else {
let tau_delta = (self.gaussian.tau - other.gaussian.tau).abs();
if pi_delta > tau_delta {
pi_delta
} else {
tau_delta
}
}
}
}
pub trait Factor {
fn down(&self) -> f32 {
0.0
}
}
pub struct PriorFactor {
variable: Variable,
dynamic: f32
}
impl PriorFactor {
pub fn new(variable: Variable, dynamic: f32) -> PriorFactor {
PriorFactor { variable, dynamic }
}
}
impl Factor for PriorFactor {
fn down(&self) -> f32 {
0.0
}
}