-
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.
refactor: move types into their own files
- Loading branch information
Showing
9 changed files
with
155 additions
and
83 deletions.
There are no files selected for viewing
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,10 @@ | ||
/// Reimplementation of the 1D line fitting example from https://gaussianbp.github.io/ | ||
/// jupyter notebook: https://colab.research.google.com/drive/1-nrE95X4UC9FBLR0-cTnsIP_XhA_PZKW?usp=sharing#scrollTo=kiAOHWV4uMGY | ||
use gbp_rs::prelude::*; | ||
|
||
fn main() { | ||
|
||
let mut fg = FactorGraph::new(); | ||
|
||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
|
||
|
||
pub trait Factor {} | ||
|
||
#[derive(Debug)] | ||
struct DefaultFactor; | ||
#[derive(Debug)] | ||
struct DynamicFactor; | ||
#[derive(Debug)] | ||
struct InterRobotFactor; | ||
#[derive(Debug)] | ||
struct ObstacleFactor; | ||
|
||
impl Factor for DefaultFactor {} | ||
impl Factor for DynamicFactor {} | ||
impl Factor for InterRobotFactor {} | ||
impl Factor for ObstacleFactor {} | ||
|
||
#[derive(Debug)] | ||
enum FactorType { | ||
Default(DefaultFactor), | ||
Dynamic(DynamicFactor), | ||
InterRobot(InterRobotFactor), | ||
Ocstacle(ObstacleFactor), | ||
} |
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,39 @@ | ||
|
||
use crate::factorgraph::factor::Factor; | ||
use crate::factorgraph::variable::Variable; | ||
|
||
/// A factor graph is a bipartite graph representing the factorization of a function. | ||
/// It is composed of two types of nodes: factors and variables. | ||
/// | ||
pub struct FactorGraph { | ||
factors: Vec<Box<dyn Factor>>, | ||
variables: Vec<Variable>, | ||
} | ||
|
||
|
||
impl FactorGraph { | ||
pub fn new() -> Self { | ||
Self { | ||
factors: Vec::new(), | ||
variables: Vec::new(), | ||
} | ||
} | ||
|
||
pub fn add_factor(&mut self, factor: Box<dyn Factor>) { | ||
self.factors.push(factor); | ||
} | ||
|
||
pub fn add_variable(&mut self, variable: Variable) { | ||
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(); | ||
// } | ||
} | ||
} |
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,45 @@ | ||
// enum MsgPassingMode {EXTERNAL, INTERNAL}; | ||
|
||
/// Ways message passing can be performed | ||
#[derive(Debug)] | ||
enum MessagePassingMode { | ||
/// Between two different robots/factorgraphs | ||
External, | ||
/// Within a robot/factorgraph | ||
Internal, | ||
} | ||
// Eigen::VectorXd eta; | ||
// Eigen::MatrixXd lambda; | ||
// Eigen::VectorXd mu; | ||
|
||
#[derive(Debug)] | ||
pub struct Message { | ||
pub eta: nalgebra::DVector<f64>, | ||
pub lambda: nalgebra::DMatrix<f64>, | ||
pub mu: nalgebra::DVector<f64>, | ||
} | ||
|
||
// Implement addtion and subtraction for messages | ||
impl std::ops::Add for Message { | ||
type Output = Self; | ||
|
||
fn add(self, other: Self) -> Self { | ||
Self { | ||
eta: self.eta + other.eta, | ||
lambda: self.lambda + other.lambda, | ||
mu: self.mu + other.mu, | ||
} | ||
} | ||
} | ||
|
||
impl std::ops::Sub for Message { | ||
type Output = Self; | ||
|
||
fn sub(self, other: Self) -> Self { | ||
Self { | ||
eta: self.eta - other.eta, | ||
lambda: self.lambda - other.lambda, | ||
mu: self.mu - other.mu, | ||
} | ||
} | ||
} |
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,4 @@ | ||
pub mod factor; | ||
pub mod variable; | ||
pub mod factorgraph; | ||
pub mod message; |
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,21 @@ | ||
/// | ||
// pub trait Variable {} | ||
|
||
// struct RobotId(usize); | ||
type RobotId = usize; | ||
// struct NodeId(usize); | ||
type NodeId = usize; | ||
|
||
|
||
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd)] | ||
pub struct Variable { | ||
node_id: NodeId, | ||
robot_id: RobotId, | ||
} | ||
|
||
impl Variable { | ||
fn new(node_id: NodeId, robot_id: RobotId) -> Self { | ||
Self { node_id, robot_id } | ||
} | ||
} |
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,86 +1,10 @@ | ||
// struct RobotId(usize); | ||
type RobotId = usize; | ||
// struct NodeId(usize); | ||
type NodeId = usize; | ||
pub mod factorgraph; | ||
|
||
trait Factor {} | ||
|
||
#[derive(Debug)] | ||
struct DefaultFactor; | ||
#[derive(Debug)] | ||
struct DynamicFactor; | ||
#[derive(Debug)] | ||
struct InterRobotFactor; | ||
#[derive(Debug)] | ||
struct ObstacleFactor; | ||
|
||
impl Factor for DefaultFactor {} | ||
impl Factor for DynamicFactor {} | ||
impl Factor for InterRobotFactor {} | ||
impl Factor for ObstacleFactor {} | ||
|
||
#[derive(Debug)] | ||
enum FactorType { | ||
Default(DefaultFactor), | ||
Dynamic(DynamicFactor), | ||
InterRobot(InterRobotFactor), | ||
Ocstacle(ObstacleFactor), | ||
} | ||
|
||
// enum MsgPassingMode {EXTERNAL, INTERNAL}; | ||
|
||
/// Ways message passing can be performed | ||
#[derive(Debug)] | ||
enum MessagePassingMode { | ||
/// Between two different robots/factorgraphs | ||
External, | ||
/// Within a robot/factorgraph | ||
Internal, | ||
} | ||
// Eigen::VectorXd eta; | ||
// Eigen::MatrixXd lambda; | ||
// Eigen::VectorXd mu; | ||
|
||
#[derive(Debug)] | ||
struct Message { | ||
pub eta: nalgebra::DVector<f64>, | ||
pub lambda: nalgebra::DMatrix<f64>, | ||
pub mu: nalgebra::DVector<f64>, | ||
pub mod prelude { | ||
pub use crate::factorgraph::factor::Factor; | ||
pub use crate::factorgraph::factorgraph::FactorGraph; | ||
pub use crate::factorgraph::variable::Variable; | ||
pub use crate::factorgraph::message::Message; | ||
} | ||
|
||
// Implement addtion and subtraction for messages | ||
impl std::ops::Add for Message { | ||
type Output = Self; | ||
|
||
fn add(self, other: Self) -> Self { | ||
Self { | ||
eta: self.eta + other.eta, | ||
lambda: self.lambda + other.lambda, | ||
mu: self.mu + other.mu, | ||
} | ||
} | ||
} | ||
|
||
impl std::ops::Sub for Message { | ||
type Output = Self; | ||
|
||
fn sub(self, other: Self) -> Self { | ||
Self { | ||
eta: self.eta - other.eta, | ||
lambda: self.lambda - other.lambda, | ||
mu: self.mu - other.mu, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone, Eq, PartialEq, PartialOrd)] | ||
struct Variable { | ||
node_id: NodeId, | ||
robot_id: RobotId, | ||
} | ||
|
||
impl Variable { | ||
fn new(node_id: NodeId, robot_id: RobotId) -> Self { | ||
Self { node_id, robot_id } | ||
} | ||
} |