Start working on factor graph.
This commit is contained in:
54
src/factor_graph.rs
Normal file
54
src/factor_graph.rs
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user