17#include <unsupported/Eigen/Polynomials>
43 virtual bool read(std::istream& is) {
49 virtual bool write(std::ostream& os)
const {
58 Eigen::Vector3d::ConstMapType v(update, 3);
75 virtual bool read(std::istream& is) {
79 if (is.good() ==
false) {
92 virtual bool write(std::ostream& os)
const {
102 Eigen::VectorXd::ConstMapType v(update,
_dimension);
126 FPolynomialCoefficientVertex,
127 PPolynomialCoefficientVertex> {
138 virtual bool read(std::istream& is) {
147 virtual bool write(std::ostream& os)
const {
160 double x3 = pow(
_x[i], 3);
162 Eigen::poly_eval(fvertex->
estimate(),
_x[i]) -
163 x3 * (Eigen::poly_eval(pvertex->
estimate(),
_x[i]));
172int main(
int argc,
const char* argv[]) {
174 std::default_random_engine generator;
178 for (
int i = 0; i < 3; ++i) {
183 int polynomialDimension = 4;
185 polynomialDimension = atoi(argv[1]);
189 Eigen::VectorXd p(polynomialDimension);
190 for (
int i = 0; i < polynomialDimension; ++i) {
194 std::cout <<
"Ground truth vectors f=" << f.transpose()
195 <<
"; p=" << p.transpose() << std::endl;
208 std::vector<FunctionObservation> observations(obs);
209 std::uniform_int_distribution<int> cardinalitySampler(1, 5);
211 for (
int i = 0; i < obs; ++i) {
213 int numObs = cardinalitySampler(generator);
216 for (
int o = 0; o < numObs; ++o) {
218 double x3 = pow(fo.
x[o], 3);
219 fo.
z[o] = Eigen::poly_eval(f, fo.
x[o]) +
220 x3 * (Eigen::poly_eval(p, fo.
x[o])) +
226 std::unique_ptr<g2o::BlockSolverX::LinearSolverType> linearSolver =
231 std::unique_ptr<g2o::BlockSolverX> blockSolver =
232 std::make_unique<g2o::BlockSolverX>(std::move(linearSolver));
239 std::unique_ptr<g2o::SparseOptimizer> optimizer =
240 std::make_unique<g2o::SparseOptimizer>();
241 optimizer->setVerbose(
true);
242 optimizer->setAlgorithm(optimisationAlgorithm);
247 optimizer->addVertex(pf);
252 optimizer->addVertex(pv);
255 double omega = 1 / (sigmaZ * sigmaZ);
258 for (
int i = 0; i < obs; ++i) {
262 optimizer->addEdge(mve);
270 for (
int testDimension = 1; testDimension <= polynomialDimension;
273 optimizer->initializeOptimization();
274 optimizer->optimize(10);
275 std::cout <<
"Computed parameters: f=" << pf->
estimate().transpose()
276 <<
"; p=" << pv->
estimate().transpose() << std::endl;
278 for (
int testDimension = polynomialDimension - 1; testDimension >= 1;
281 optimizer->initializeOptimization();
282 optimizer->optimize(10);
283 std::cout <<
"Computed parameters: f= " << pf->
estimate().transpose()
284 <<
"; p=" << pv->
estimate().transpose() << std::endl;
virtual void oplusImpl(const double *update)
FPolynomialCoefficientVertex()
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
virtual bool write(std::ostream &os) const
write the vertex to a stream
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
virtual void computeError()
MultipleValueEdge(const FunctionObservation &obs, double omega)
virtual bool write(std::ostream &os) const
write the vertex to a stream
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
virtual void oplusImpl(const double *update)
virtual bool write(std::ostream &os) const
write the vertex to a stream
virtual bool read(std::istream &is)
read the vertex from a stream, i.e., the internal state of the vertex
PPolynomialCoefficientVertex()
virtual bool setDimensionImpl(int newDimension)
virtual void setToOriginImpl()
sets the node to the origin (used in the multilevel stuff)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
virtual bool setDimension(int newDimension)
bool writeInformationMatrix(std::ostream &os) const
write the upper trinagular part of the information matrix into the stream
bool readInformationMatrix(std::istream &is)
virtual void setMeasurement(const Measurement &m)
void setInformation(const InformationType &information)
std::enable_if< Dim==-1, void >::type setDimension(int dim)
Measurement _measurement
the measurement of the edge
BaseEdge< D, E >::InformationType InformationType
const EstimateType & estimate() const
return the current estimate of the vertex
void setVertex(size_t i, Vertex *v)
VertexContainer _vertices
linear solver which uses the sparse Cholesky solver from Eigen
int dimension() const
dimension of the estimated state belonging to this node
void setToOrigin()
sets the node to the origin (used in the multilevel stuff)
virtual void setId(int id)
Implementation of the Levenberg Algorithm.
Generic interface for a non-linear solver operating on a graph.
bool writeVector(std::ostream &os, const Eigen::DenseBase< Derived > &b)
bool readVector(std::istream &is, Eigen::DenseBase< Derived > &b)
double sampleUniform(double min, double max, std::mt19937 *generator)
double sampleGaussian(std::mt19937 *generator)