covariance_estimation.cpp
Go to the documentation of this file.
00001 #include "covariance_estimation.h"
00002 #include <iostream>
00003 #include <fstream>
00004 
00005 
00006 Vector6d toVectorScaledAxis(Vector6d vecMQT)
00007 {
00008     return vecMQT;
00009     /*
00010     double sqr_nrm = vecMQT.tail<3>().squaredNorm();
00011     if(!(sqr_nrm > 0.0 && sqr_nrm <= 1.0)){ //No (valid) rotation
00012       vecMQT.tail<3>().setZero();
00013       //std::cerr << "\nSquared Norm is " << sqr_nrm << ", setting rotational part to zero\n";
00014     } else {
00015       double qw = std::sqrt(1 - sqr_nrm);
00016       double alpha = 2*std::acos(qw);
00017       double factor = alpha / std::sqrt(sqr_nrm); //to normalize axis and multiply with angle
00018       vecMQT.tail<3>() = vecMQT.tail<3>() * factor;
00019       //std::cout << "VecScAx: " << vecMQT.transpose() << "\t";
00020       //std::cout << "sqr_nrm: " << sqr_nrm << "\t";
00021       //std::cout << "qw:      " << qw << "\t";
00022       //std::cout << "alpha:   " << alpha << "\n";
00023     }
00024     return vecMQT;
00025     */
00026 }
00027 
00028 Vector6d toVectorScaledAxis(const Eigen::Isometry3d& tf)
00029 {
00030     Vector6d vecMQT = g2o::internal::toVectorMQT(tf);
00031     return toVectorScaledAxis(vecMQT);
00032 }
00033 
00034 inline Vector6d absManhattanDistance(const Eigen::Isometry3d& tf1,
00035                                           const Eigen::Isometry3d& tf2)
00036 {
00037   return (toVectorScaledAxis(tf1) - toVectorScaledAxis(tf2)).cwiseAbs();
00038 }
00039 
00040 
00041 InfoMatType computeEmpiricalInformationMatrix(const Matrix6Xd& measurements,
00042                                               const Matrix6Xd& errors,
00043                                               const Vector6d& currentMeasurement,
00044                                               const Vector6d& stdDeviation)
00045 {
00046   ScopedTimer s(__FUNCTION__);
00047   //g2o::EdgeSE3::InformationType covarianceMatrix;
00048   //This function assumes the DOFs to be independent and therefore works
00049   //with vectors that represent the diagonal matrices (covariances)
00050   Vector6d covarianceMatrixDiag = Vector6d::Zero();
00051   Vector6d sum_of_weights = Vector6d::Zero();
00052 
00053   //Precomputation of weights and weighted errors
00054   Matrix6Xd distanceMat = (measurements.colwise() - currentMeasurement).cwiseAbs();
00055   //Vector6d stdDistance = distanceMat.rowwise().mean(); //Now use stddeviation from global mean, not from this measurement -> outlier transformation should get lower weights for variance of other measurements and therefore more or less speak for themself
00056   distanceMat = stdDeviation.cwiseInverse().asDiagonal() * distanceMat; 
00057   distanceMat = distanceMat.cwiseProduct(distanceMat);
00058 
00059   size_t size = measurements.cols();
00060   Vector6d weight, weightedError;
00061   for(size_t i = 0; i < size; ++i)
00062   {
00063     for(size_t r = 0; r < 6; ++r){ //Weighting by similarity per dimension
00064       weight(r) = exp(-0.5*distanceMat(r,i)); // Gaussian model, with precomputed exponent
00065     }
00066     weightedError = weight.cwiseProduct(errors.col(i));
00067     covarianceMatrixDiag += weightedError.cwiseProduct(weightedError);
00068     sum_of_weights += weight;
00069   }
00070 
00071   //Note: Empirical covariance should be computed with division by N-1.
00072   //Since each of the N components is weighted, an open question is how much is the "-1"
00073   covarianceMatrixDiag = covarianceMatrixDiag.cwiseQuotient(sum_of_weights); 
00074   InfoMatType informationMatrix = covarianceMatrixDiag.cwiseInverse().asDiagonal();
00075   
00076   return informationMatrix;
00077 }
00078 


rgbdslam_v2
Author(s): Felix Endres, Juergen Hess, Nikolas Engelhard
autogenerated on Thu Jun 6 2019 21:49:45