| 48 | |
| 49 | template<int Dim> |
| 50 | void EvaluateCostSurface(ceres::Problem &Graph, |
| 51 | double * const StatePointer, |
| 52 | const int Points, |
| 53 | const double Range, |
| 54 | StateDataSet &Result) |
| 55 | { |
| 56 | typedef VectorStatic<Dim> SizedVector; |
| 57 | |
| 58 | /** configure evaluation */ |
| 59 | ceres::Problem::EvaluateOptions Options; |
| 60 | Options.apply_loss_function = true; |
| 61 | Options.num_threads = std::thread::hardware_concurrency(); |
| 62 | Options.parameter_blocks = {StatePointer}; |
| 63 | |
| 64 | /** save original value */ |
| 65 | VectorRef<double, Dim> State(StatePointer); |
| 66 | const SizedVector OriginalState = State; |
| 67 | |
| 68 | /** create 1D point set */ |
| 69 | Vector Lin = Vector::LinSpaced(Points, -Range/2, Range/2); |
| 70 | |
| 71 | /** create nD point set */ |
| 72 | std::vector<Vector> Grid; |
| 73 | for (int nDim = 0; nDim < Dim; ++nDim) |
| 74 | { |
| 75 | Grid.push_back((Lin.array() + State(nDim)).matrix()); |
| 76 | } |
| 77 | |
| 78 | /** create multi dimensional index */ |
| 79 | std::vector<int> Index; |
| 80 | for (int nDim = 0; nDim < Dim; ++nDim) |
| 81 | { |
| 82 | Index.push_back(0); |
| 83 | } |
| 84 | |
| 85 | /** loop over grid */ |
| 86 | for (uint64_t n = 0; n < std::pow(Points,Dim); ++n) |
| 87 | { |
| 88 | /** write point */ |
| 89 | for (int nDim = 0; nDim < Dim; ++nDim) |
| 90 | { |
| 91 | State.segment(nDim,1) = Grid.at(nDim).segment(Index.at(nDim),1); |
| 92 | } |
| 93 | |
| 94 | /** evaluate */ |
| 95 | double Cost; |
| 96 | std::vector<double> Gradient; |
| 97 | ceres::CRSMatrix JacobianCRS; |
| 98 | Graph.Evaluate(Options, &Cost, nullptr, &Gradient, &JacobianCRS); |
| 99 | |
| 100 | /** calculate the Hessian */ |
| 101 | Matrix Jacobian; |
| 102 | CRSToMatrix(JacobianCRS, Jacobian); |
| 103 | MatrixStatic<Dim,Dim> Hessian = Jacobian.transpose()*Jacobian; |
| 104 | |
| 105 | /** create state data to store the result */ |
| 106 | Data CostState; |
| 107 | if (Dim == 1) |
nothing calls this directly
no test coverage detected