|0.4.0||May 25, 2021|
|0.3.2||Nov 4, 2019|
|0.3.1||Aug 22, 2019|
|0.2.2||Aug 5, 2019|
32 downloads per month
rusfun crate is a small library to compile parametrized functions from
Rust to wasm. Furthermore it contains minimizer routines to find for a given
set of data, parameters that minimize a cost function.
Currently the Levenberg-Marquardt algorithm is implemented to minimize
To define a function, a Func1D structs is defined, which contains as fields a reference to the initial parameters p, a reference to the domain x and a function, which maps p and x to the model values f(x). A few models are pre-defined in the standard, size_distribution and sas modules.
To initiate a Gaussian function for example one can do:
let p = array![300.0, 3.0, 0.2, 0.0]; let model = size_distribution::gaussian; let model_function = func1d::Func1D::new(&p, &x, model);
Note that p and x are ndarrays.
The function can then be evaluated by calling
To minimize a model for given data (xᵢ, yᵢ, σᵢ) with LM a Minimizer struct needs to be initialized as mutable variable, with the previously defined model_function, a reference to y and σ as ndarrays, as well as an initial ƛ value for the LM step.
let mut minimizer = curve_fit::Minimizer::init(&model_function, &y, &sy, 0.01);
Then a fit can be performed by
and the result can be printed by
So far the basic function of the rusfun crate. The crate is very young and the syntax might have breaking changes when more flexibility in choice for fitting algorithms are implemented.