Added MATLAB-friendly versions of eliminate and optimize in LinearFactorGraph (with trailing underscore). Also fixed some MATLAB code.
parent
ac840d6f0a
commit
d585a329dc
|
@ -64,6 +64,18 @@ VectorConfig LinearFactorGraph::optimize(const Ordering& ordering)
|
||||||
return newConfig;
|
return newConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
boost::shared_ptr<GaussianBayesNet>
|
||||||
|
LinearFactorGraph::eliminate_(const Ordering& ordering) {
|
||||||
|
return boost::shared_ptr<GaussianBayesNet>(new GaussianBayesNet(eliminate(ordering)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
boost::shared_ptr<VectorConfig>
|
||||||
|
LinearFactorGraph::optimize_(const Ordering& ordering) {
|
||||||
|
return boost::shared_ptr<VectorConfig>(new VectorConfig(optimize(ordering)));
|
||||||
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void LinearFactorGraph::combine(const LinearFactorGraph &lfg){
|
void LinearFactorGraph::combine(const LinearFactorGraph &lfg){
|
||||||
for(const_iterator factor=lfg.factors_.begin(); factor!=lfg.factors_.end(); factor++){
|
for(const_iterator factor=lfg.factors_.begin(); factor!=lfg.factors_.end(); factor++){
|
||||||
|
|
|
@ -83,6 +83,12 @@ namespace gtsam {
|
||||||
*/
|
*/
|
||||||
VectorConfig optimize(const Ordering& ordering);
|
VectorConfig optimize(const Ordering& ordering);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* shared pointer versions for MATLAB
|
||||||
|
*/
|
||||||
|
boost::shared_ptr<GaussianBayesNet> eliminate_(const Ordering&);
|
||||||
|
boost::shared_ptr<VectorConfig> optimize_(const Ordering&);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* static function that combines two factor graphs
|
* static function that combines two factor graphs
|
||||||
* @param const &lfg1 Linear factor graph
|
* @param const &lfg1 Linear factor graph
|
||||||
|
|
10
cpp/gtsam.h
10
cpp/gtsam.h
|
@ -48,13 +48,13 @@ class ConditionalGaussian {
|
||||||
ConditionalGaussian(string key,
|
ConditionalGaussian(string key,
|
||||||
Vector d,
|
Vector d,
|
||||||
Matrix R,
|
Matrix R,
|
||||||
Vector precisions);
|
Vector sigmas);
|
||||||
ConditionalGaussian(string key,
|
ConditionalGaussian(string key,
|
||||||
Vector d,
|
Vector d,
|
||||||
Matrix R,
|
Matrix R,
|
||||||
string name1,
|
string name1,
|
||||||
Matrix S,
|
Matrix S,
|
||||||
Vector precisions);
|
Vector sigmas);
|
||||||
ConditionalGaussian(string key,
|
ConditionalGaussian(string key,
|
||||||
Vector d,
|
Vector d,
|
||||||
Matrix R,
|
Matrix R,
|
||||||
|
@ -62,7 +62,7 @@ class ConditionalGaussian {
|
||||||
Matrix S,
|
Matrix S,
|
||||||
string name2,
|
string name2,
|
||||||
Matrix T,
|
Matrix T,
|
||||||
Vector precisions);
|
Vector sigmas);
|
||||||
void print() const;
|
void print() const;
|
||||||
Vector solve(const VectorConfig& x);
|
Vector solve(const VectorConfig& x);
|
||||||
void add(string key, Matrix S);
|
void add(string key, Matrix S);
|
||||||
|
@ -91,8 +91,8 @@ class LinearFactorGraph {
|
||||||
void print() const;
|
void print() const;
|
||||||
bool equals(const LinearFactorGraph& lfgraph) const;
|
bool equals(const LinearFactorGraph& lfgraph) const;
|
||||||
|
|
||||||
VectorConfig optimize(const Ordering& ordering);
|
VectorConfig* optimize_(const Ordering& ordering);
|
||||||
void eliminate(const Ordering& ordering);
|
GaussianBayesNet* eliminate_(const Ordering& ordering);
|
||||||
pair<Matrix,Vector> matrix(const Ordering& ordering) const;
|
pair<Matrix,Vector> matrix(const Ordering& ordering) const;
|
||||||
Matrix sparse(const Ordering& ordering) const;
|
Matrix sparse(const Ordering& ordering) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ function c = createNoisyConfig()
|
||||||
v_x1 = [0.1; 0.1];
|
v_x1 = [0.1; 0.1];
|
||||||
v_x2 = [1.4; 0.2];
|
v_x2 = [1.4; 0.2];
|
||||||
v_l1 = [0.1; -1.1];
|
v_l1 = [0.1; -1.1];
|
||||||
c = FGConfig();
|
c = VectorConfig();
|
||||||
c.insert('x1', v_x1);
|
c.insert('x1', v_x1);
|
||||||
c.insert('x2', v_x2);
|
c.insert('x2', v_x2);
|
||||||
c.insert('l1', v_l1);
|
c.insert('l1', v_l1);
|
||||||
|
|
|
@ -26,7 +26,7 @@ Ax1 = [
|
||||||
% the RHS
|
% the RHS
|
||||||
b2=[-1;1.5;2;-1];
|
b2=[-1;1.5;2;-1];
|
||||||
|
|
||||||
combined = LinearFactor('x2', Ax2, 'l1', Al1, 'x1', Ax1, b2);
|
combined = LinearFactor('x2', Ax2, 'l1', Al1, 'x1', Ax1, b2, 1);
|
||||||
|
|
||||||
% eliminate the combined factor
|
% eliminate the combined factor
|
||||||
% NOT WORKING
|
% NOT WORKING
|
||||||
|
@ -48,7 +48,7 @@ S13 = [
|
||||||
+0.00,-8.94427
|
+0.00,-8.94427
|
||||||
];
|
];
|
||||||
d=[2.23607;-1.56525];
|
d=[2.23607;-1.56525];
|
||||||
expectedCG = ConditionalGaussian(d,R11,'l1',S12,'x1',S13);
|
expectedCG = ConditionalGaussian('x2',d,R11,'l1',S12,'x1',S13,[1 1]');
|
||||||
|
|
||||||
% the expected linear factor
|
% the expected linear factor
|
||||||
Bl1 = [
|
Bl1 = [
|
||||||
|
@ -65,7 +65,7 @@ Bx1 = [
|
||||||
% the RHS
|
% the RHS
|
||||||
b1= [0.0;0.894427];
|
b1= [0.0;0.894427];
|
||||||
|
|
||||||
expectedLF = LinearFactor('l1', Bl1, 'x1', Bx1, b1);
|
expectedLF = LinearFactor('l1', Bl1, 'x1', Bx1, b1, 1);
|
||||||
|
|
||||||
% check if the result matches
|
% check if the result matches
|
||||||
% NOT WORKING
|
% NOT WORKING
|
||||||
|
|
|
@ -62,7 +62,7 @@ for steps=1:noRuns
|
||||||
% eliminate with that ordering
|
% eliminate with that ordering
|
||||||
%time gt_sam
|
%time gt_sam
|
||||||
ck=cputime;
|
ck=cputime;
|
||||||
BayesNet = linearFactorGraph.eliminate(ord);
|
BayesNet = linearFactorGraph.eliminate_(ord);
|
||||||
time_gtsam=[time_gtsam,(cputime-ck)];
|
time_gtsam=[time_gtsam,(cputime-ck)];
|
||||||
|
|
||||||
clear trajectory visibility linearFactorGraph measurements odometry;
|
clear trajectory visibility linearFactorGraph measurements odometry;
|
||||||
|
|
Loading…
Reference in New Issue