Skip to content

Commit

Permalink
feat: add UnitInterval type
Browse files Browse the repository at this point in the history
  • Loading branch information
kpbaks committed Feb 1, 2024
1 parent 920ae6e commit 4a1dfab
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
.direnv/

*.log
59 changes: 35 additions & 24 deletions gbp-rs/src/factorgraph/factorgraph.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
use crate::factorgraph::factor::Factor;
use crate::factorgraph::variable::Variable;

use super::factor::MeasurementModel;
use super::UnitInterval;

#[derive(Debug)]
pub struct GbpSettings {
/// Absolute distance threshold between linearisation point and adjacent belief means for relinearisation
pub beta: f64,
/// Damping for the eta component of the message
pub damping: f64,
pub dropout: UnitInterval,
/// Number of undamped iterations after relinearisation before
pub num_undamped_iterations: usize,
}
/// A factor graph is a bipartite graph representing the factorization of a function.
/// It is composed of two types of nodes: factors and variables.
Expand All @@ -18,14 +28,6 @@ pub struct FactorGraph<F: Factor, V: Variable> {
// std::unique_ptr

impl<F: Factor, V: Variable> FactorGraph<F, V> {
pub fn new(gbp_settings: GbpSettings) -> Self {
Self {
factors: Vec::new(),
variables: Vec::new(),
gbp_settings,
}
}

pub fn add_factor(&mut self, factor: F) {
self.factors.push(factor);
}
Expand All @@ -34,29 +36,13 @@ impl<F: Factor, V: Variable> FactorGraph<F, V> {
self.variables.push(variable);
}

pub fn update_all_beliefs(&mut self) {
// for variable in self.variables.iter_mut() {
// variable.update_belief();
// }
todo!()
// for factor in self.factors.iter_mut() {
// factor.update_belief();
// }
}

// linearize_all_factors
fn compute_factors(&mut self) {
for factor in self.factors.iter() {
factor.compute();
}
}

fn robustify_all_factors(&mut self) {
for factor in self.factors.iter() {
factor.robustify_loss();
}
}

fn jit_linearisation(&mut self) {
for factor in self.factors.iter() {
match factor.measurement_model() {
Expand All @@ -67,7 +53,32 @@ impl<F: Factor, V: Variable> FactorGraph<F, V> {
factor.compute();
}
}
MeasurementModel::Linear => {}
}
}
}

pub fn new(gbp_settings: GbpSettings) -> Self {
Self {
factors: Vec::new(),
variables: Vec::new(),
gbp_settings,
}
}

fn robustify_all_factors(&mut self) {
for factor in self.factors.iter() {
factor.robustify_loss();
}
}

pub fn update_all_beliefs(&mut self) {
// for variable in self.variables.iter_mut() {
// variable.update_belief();
// }
todo!()
// for factor in self.factors.iter_mut() {
// factor.update_belief();
// }
}
}
9 changes: 9 additions & 0 deletions gbp-rs/src/factorgraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ pub mod message;
pub mod variable;

type NodeId = usize;

use nutype::nutype;

/// Represents a closed interval [0,1]
#[nutype(
validate(greater_or_equal = 0.0, less_or_equal = 1.0),
derive(Debug, Clone, Copy)
)]
pub struct UnitInterval(f64);
3 changes: 0 additions & 3 deletions hx.log

This file was deleted.

0 comments on commit 4a1dfab

Please sign in to comment.