g2o
Loading...
Searching...
No Matches
Typedefs | Functions
g2o_hierarchical_test_functions.cpp File Reference
#include <signal.h>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <algorithm>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include "edge_creator.h"
#include "edge_labeler.h"
#include "g2o/apps/g2o_cli/dl_wrapper.h"
#include "g2o/apps/g2o_cli/g2o_common.h"
#include "g2o/apps/g2o_cli/output_helper.h"
#include "g2o/core/estimate_propagator.h"
#include "g2o/core/factory.h"
#include "g2o/core/hyper_dijkstra.h"
#include "g2o/core/optimization_algorithm_factory.h"
#include "g2o/core/sparse_optimizer.h"
#include "g2o/stuff/color_macros.h"
#include "g2o/stuff/command_args.h"
#include "g2o/stuff/filesys_tools.h"
#include "g2o/stuff/macros.h"
#include "g2o/stuff/string_tools.h"
#include "g2o/stuff/timeutil.h"
#include "g2o/stuff/unscented.h"
#include "star.h"
Include dependency graph for g2o_hierarchical_test_functions.cpp:

Go to the source code of this file.

Typedefs

typedef SigmaPoint< VectorXd > MySigmaPoint
 

Functions

void testMarginals (SparseOptimizer &optimizer)
 
int unscentedTest ()
 

Typedef Documentation

◆ MySigmaPoint

typedef SigmaPoint<VectorXd> MySigmaPoint

Definition at line 62 of file g2o_hierarchical_test_functions.cpp.

Function Documentation

◆ testMarginals()

void testMarginals ( SparseOptimizer optimizer)

Definition at line 64 of file g2o_hierarchical_test_functions.cpp.

64 {
65 cerr << "Projecting marginals" << endl;
66 std::vector<std::pair<int, int> > blockIndices;
67 for (size_t i = 0; i < optimizer.activeVertices().size(); i++) {
68 OptimizableGraph::Vertex* v = optimizer.activeVertices()[i];
69 if (v->hessianIndex() >= 0) {
70 blockIndices.push_back(make_pair(v->hessianIndex(), v->hessianIndex()));
71 }
72 // if (v->hessianIndex()>0){
73 // blockIndices.push_back(make_pair(v->hessianIndex()-1,
74 // v->hessianIndex()));
75 // }
76 }
78 if (optimizer.computeMarginals(spinv, blockIndices)) {
79 for (size_t i = 0; i < optimizer.activeVertices().size(); i++) {
80 OptimizableGraph::Vertex* v = optimizer.activeVertices()[i];
81 cerr << "Vertex id:" << v->id() << endl;
82 if (v->hessianIndex() >= 0) {
83 cerr << "increments block :" << v->hessianIndex() << ", "
84 << v->hessianIndex() << " covariance:" << endl;
85 VectorXd mean(
86 v->minimalEstimateDimension()); // HACK: need to set identity
87 mean.fill(0);
88 VectorXd oldMean(
89 v->minimalEstimateDimension()); // HACK: need to set identity
90 v->getMinimalEstimateData(&oldMean[0]);
91 MatrixXd& cov = *(spinv.block(v->hessianIndex(), v->hessianIndex()));
92 std::vector<MySigmaPoint> spts;
93 cerr << cov << endl;
94 if (!sampleUnscented(spts, mean, cov)) continue;
95
96 // now apply the oplus operator to the sigma points,
97 // and get the points in the global space
98 std::vector<MySigmaPoint> tspts = spts;
99
100 for (size_t j = 0; j < spts.size(); j++) {
101 v->push();
102 // cerr << "v_before [" << j << "]" << endl;
103 v->getMinimalEstimateData(&mean[0]);
104 // cerr << mean << endl;
105 // cerr << "sigma [" << j << "]" << endl;
106 // cerr << spts[j]._sample << endl;
107 v->oplus(&(spts[j]._sample[0]));
108 v->getMinimalEstimateData(&mean[0]);
109 tspts[j]._sample = mean;
110 // cerr << "oplus [" << j << "]" << endl;
111 // cerr << tspts[j]._sample << endl;
112 v->pop();
113 }
114 MatrixXd cov2 = cov;
115 reconstructGaussian(mean, cov2, tspts);
116 cerr << "global block :" << v->hessianIndex() << ", "
117 << v->hessianIndex() << endl;
118 cerr << "mean: " << endl;
119 cerr << mean << endl;
120 cerr << "oldMean: " << endl;
121 cerr << oldMean << endl;
122 cerr << "cov: " << endl;
123 cerr << cov2 << endl;
124 }
125 // if (v->hessianIndex()>0){
126 // cerr << "inv block :" << v->hessianIndex()-1 << ", " <<
127 // v->hessianIndex()<< endl; cerr << *(spinv.block(v->hessianIndex()-1,
128 // v->hessianIndex())); cerr << endl;
129 // }
130 }
131 }
132}
int id() const
returns the id
A general case Vertex for optimization.
virtual void push()=0
backup the position of the vertex to a stack
virtual bool getMinimalEstimateData(double *estimate) const
virtual int minimalEstimateDimension() const
Sparse matrix which uses blocks.
SparseMatrixBlock * block(int r, int c, bool alloc=false)
const VertexContainer & activeVertices() const
the vertices active in the current optimization
bool computeMarginals(SparseBlockMatrix< MatrixX > &spinv, const std::vector< std::pair< int, int > > &blockIndices)
void reconstructGaussian(SampleType &mean, CovarianceType &covariance, const std::vector< SigmaPoint< SampleType > > &sigmaPoints)
Definition unscented.h:77
bool sampleUnscented(std::vector< SigmaPoint< SampleType > > &sigmaPoints, const SampleType &mean, const CovarianceType &covariance)
Definition unscented.h:48

