Expand description
Separable least squares for partially linear problems
This module implements variable projection (VARPRO) algorithm for solving separable nonlinear least squares problems where the model has the form:
f(x, α, β) = Σ αᵢ φᵢ(x, β)
where α are linear parameters and β are nonlinear parameters.
§Example
use ndarray::{array, Array1, Array2};
use scirs2_optimize::least_squares::separable::{separable_least_squares, SeparableOptions};
// Model: y = α₁ * exp(-β * t) + α₂
// Linear parameters: α = [α₁, α₂]
// Nonlinear parameters: β = [β]
// Basis functions that depend on nonlinear parameters
fn basis_functions(t: &[f64], beta: &[f64]) -> Array2<f64> {
let n = t.len();
let mut phi = Array2::zeros((n, 2));
for i in 0..n {
phi[[i, 0]] = (-beta[0] * t[i]).exp(); // exp(-β*t)
phi[[i, 1]] = 1.0; // constant term
}
phi
}
// Jacobian of basis functions w.r.t. nonlinear parameters
fn basis_jacobian(t: &[f64], beta: &[f64]) -> Array2<f64> {
let n = t.len();
let mut dphi_dbeta = Array2::zeros((n * 2, 1)); // n*p x q
for i in 0..n {
// d/dβ(exp(-β*t)) = -t * exp(-β*t)
dphi_dbeta[[i, 0]] = -t[i] * (-beta[0] * t[i]).exp();
// d/dβ(1) = 0
dphi_dbeta[[n + i, 0]] = 0.0;
}
dphi_dbeta
}
// Data points
let t_data = array![0.0, 0.5, 1.0, 1.5, 2.0];
let y_data = array![2.0, 1.6, 1.3, 1.1, 1.0];
// Initial guess for nonlinear parameters
let beta0 = array![0.5];
let result = separable_least_squares(
basis_functions,
basis_jacobian,
&t_data,
&y_data,
&beta0,
None
)?;
println!("Nonlinear params: {:?}", result.result.x);
println!("Linear params: {:?}", result.linear_params);
Structs§
- Separable
Options - Options for separable least squares
- Separable
Result - Result structure extended for separable least squares
Enums§
- Linear
Solver - Methods for solving the linear least squares subproblem
Functions§
- separable_
least_ squares - Solve a separable nonlinear least squares problem