Skip to content

Commit

Permalink
Cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
contagon committed Dec 17, 2024
1 parent 8127c1e commit 42fa235
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 46 deletions.
72 changes: 35 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,48 +42,46 @@ Additionally, we recommend checking out the [tests](/tests/) folder for more exa

```rust
use factrs::{
assign_symbols,
fac,
containers::{FactorBuilder, Graph, Values},
noise::GaussianNoise,
optimizers::GaussNewton,
residuals::{BetweenResidual, PriorResidual},
robust::Huber,
traits::*,
variables::SO2,
core::{
assign_symbols, fac, BetweenResidual, GaussNewton, Graph, Huber, PriorResidual, Values, SO2,
},
traits::*,
};

// Assign symbols to variable types
assign_symbols!(X: SO2);

// Make all the values
let mut values = Values::new();

let x = SO2::from_theta(1.0);
let y = SO2::from_theta(2.0);
values.insert(X(0), SO2::identity());
values.insert(X(1), SO2::identity());

// Make the factors & insert into graph
let mut graph = Graph::new();
let res = PriorResidual::new(x.clone());
let factor = fac![res, X(0)];
graph.add_factor(factor);

let res = BetweenResidual::new(y.minus(&x));
let robust = Huber::default();
let factor = fac![res, (X(0), X(1)), 0.1 as std, robust];
// fac! is syntactic sugar for the following
// let noise = GaussianNoise::from_scalar_sigma(0.1);
// let factor = FactorBuilder::new2(res, X(0), X(1))
// .noise(noise)
// .robust(robust)
// .build();
graph.add_factor(factor);

// Optimize!
let mut opt: GaussNewton = GaussNewton::new(graph);
let result = opt.optimize(values);
fn main() {
// Make all the values
let mut values = Values::new();

let x = SO2::from_theta(1.0);
let y = SO2::from_theta(2.0);
values.insert(X(0), SO2::identity());
values.insert(X(1), SO2::identity());

// Make the factors & insert into graph
let mut graph = Graph::new();
let res = PriorResidual::new(x.clone());
let factor = fac![res, X(0)];
graph.add_factor(factor);

let res = BetweenResidual::new(y.minus(&x));
let robust = Huber::default();
let factor = fac![res, (X(0), X(1)), 0.1 as std, robust];
// fac! is syntactic sugar for the following
// let noise = GaussianNoise::from_scalar_sigma(0.1);
// let factor = FactorBuilder::new2(res, X(0), X(1))
// .noise(noise)
// .robust(robust)
// .build();
graph.add_factor(factor);

// Optimize!
let mut opt: GaussNewton = GaussNewton::new(graph);
let result = opt.optimize(values).unwrap();
println!("Results {:#}", result);
}
```

# Installation
Expand Down
41 changes: 41 additions & 0 deletions examples/readme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use factrs::{
core::{
assign_symbols, fac, BetweenResidual, GaussNewton, Graph, Huber, PriorResidual, Values, SO2,
},
traits::*,
};

// Assign symbols to variable types
assign_symbols!(X: SO2);

fn main() {
// Make all the values
let mut values = Values::new();

let x = SO2::from_theta(1.0);
let y = SO2::from_theta(2.0);
values.insert(X(0), SO2::identity());
values.insert(X(1), SO2::identity());

// Make the factors & insert into graph
let mut graph = Graph::new();
let res = PriorResidual::new(x.clone());
let factor = fac![res, X(0)];
graph.add_factor(factor);

let res = BetweenResidual::new(y.minus(&x));
let robust = Huber::default();
let factor = fac![res, (X(0), X(1)), 0.1 as std, robust];
// fac! is syntactic sugar for the following
// let noise = GaussianNoise::from_scalar_sigma(0.1);
// let factor = FactorBuilder::new2(res, X(0), X(1))
// .noise(noise)
// .robust(robust)
// .build();
graph.add_factor(factor);

// Optimize!
let mut opt: GaussNewton = GaussNewton::new(graph);
let result = opt.optimize(values).unwrap();
println!("Results {:#}", result);
}
9 changes: 2 additions & 7 deletions examples/serde.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use factrs::{
assign_symbols,
containers::{Graph, Values},
fac,
residuals::{BetweenResidual, PriorResidual},
robust::GemanMcClure,
variables::{SE2, SO2},
use factrs::core::{
assign_symbols, fac, BetweenResidual, GemanMcClure, Graph, PriorResidual, Values, SE2, SO2,
};

assign_symbols!(X: SO2; Y: SE2);
Expand Down
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,20 @@ pub mod traits {
/// Helper module to group together common types
///
/// Specifically, this contains everything that would be needed to implement a
/// simple pose graph. While we recommend against it, it can be all imported
/// using
/// simple pose graph. While we recommend against it, for quick usage it can be
/// glob imported as
/// ```
/// use factrs::core::*;
/// ```
pub mod core {
pub use crate::{
assign_symbols,
containers::{Factor, Graph, Values},
fac,
noise::{GaussianNoise, UnitNoise},
optimizers::{GaussNewton, LevenMarquardt},
residuals::{BetweenResidual, PriorResidual},
robust::{GemanMcClure, Huber, L2},
variables::{VectorVar, VectorVar1, VectorVar2, VectorVar3, SE2, SE3, SO2, SO3},
};
}
Expand Down

0 comments on commit 42fa235

Please sign in to comment.