-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/AU-Master-Thesis/gbp-rs
- Loading branch information
Showing
7 changed files
with
235 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use nalgebra::{DMatrix, DVector}; | ||
// use num::Float; | ||
|
||
// TODO: maybe there should be something to ensure the dimensions of the information vector and precision matrix match | ||
#[derive(Debug)] | ||
pub struct Gaussian { | ||
size: usize, // dim | ||
pub information_vector: DVector<f64>, // eta | ||
pub precision_matrix: DMatrix<f64>, // lam | ||
} | ||
|
||
impl Gaussian { | ||
/// information_vector commonly used symbol: lowercase eta (η) | ||
/// precision_matrix commmonly used symbol: uppercase lambda (Λ) | ||
pub fn new( | ||
size: usize, | ||
information_vector: Option<DVector<f64>>, | ||
precision_matrix: Option<DMatrix<f64>>, | ||
) -> Self { | ||
let information_vector = information_vector.unwrap_or_else(|| DVector::zeros(size)); | ||
// check if the precision_matrix has an inverse | ||
let precision_matrix = precision_matrix.unwrap_or_else(|| DMatrix::zeros(size, size)); | ||
|
||
Gaussian { | ||
size, | ||
information_vector, | ||
precision_matrix, | ||
} | ||
} | ||
|
||
pub fn mean(&self) -> DVector<f64> { | ||
self.precision_matrix.try_inverse().unwrap() * &self.information_vector | ||
} | ||
|
||
pub fn covariance(&self) -> DMatrix<f64> { | ||
self.precision_matrix.try_inverse().unwrap() | ||
} | ||
|
||
pub fn mean_and_coveriance(&self) -> (DVector<f64>, DMatrix<f64>) { | ||
let covariance = self.covariance(); | ||
let mean = &covariance * &self.information_vector; | ||
|
||
(mean, covariance) | ||
} | ||
|
||
pub fn set_with_covariance_form(&mut self, mean: DVector<f64>, covariance: DMatrix<f64>) { | ||
// check for invertibility of covariance matrix input | ||
self.precision_matrix = covariance.try_inverse().unwrap(); | ||
self.information_vector = &self.precision_matrix * mean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
pub mod factorgraph; | ||
pub mod gaussian; | ||
|
||
pub mod prelude { | ||
pub use crate::factorgraph::factor::Factor; | ||
pub use crate::factorgraph::factorgraph::FactorGraph; | ||
pub use crate::factorgraph::message::Message; | ||
pub use crate::factorgraph::variable::Variable; | ||
pub use crate::gaussian; | ||
} |