Module bounded

Module bounded 

Source
Expand description

Bounded-variable least squares optimization

This module provides least squares methods with box constraints on variables. It implements trust-region reflective algorithm adapted for bounds.

§Example

use scirs2_core::ndarray::{array, Array1, Array2};
use scirs2_optimize::{Bounds, least_squares::bounded::{bounded_least_squares, BoundedOptions}};

// Define a function that returns the residuals
fn residual(x: &[f64], data: &[f64]) -> Array1<f64> {
    array![
        x[0] + 2.0 * x[1] - 2.0,
        x[0] - x[1] - 1.0,
        x[0] + x[1] - 1.5
    ]
}

// Initial guess
let x0 = array![0.0, 0.0];

// Define bounds: 0 <= x[0] <= 2, -1 <= x[1] <= 1
let bounds = Bounds::new(&[(Some(0.0), Some(2.0)), (Some(-1.0), Some(1.0))]);

// Solve using bounded least squares
let result = bounded_least_squares(
    residual,
    &x0,
    Some(bounds),
    None::<fn(&[f64], &[f64]) -> Array2<f64>>,
    &array![],
    None
)?;

assert!(result.success);

Structs§

BoundedOptions
Options for bounded least squares optimization

Functions§

bounded_least_squares
Solve a bounded least squares problem