blob: 94c716224cfd8981e1095336dffaca56709397f0 [file] [log] [blame]
Austin Schuh70cc9552019-01-21 19:46:48 -08001// Ceres Solver - A fast non-linear least squares minimizer
Austin Schuh3de38b02024-06-25 18:25:10 -07002// Copyright 2023 Google Inc. All rights reserved.
Austin Schuh70cc9552019-01-21 19:46:48 -08003// http://ceres-solver.org/
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7//
8// * Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above copyright notice,
11// this list of conditions and the following disclaimer in the documentation
12// and/or other materials provided with the distribution.
13// * Neither the name of Google Inc. nor the names of its contributors may be
14// used to endorse or promote products derived from this software without
15// specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27// POSSIBILITY OF SUCH DAMAGE.
28//
29// Author: keir@google.com (Keir Mierle)
30// sameeragarwal@google.com (Sameer Agarwal)
31//
32// This tests the TrustRegionMinimizer loop using a direct Evaluator
33// implementation, rather than having a test that goes through all the
34// Program and Problem machinery.
35
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080036#include "ceres/trust_region_minimizer.h"
37
Austin Schuh70cc9552019-01-21 19:46:48 -080038#include <cmath>
Austin Schuh3de38b02024-06-25 18:25:10 -070039#include <memory>
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080040
Austin Schuh70cc9552019-01-21 19:46:48 -080041#include "ceres/autodiff_cost_function.h"
42#include "ceres/cost_function.h"
43#include "ceres/dense_qr_solver.h"
44#include "ceres/dense_sparse_matrix.h"
45#include "ceres/evaluator.h"
Austin Schuh3de38b02024-06-25 18:25:10 -070046#include "ceres/internal/export.h"
Austin Schuh70cc9552019-01-21 19:46:48 -080047#include "ceres/linear_solver.h"
48#include "ceres/minimizer.h"
49#include "ceres/problem.h"
Austin Schuh70cc9552019-01-21 19:46:48 -080050#include "ceres/trust_region_strategy.h"
51#include "gtest/gtest.h"
52
Austin Schuh3de38b02024-06-25 18:25:10 -070053namespace ceres::internal {
Austin Schuh70cc9552019-01-21 19:46:48 -080054
55// Templated Evaluator for Powell's function. The template parameters
56// indicate which of the four variables/columns of the jacobian are
57// active. This is equivalent to constructing a problem and using the
Austin Schuh3de38b02024-06-25 18:25:10 -070058// SubsetManifold. This allows us to test the support for
Austin Schuh70cc9552019-01-21 19:46:48 -080059// the Evaluator::Plus operation besides checking for the basic
60// performance of the trust region algorithm.
61template <bool col1, bool col2, bool col3, bool col4>
62class PowellEvaluator2 : public Evaluator {
63 public:
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080064 // clang-format off
Austin Schuh70cc9552019-01-21 19:46:48 -080065 PowellEvaluator2()
66 : num_active_cols_(
67 (col1 ? 1 : 0) +
68 (col2 ? 1 : 0) +
69 (col3 ? 1 : 0) +
70 (col4 ? 1 : 0)) {
71 VLOG(1) << "Columns: "
72 << col1 << " "
73 << col2 << " "
74 << col3 << " "
75 << col4;
76 }
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080077 // clang-format on
Austin Schuh70cc9552019-01-21 19:46:48 -080078
Austin Schuh70cc9552019-01-21 19:46:48 -080079 // Implementation of Evaluator interface.
Austin Schuh3de38b02024-06-25 18:25:10 -070080 std::unique_ptr<SparseMatrix> CreateJacobian() const final {
Austin Schuh70cc9552019-01-21 19:46:48 -080081 CHECK(col1 || col2 || col3 || col4);
Austin Schuh3de38b02024-06-25 18:25:10 -070082 auto dense_jacobian = std::make_unique<DenseSparseMatrix>(
83 NumResiduals(), NumEffectiveParameters());
Austin Schuh70cc9552019-01-21 19:46:48 -080084 dense_jacobian->SetZero();
85 return dense_jacobian;
86 }
87
Austin Schuh1d1e6ea2020-12-23 21:56:30 -080088 bool Evaluate(const Evaluator::EvaluateOptions& evaluate_options,
89 const double* state,
90 double* cost,
91 double* residuals,
92 double* gradient,
93 SparseMatrix* jacobian) final {
Austin Schuh70cc9552019-01-21 19:46:48 -080094 const double x1 = state[0];
95 const double x2 = state[1];
96 const double x3 = state[2];
97 const double x4 = state[3];
98
99 VLOG(1) << "State: "
100 << "x1=" << x1 << ", "
101 << "x2=" << x2 << ", "
102 << "x3=" << x3 << ", "
103 << "x4=" << x4 << ".";
104
105 const double f1 = x1 + 10.0 * x2;
106 const double f2 = sqrt(5.0) * (x3 - x4);
107 const double f3 = pow(x2 - 2.0 * x3, 2.0);
108 const double f4 = sqrt(10.0) * pow(x1 - x4, 2.0);
109
110 VLOG(1) << "Function: "
111 << "f1=" << f1 << ", "
112 << "f2=" << f2 << ", "
113 << "f3=" << f3 << ", "
114 << "f4=" << f4 << ".";
115
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800116 *cost = (f1 * f1 + f2 * f2 + f3 * f3 + f4 * f4) / 2.0;
Austin Schuh70cc9552019-01-21 19:46:48 -0800117
118 VLOG(1) << "Cost: " << *cost;
119
Austin Schuh3de38b02024-06-25 18:25:10 -0700120 if (residuals != nullptr) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800121 residuals[0] = f1;
122 residuals[1] = f2;
123 residuals[2] = f3;
124 residuals[3] = f4;
125 }
126
Austin Schuh3de38b02024-06-25 18:25:10 -0700127 if (jacobian != nullptr) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800128 DenseSparseMatrix* dense_jacobian;
129 dense_jacobian = down_cast<DenseSparseMatrix*>(jacobian);
130 dense_jacobian->SetZero();
131
Austin Schuh3de38b02024-06-25 18:25:10 -0700132 Matrix& jacobian_matrix = *(dense_jacobian->mutable_matrix());
Austin Schuh70cc9552019-01-21 19:46:48 -0800133 CHECK_EQ(jacobian_matrix.cols(), num_active_cols_);
134
135 int column_index = 0;
136 if (col1) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800137 // clang-format off
Austin Schuh70cc9552019-01-21 19:46:48 -0800138 jacobian_matrix.col(column_index++) <<
139 1.0,
140 0.0,
141 0.0,
Austin Schuh3de38b02024-06-25 18:25:10 -0700142 sqrt(10.0) * 2.0 * (x1 - x4);
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800143 // clang-format on
Austin Schuh70cc9552019-01-21 19:46:48 -0800144 }
145 if (col2) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800146 // clang-format off
Austin Schuh70cc9552019-01-21 19:46:48 -0800147 jacobian_matrix.col(column_index++) <<
148 10.0,
149 0.0,
Austin Schuh3de38b02024-06-25 18:25:10 -0700150 2.0*(x2 - 2.0*x3),
Austin Schuh70cc9552019-01-21 19:46:48 -0800151 0.0;
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800152 // clang-format on
Austin Schuh70cc9552019-01-21 19:46:48 -0800153 }
154
155 if (col3) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800156 // clang-format off
Austin Schuh70cc9552019-01-21 19:46:48 -0800157 jacobian_matrix.col(column_index++) <<
158 0.0,
159 sqrt(5.0),
Austin Schuh3de38b02024-06-25 18:25:10 -0700160 4.0*(2.0*x3 - x2),
Austin Schuh70cc9552019-01-21 19:46:48 -0800161 0.0;
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800162 // clang-format on
Austin Schuh70cc9552019-01-21 19:46:48 -0800163 }
164
165 if (col4) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800166 // clang-format off
Austin Schuh70cc9552019-01-21 19:46:48 -0800167 jacobian_matrix.col(column_index++) <<
168 0.0,
169 -sqrt(5.0),
170 0.0,
Austin Schuh3de38b02024-06-25 18:25:10 -0700171 sqrt(10.0) * 2.0 * (x4 - x1);
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800172 // clang-format on
Austin Schuh70cc9552019-01-21 19:46:48 -0800173 }
174 VLOG(1) << "\n" << jacobian_matrix;
175 }
176
Austin Schuh3de38b02024-06-25 18:25:10 -0700177 if (gradient != nullptr) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800178 int column_index = 0;
179 if (col1) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800180 gradient[column_index++] = f1 + f4 * sqrt(10.0) * 2.0 * (x1 - x4);
Austin Schuh70cc9552019-01-21 19:46:48 -0800181 }
182
183 if (col2) {
184 gradient[column_index++] = f1 * 10.0 + f3 * 2.0 * (x2 - 2.0 * x3);
185 }
186
187 if (col3) {
188 gradient[column_index++] =
Austin Schuh3de38b02024-06-25 18:25:10 -0700189 f2 * sqrt(5.0) + f3 * (4.0 * (2.0 * x3 - x2));
Austin Schuh70cc9552019-01-21 19:46:48 -0800190 }
191
192 if (col4) {
193 gradient[column_index++] =
194 -f2 * sqrt(5.0) + f4 * sqrt(10.0) * 2.0 * (x4 - x1);
195 }
196 }
197
198 return true;
199 }
200
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800201 bool Plus(const double* state,
202 const double* delta,
203 double* state_plus_delta) const final {
Austin Schuh70cc9552019-01-21 19:46:48 -0800204 int delta_index = 0;
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800205 state_plus_delta[0] = (col1 ? state[0] + delta[delta_index++] : state[0]);
206 state_plus_delta[1] = (col2 ? state[1] + delta[delta_index++] : state[1]);
207 state_plus_delta[2] = (col3 ? state[2] + delta[delta_index++] : state[2]);
208 state_plus_delta[3] = (col4 ? state[3] + delta[delta_index++] : state[3]);
Austin Schuh70cc9552019-01-21 19:46:48 -0800209 return true;
210 }
211
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800212 int NumEffectiveParameters() const final { return num_active_cols_; }
213 int NumParameters() const final { return 4; }
214 int NumResiduals() const final { return 4; }
Austin Schuh70cc9552019-01-21 19:46:48 -0800215
216 private:
217 const int num_active_cols_;
218};
219
220// Templated function to hold a subset of the columns fixed and check
221// if the solver converges to the optimal values or not.
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800222template <bool col1, bool col2, bool col3, bool col4>
Austin Schuh70cc9552019-01-21 19:46:48 -0800223void IsTrustRegionSolveSuccessful(TrustRegionStrategyType strategy_type) {
224 Solver::Options solver_options;
225 LinearSolver::Options linear_solver_options;
226 DenseQRSolver linear_solver(linear_solver_options);
227
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800228 double parameters[4] = {3, -1, 0, 1.0};
Austin Schuh70cc9552019-01-21 19:46:48 -0800229
230 // If the column is inactive, then set its value to the optimal
231 // value.
232 parameters[0] = (col1 ? parameters[0] : 0.0);
233 parameters[1] = (col2 ? parameters[1] : 0.0);
234 parameters[2] = (col3 ? parameters[2] : 0.0);
235 parameters[3] = (col4 ? parameters[3] : 0.0);
236
237 Minimizer::Options minimizer_options(solver_options);
238 minimizer_options.gradient_tolerance = 1e-26;
239 minimizer_options.function_tolerance = 1e-26;
240 minimizer_options.parameter_tolerance = 1e-26;
Austin Schuh3de38b02024-06-25 18:25:10 -0700241 minimizer_options.evaluator =
242 std::make_unique<PowellEvaluator2<col1, col2, col3, col4>>();
243 minimizer_options.jacobian = minimizer_options.evaluator->CreateJacobian();
Austin Schuh70cc9552019-01-21 19:46:48 -0800244
245 TrustRegionStrategy::Options trust_region_strategy_options;
246 trust_region_strategy_options.trust_region_strategy_type = strategy_type;
247 trust_region_strategy_options.linear_solver = &linear_solver;
248 trust_region_strategy_options.initial_radius = 1e4;
249 trust_region_strategy_options.max_radius = 1e20;
250 trust_region_strategy_options.min_lm_diagonal = 1e-6;
251 trust_region_strategy_options.max_lm_diagonal = 1e32;
Austin Schuh3de38b02024-06-25 18:25:10 -0700252 minimizer_options.trust_region_strategy =
253 TrustRegionStrategy::Create(trust_region_strategy_options);
Austin Schuh70cc9552019-01-21 19:46:48 -0800254
255 TrustRegionMinimizer minimizer;
256 Solver::Summary summary;
257 minimizer.Minimize(minimizer_options, parameters, &summary);
258
259 // The minimum is at x1 = x2 = x3 = x4 = 0.
260 EXPECT_NEAR(0.0, parameters[0], 0.001);
261 EXPECT_NEAR(0.0, parameters[1], 0.001);
262 EXPECT_NEAR(0.0, parameters[2], 0.001);
263 EXPECT_NEAR(0.0, parameters[3], 0.001);
264}
265
266TEST(TrustRegionMinimizer, PowellsSingularFunctionUsingLevenbergMarquardt) {
267 // This case is excluded because this has a local minimum and does
268 // not find the optimum. This should not affect the correctness of
269 // this test since we are testing all the other 14 combinations of
270 // column activations.
271 //
272 // IsSolveSuccessful<true, true, false, true>();
273
274 const TrustRegionStrategyType kStrategy = LEVENBERG_MARQUARDT;
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800275 // clang-format off
Austin Schuh70cc9552019-01-21 19:46:48 -0800276 IsTrustRegionSolveSuccessful<true, true, true, true >(kStrategy);
277 IsTrustRegionSolveSuccessful<true, true, true, false>(kStrategy);
278 IsTrustRegionSolveSuccessful<true, false, true, true >(kStrategy);
279 IsTrustRegionSolveSuccessful<false, true, true, true >(kStrategy);
280 IsTrustRegionSolveSuccessful<true, true, false, false>(kStrategy);
281 IsTrustRegionSolveSuccessful<true, false, true, false>(kStrategy);
282 IsTrustRegionSolveSuccessful<false, true, true, false>(kStrategy);
283 IsTrustRegionSolveSuccessful<true, false, false, true >(kStrategy);
284 IsTrustRegionSolveSuccessful<false, true, false, true >(kStrategy);
285 IsTrustRegionSolveSuccessful<false, false, true, true >(kStrategy);
286 IsTrustRegionSolveSuccessful<true, false, false, false>(kStrategy);
287 IsTrustRegionSolveSuccessful<false, true, false, false>(kStrategy);
288 IsTrustRegionSolveSuccessful<false, false, true, false>(kStrategy);
289 IsTrustRegionSolveSuccessful<false, false, false, true >(kStrategy);
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800290 // clang-format on
Austin Schuh70cc9552019-01-21 19:46:48 -0800291}
292
293TEST(TrustRegionMinimizer, PowellsSingularFunctionUsingDogleg) {
294 // The following two cases are excluded because they encounter a
295 // local minimum.
296 //
297 // IsTrustRegionSolveSuccessful<true, true, false, true >(kStrategy);
298 // IsTrustRegionSolveSuccessful<true, true, true, true >(kStrategy);
299
300 const TrustRegionStrategyType kStrategy = DOGLEG;
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800301 // clang-format off
Austin Schuh70cc9552019-01-21 19:46:48 -0800302 IsTrustRegionSolveSuccessful<true, true, true, false>(kStrategy);
303 IsTrustRegionSolveSuccessful<true, false, true, true >(kStrategy);
304 IsTrustRegionSolveSuccessful<false, true, true, true >(kStrategy);
305 IsTrustRegionSolveSuccessful<true, true, false, false>(kStrategy);
306 IsTrustRegionSolveSuccessful<true, false, true, false>(kStrategy);
307 IsTrustRegionSolveSuccessful<false, true, true, false>(kStrategy);
308 IsTrustRegionSolveSuccessful<true, false, false, true >(kStrategy);
309 IsTrustRegionSolveSuccessful<false, true, false, true >(kStrategy);
310 IsTrustRegionSolveSuccessful<false, false, true, true >(kStrategy);
311 IsTrustRegionSolveSuccessful<true, false, false, false>(kStrategy);
312 IsTrustRegionSolveSuccessful<false, true, false, false>(kStrategy);
313 IsTrustRegionSolveSuccessful<false, false, true, false>(kStrategy);
314 IsTrustRegionSolveSuccessful<false, false, false, true >(kStrategy);
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800315 // clang-format on
Austin Schuh70cc9552019-01-21 19:46:48 -0800316}
317
Austin Schuh70cc9552019-01-21 19:46:48 -0800318class CurveCostFunction : public CostFunction {
319 public:
320 CurveCostFunction(int num_vertices, double target_length)
321 : num_vertices_(num_vertices), target_length_(target_length) {
322 set_num_residuals(1);
323 for (int i = 0; i < num_vertices_; ++i) {
324 mutable_parameter_block_sizes()->push_back(2);
325 }
326 }
327
328 bool Evaluate(double const* const* parameters,
329 double* residuals,
Austin Schuh3de38b02024-06-25 18:25:10 -0700330 double** jacobians) const override {
Austin Schuh70cc9552019-01-21 19:46:48 -0800331 residuals[0] = target_length_;
332
333 for (int i = 0; i < num_vertices_; ++i) {
334 int prev = (num_vertices_ + i - 1) % num_vertices_;
335 double length = 0.0;
336 for (int dim = 0; dim < 2; dim++) {
337 const double diff = parameters[prev][dim] - parameters[i][dim];
338 length += diff * diff;
339 }
340 residuals[0] -= sqrt(length);
341 }
342
Austin Schuh3de38b02024-06-25 18:25:10 -0700343 if (jacobians == nullptr) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800344 return true;
345 }
346
347 for (int i = 0; i < num_vertices_; ++i) {
Austin Schuh3de38b02024-06-25 18:25:10 -0700348 if (jacobians[i] != nullptr) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800349 int prev = (num_vertices_ + i - 1) % num_vertices_;
350 int next = (i + 1) % num_vertices_;
351
352 double u[2], v[2];
353 double norm_u = 0., norm_v = 0.;
354 for (int dim = 0; dim < 2; dim++) {
355 u[dim] = parameters[i][dim] - parameters[prev][dim];
356 norm_u += u[dim] * u[dim];
357 v[dim] = parameters[next][dim] - parameters[i][dim];
358 norm_v += v[dim] * v[dim];
359 }
360
361 norm_u = sqrt(norm_u);
362 norm_v = sqrt(norm_v);
363
364 for (int dim = 0; dim < 2; dim++) {
365 jacobians[i][dim] = 0.;
366
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800367 if (norm_u > std::numeric_limits<double>::min()) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800368 jacobians[i][dim] -= u[dim] / norm_u;
369 }
370
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800371 if (norm_v > std::numeric_limits<double>::min()) {
Austin Schuh70cc9552019-01-21 19:46:48 -0800372 jacobians[i][dim] += v[dim] / norm_v;
373 }
374 }
375 }
376 }
377
378 return true;
379 }
380
381 private:
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800382 int num_vertices_;
383 double target_length_;
Austin Schuh70cc9552019-01-21 19:46:48 -0800384};
385
386TEST(TrustRegionMinimizer, JacobiScalingTest) {
387 int N = 6;
388 std::vector<double*> y(N);
389 const double pi = 3.1415926535897932384626433;
390 for (int i = 0; i < N; i++) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800391 double theta = i * 2. * pi / static_cast<double>(N);
Austin Schuh70cc9552019-01-21 19:46:48 -0800392 y[i] = new double[2];
393 y[i][0] = cos(theta);
394 y[i][1] = sin(theta);
395 }
396
397 Problem problem;
Austin Schuh3de38b02024-06-25 18:25:10 -0700398 problem.AddResidualBlock(new CurveCostFunction(N, 10.), nullptr, y);
Austin Schuh70cc9552019-01-21 19:46:48 -0800399 Solver::Options options;
400 options.linear_solver_type = ceres::DENSE_QR;
401 Solver::Summary summary;
402 Solve(options, &problem, &summary);
403 EXPECT_LE(summary.final_cost, 1e-10);
404
405 for (int i = 0; i < N; i++) {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800406 delete[] y[i];
Austin Schuh70cc9552019-01-21 19:46:48 -0800407 }
408}
409
410struct ExpCostFunctor {
411 template <typename T>
412 bool operator()(const T* const x, T* residual) const {
413 residual[0] = T(10.0) - exp(x[0]);
414 return true;
415 }
416
417 static CostFunction* Create() {
Austin Schuh1d1e6ea2020-12-23 21:56:30 -0800418 return new AutoDiffCostFunction<ExpCostFunctor, 1, 1>(new ExpCostFunctor);
Austin Schuh70cc9552019-01-21 19:46:48 -0800419 }
420};
421
422TEST(TrustRegionMinimizer, GradientToleranceConvergenceUpdatesStep) {
423 double x = 5;
424 Problem problem;
Austin Schuh3de38b02024-06-25 18:25:10 -0700425 problem.AddResidualBlock(ExpCostFunctor::Create(), nullptr, &x);
Austin Schuh70cc9552019-01-21 19:46:48 -0800426 problem.SetParameterLowerBound(&x, 0, 3.0);
427 Solver::Options options;
428 Solver::Summary summary;
429 Solve(options, &problem, &summary);
430 EXPECT_NEAR(3.0, x, 1e-12);
431 const double expected_final_cost = 0.5 * pow(10.0 - exp(3.0), 2);
432 EXPECT_NEAR(expected_final_cost, summary.final_cost, 1e-12);
433}
434
Austin Schuh3de38b02024-06-25 18:25:10 -0700435} // namespace ceres::internal