class QuadraticCostFunction : public ceres::SizedCostFunction < 4, 1, 1, 1, 1 >{public: virtual ~QuadraticCostFunction() {} virtual bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const { const double x1 = parameters[0][0]; const double x2 = parameters[1][0]; const double x3 = parameters[2][0]; const double x4 = parameters[3][0]; residuals[0] = x1 + 10.0*x2; residuals[1] = sqrt(5)*(x3 - x4); residuals[2] = pow((x2 - 2.0*x3), 2); residuals[3] = sqrt(10.0)*pow((x1 - x4), 2);
if (jacobians != NULL && jacobians[0] != NULL) { jacobians[0][0] = 1.0; jacobians[0][1] = 10.0; jacobians[0][2] = 0.0; jacobians[0][3] = 0.0;
jacobians[1][0] = 0.0; jacobians[1][1] = 0.0; jacobians[1][2] = sqrt(5.0); jacobians[1][3] = -sqrt(5.0);
jacobians[2][0] = 0.0; jacobians[2][1] = 2.0*(x2 - 2.0*x3); jacobians[2][2] = -4.0*(x2 - 2.0*x3); jacobians[2][3] = 0.0;
jacobians[3][0] = 2.0*sqrt(10)*(x1 - x4); jacobians[3][1] = 0.0; jacobians[3][2] = 0.0; jacobians[3][3] = -2.0*sqrt(10)*(x1 - x4); } return true; }}; double params[4] = { 0.0, 0.0, 0.0, 0.0 };
Problem problem; CostFunction * cost_function = new QuadraticCostFunction; problem.AddResidualBlock(cost_function, NULL, params); Solver::Options options;
options.linear_solver_type = ceres::DENSE_QR; options.minimizer_progress_to_stdout = true; Solver::Summary summary; Solve(options, &problem, &summary);
--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/48caec29-8658-48ea-8456-8446f356c260%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class QuadraticCostFunction : public ceres::SizedCostFunction < 4, 4 > /* I believe these entries are Num_residuals, size of x1, x2, x3 & x4... */ {public: virtual ~QuadraticCostFunction() {} virtual bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const { const double x1 = parameters[0][0]; const double x2 = parameters[0][1]; const double x3 = parameters[0][2]; const double x4 = parameters[0][3]; residuals[0] = x1 + 10.0*x2; residuals[1] = sqrt(5)*(x3 - x4); residuals[2] = pow((x2 - 2.0*x3), 2); residuals[3] = sqrt(10.0)*pow((x1 - x4), 2);
if (jacobians != NULL && jacobians[0] != NULL) { jacobians[0][0] = 1.0; jacobians[0][1] = 10.0; jacobians[0][2] = 0.0; jacobians[0][3] = 0.0;
jacobians[1][0] = 0.0; jacobians[1][1] = 0.0; jacobians[1][2] = sqrt(5.0); jacobians[1][3] = -sqrt(5.0);
jacobians[2][0] = 0.0; jacobians[2][1] = 2.0*(x2 - 2.0*x3); jacobians[2][2] = -4.0*(x2 - 2.0*x3); jacobians[2][3] = 0.0;
jacobians[3][0] = 2.0*sqrt(10)*(x1 - x4); jacobians[3][1] = 0.0; jacobians[3][2] = 0.0; jacobians[3][3] = -2.0*sqrt(10)*(x1 - x4); } return true; }};To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/69104e25-e096-4e9b-8506-f53cf62b10d2%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/69104e25-e096-4e9b-8506-f53cf62b10d2%40googlegroups.com.