diff --git a/lib/rust/mmscenegraph/src/math/curve_fit.rs b/lib/rust/mmscenegraph/src/math/curve_fit.rs index 94457edc..c9c5a511 100644 --- a/lib/rust/mmscenegraph/src/math/curve_fit.rs +++ b/lib/rust/mmscenegraph/src/math/curve_fit.rs @@ -389,7 +389,7 @@ pub fn nonlinear_line_n3( // solved. let initial_parameters_vec = vec![point_a.y, point_b.y, point_c.y]; let initial_parameters: Array1 = Array1::from(initial_parameters_vec); - println!("initial_parameters={initial_parameters:?}"); + debug!("initial_parameters={initial_parameters:?}"); // Define the problem let reference_values: Vec<(f64, f64)> = x_values @@ -406,16 +406,25 @@ pub fn nonlinear_line_n3( &reference_values, ); - // Set up the subproblem - let subproblem: argmin::solver::trustregion::CauchyPoint = - argmin::solver::trustregion::CauchyPoint::new(); - - // Set up solver - let solver = argmin::solver::trustregion::TrustRegion::new(subproblem); + // Set up solver. + let epsilon = 1e-9; + let condition = + argmin::solver::linesearch::condition::ArmijoCondition::new(1e-5)?; + let linesearch = + argmin::solver::linesearch::BacktrackingLineSearch::new(condition) + .rho(0.5)?; + let solver = argmin::solver::quasinewton::BFGS::new(linesearch) + .with_tolerance_cost(epsilon)?; // Run solver + let initial_hessian: Array2 = Array2::eye(3); let result = argmin::core::Executor::new(problem, solver) - .configure(|state| state.param(initial_parameters).max_iters(30)) + .configure(|state| { + state + .param(initial_parameters) + .inv_hessian(initial_hessian) + .max_iters(50) + }) .run()?; debug!("Solver Result: {result}"); diff --git a/lib/rust/mmscenegraph/tests/curvefit_linear_3_point.rs b/lib/rust/mmscenegraph/tests/curvefit_linear_3_point.rs index dc95bcb1..b89166d8 100644 --- a/lib/rust/mmscenegraph/tests/curvefit_linear_3_point.rs +++ b/lib/rust/mmscenegraph/tests/curvefit_linear_3_point.rs @@ -260,13 +260,13 @@ fn linear_3_point_variance4() -> Result<()> { )?; assert_relative_eq!(point_a.x(), 1001.0, epsilon = 1.0e-1); - assert_relative_eq!(point_a.y(), -1.21533949192, epsilon = 0.75); + assert_relative_eq!(point_a.y(), -1.21533949192, epsilon = 2.8); assert_relative_eq!(point_b.x(), 1051.0, epsilon = 1.0e-9); - assert_relative_eq!(point_b.y(), 4.5, epsilon = 2.0); + assert_relative_eq!(point_b.y(), 4.5, epsilon = 1.8); assert_relative_eq!(point_c.x(), 1101.0, epsilon = 1.0e-1); - assert_relative_eq!(point_c.y(), 1.855, epsilon = 2.5); + assert_relative_eq!(point_c.y(), 1.855, epsilon = 3.1); Ok(()) } diff --git a/lib/rust/mmscenegraph/tests/data/linear_3_point_variance1.png b/lib/rust/mmscenegraph/tests/data/linear_3_point_variance1.png index 944a07bd..5a5270cf 100644 Binary files a/lib/rust/mmscenegraph/tests/data/linear_3_point_variance1.png and b/lib/rust/mmscenegraph/tests/data/linear_3_point_variance1.png differ diff --git a/lib/rust/mmscenegraph/tests/data/linear_3_point_variance2.png b/lib/rust/mmscenegraph/tests/data/linear_3_point_variance2.png index 5c5389d3..654c36ef 100644 Binary files a/lib/rust/mmscenegraph/tests/data/linear_3_point_variance2.png and b/lib/rust/mmscenegraph/tests/data/linear_3_point_variance2.png differ diff --git a/lib/rust/mmscenegraph/tests/data/linear_3_point_variance3.png b/lib/rust/mmscenegraph/tests/data/linear_3_point_variance3.png index dd19abb5..415b93ee 100644 Binary files a/lib/rust/mmscenegraph/tests/data/linear_3_point_variance3.png and b/lib/rust/mmscenegraph/tests/data/linear_3_point_variance3.png differ diff --git a/lib/rust/mmscenegraph/tests/data/linear_3_point_variance4.png b/lib/rust/mmscenegraph/tests/data/linear_3_point_variance4.png index 3eb813ac..af09dbc8 100644 Binary files a/lib/rust/mmscenegraph/tests/data/linear_3_point_variance4.png and b/lib/rust/mmscenegraph/tests/data/linear_3_point_variance4.png differ