rusfun

Crates.iorusfun
lib.rsrusfun
version0.4.0
sourcesrc
created_at2019-08-05 18:24:39.969505
updated_at2021-05-25 17:10:33.891757
descriptionLittle experimental crate to fit simple models to data via WASM in the browser
homepage
repositoryhttps://github.com/domidre/rusfun
max_upload_size
id154347
size36,780
Domi (DomiDre)

documentation

README

RUSFUN

Build Status

The 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

equation

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

model_function.output()

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

minimizer.fit()

and the result can be printed by

minimizer.report()

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.

Commit count: 94

cargo fmt