References g2o::SparseOptimizer::activeVertices(), g2o::SparseBlockMatrix< MatrixType >::block(), g2o::SparseOptimizer::computeMarginals(), g2o::OptimizableGraph::Vertex::getMinimalEstimateData(), g2o::OptimizableGraph::Vertex::hessianIndex(), g2o::HyperGraph::Vertex::id(), g2o::OptimizableGraph::Vertex::minimalEstimateDimension(), g2o::OptimizableGraph::Vertex::oplus(), g2o::OptimizableGraph::Vertex::pop(), g2o::OptimizableGraph::Vertex::push(), g2o::reconstructGaussian(), and g2o::sampleUnscented().

◆ unscentedTest()

int unscentedTest ( )

Definition at line 134 of file g2o_hierarchical_test_functions.cpp.

134 {
135 MatrixXd m = MatrixXd(6, 6);
136 for (int i = 0; i < 6; i++) {
137 for (int j = i; j < 6; j++) {
138 m(i, j) = m(j, i) = i * j + 1;
139 }
140 }
141 m += MatrixXd::Identity(6, 6);
142 cerr << m;
143 VectorXd mean(6);
144 mean.fill(1);
145
146 std::vector<MySigmaPoint> spts;
147 sampleUnscented(spts, mean, m);
148 for (size_t i = 0; i < spts.size(); i++) {
149 cerr << "Point " << i << " " << endl
150 << "wi=" << spts[i]._wi << " wp=" << spts[i]._wp << " " << endl;
151 cerr << spts[i]._sample << endl;
152 }
153
154 VectorXd recMean(6);
155 MatrixXd recCov(6, 6);
156
157 reconstructGaussian(recMean, recCov, spts);
158
159 cerr << "recMean" << endl;
160 cerr << recMean << endl;
161
162 cerr << "recCov" << endl;
163 cerr << recCov << endl;
164
165 return 0;
166}

References g2o::reconstructGaussian(), and g2o::sampleUnscented().