Expand description
Least squares optimization
This module provides methods for solving nonlinear least squares problems, including robust methods that are less sensitive to outliers.
§Example
use scirs2_core::ndarray::{array, Array1, Array2};
use scirs2_optimize::least_squares::{least_squares, Method};
// Define a function that returns the residuals
fn residual(x: &[f64], _data: &[f64]) -> Array1<f64> {
let y = array![
x[0] + 2.0 * x[1] - 2.0,
x[0] + x[1] - 1.0
];
y
}
// Define the Jacobian (optional)
fn jacobian(x: &[f64], _data: &[f64]) -> Array2<f64> {
array![[1.0, 2.0], [1.0, 1.0]]
}
// Initial guess
let x0 = array![0.0, 0.0];
let data = array![]; // No data needed for this example
// Solve the least squares problem
let result = least_squares(residual, &x0, Method::LevenbergMarquardt, Some(jacobian), &data, None)?;
// The solution should be close to [0.0, 1.0]
assert!(result.success);Structs§
- Options
- Options for the least squares optimizer.
Enums§
- Method
- Optimization methods for least squares problems.
Functions§
- least_
squares - Solve a nonlinear least-squares problem.