MCPcopy Create free account
hub / github.com/AutonomousFieldRoboticsLab/SVIn / getLhs

Method getLhs

okvis_ros/okvis/okvis_ceres/src/Map.cpp:105–150  ·  view source on GitHub ↗

Obtain the Hessian block for a specific parameter block.

Source from the content-addressed store, hash-verified

103
104// Obtain the Hessian block for a specific parameter block.
105void Map::getLhs(uint64_t parameterBlockId, Eigen::MatrixXd& H) {
106 OKVIS_ASSERT_TRUE_DBG(Exception, parameterBlockExists(parameterBlockId), "parameter block not in map.");
107 ResidualBlockCollection res = residuals(parameterBlockId);
108 H.setZero();
109 for (size_t i = 0; i < res.size(); ++i) {
110 // parameters:
111 ParameterBlockCollection pars = parameters(res[i].residualBlockId);
112
113 double** parametersRaw = new double*[pars.size()];
114 Eigen::VectorXd residualsEigen(res[i].errorInterfacePtr->residualDim());
115 double* residualsRaw = residualsEigen.data();
116
117 double** jacobiansRaw = new double*[pars.size()];
118 std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>,
119 Eigen::aligned_allocator<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > >
120 jacobiansEigen(pars.size());
121
122 double** jacobiansMinimalRaw = new double*[pars.size()];
123 std::vector<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>,
124 Eigen::aligned_allocator<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> > >
125 jacobiansMinimalEigen(pars.size());
126
127 int J = -1;
128 for (size_t j = 0; j < pars.size(); ++j) {
129 // determine which is the relevant block
130 if (pars[j].second->id() == parameterBlockId) J = j;
131 parametersRaw[j] = pars[j].second->parameters();
132 jacobiansEigen[j].resize(res[i].errorInterfacePtr->residualDim(), pars[j].second->dimension());
133 jacobiansRaw[j] = jacobiansEigen[j].data();
134 jacobiansMinimalEigen[j].resize(res[i].errorInterfacePtr->residualDim(), pars[j].second->minimalDimension());
135 jacobiansMinimalRaw[j] = jacobiansMinimalEigen[j].data();
136 }
137
138 // evaluate residual block
139 res[i].errorInterfacePtr->EvaluateWithMinimalJacobians(
140 parametersRaw, residualsRaw, jacobiansRaw, jacobiansMinimalRaw);
141
142 // get block
143 H += jacobiansMinimalEigen[J].transpose() * jacobiansMinimalEigen[J];
144
145 // cleanup
146 delete[] parametersRaw;
147 delete[] jacobiansRaw;
148 delete[] jacobiansMinimalRaw;
149 }
150}
151
152// Check a Jacobian with numeric differences.
153bool Map::isJacobianCorrect(::ceres::ResidualBlockId residualBlockId, double relTol) const {

Callers 1

optimizeMethod · 0.80

Calls 7

dimensionMethod · 0.80
minimalDimensionMethod · 0.80
sizeMethod · 0.45
residualDimMethod · 0.45
idMethod · 0.45
parametersMethod · 0.45

Tested by

no test coverage detected