Skip to main content

Nlls

Struct Nlls 

Source
pub struct Nlls<'a> { /* private fields */ }
Expand description

Nonlinear least-squares solver wrapping AOCL’s RAlfit family.

Provide a residual function (mandatory) and optionally a Jacobian. If the Jacobian is omitted, AOCL will estimate derivatives by finite differences. After Nlls::fit, the optimised coefficients are in the user’s input vector and a 100-element rinfo of solver stats can be retrieved via Nlls::info.

Implementations§

Source§

impl<'a> Nlls<'a>

Source

pub fn new<F>(n_coef: usize, n_res: usize, resfun: F) -> Result<Self>
where F: FnMut(&[f64], &mut [f64]) -> i32 + 'a,

Build a new NLLS solver with n_coef coefficients and n_res residuals. resfun evaluates r(x); finite differences will estimate the Jacobian unless one is supplied via Nlls::with_jacobian.

Source

pub fn with_jacobian<G>(self, resgrd: G) -> Result<Self>
where G: FnMut(&[f64], &mut [f64]) -> i32 + 'a,

Attach an analytic Jacobian. Layout follows the "storage scheme" option set on the underlying handle (default row-major).

Source

pub fn handle_mut(&mut self) -> &mut Handle

Borrow the underlying handle to set NLLS-specific options ("ralfit iteration limit", "storage scheme", etc.).

Source

pub fn set_bounds( &mut self, lower: Option<&mut [f64]>, upper: Option<&mut [f64]>, ) -> Result<()>

Constrain coefficients to lie within lower[i] <= x[i] <= upper[i]. Pass None for an unbounded side; the slices must have length n_coef.

Source

pub fn set_weights(&mut self, weights: &mut [f64]) -> Result<()>

Set per-residual weights w_i = √W_ii (length n_res).

Source

pub fn fit(&mut self, coef: &mut [f64]) -> Result<()>

Run the optimiser. On entry coef is the initial guess; on success it holds the optimised coefficients.

Concurrent solves are serialised: RALFit in aocl-da.dll is not thread-safe (AOCL 6.0.68, Windows: concurrent solves from several threads crashed the process), so Nlls::new (which defines the residuals), set_bounds, set_weights, fit and info take one process-wide lock. Two Nlls fits on different threads therefore run one after the other. Option setting through Nlls::handle_mut is NOT covered by the lock.

Source

pub fn info(&self) -> Result<Vec<f64>>

Retrieve the solver’s information vector (rinfo, length 100) — see AOCL’s documentation for the index meanings: info_objective (0), info_grad_norm (1), info_iter (2), info_time (3), etc.

Trait Implementations§

Source§

impl<'a> Debug for Nlls<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for Nlls<'a>

§

impl<'a> !RefUnwindSafe for Nlls<'a>

§

impl<'a> !Send for Nlls<'a>

§

impl<'a> !Sync for Nlls<'a>

§

impl<'a> !UnwindSafe for Nlls<'a>

§

impl<'a> Forget for Nlls<'a>

§

impl<'a> Move for Nlls<'a>

§

impl<'a> Unpin for Nlls<'a>

§

impl<'a> UnsafeUnpin for Nlls<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.