GuillaumeGomez / rust-GSL

A GSL (the GNU Scientific Library) binding for Rust
190 stars 48 forks source link

Add multifit_solver binding #68

Open GuillaumeGomez opened 5 years ago

GuillaumeGomez commented 5 years ago

Some links:

cc @SuperFluffy

SuperFluffy commented 5 years ago

With gsl 2.2.1, the follwing change was introduced:

** completely rewritten nonlinear least squares module, including support for large problems; the user may now control the linear solver used, the trust region updating strategy, and the scaling method. In addition, support has been added for the geodesic acceleration step (Transtrum 2011) which can speed up convergence on a wide class of problems.

I figure this is what gsl_multifit_nlinear.h is for. At the same time, they have removed any mention of gsl_multifit_nlin.h from the docs. Here is a mailing list question about the same issue that went unanswered: https://lists.gnu.org/archive/html/help-gsl/2017-06/msg00052.html

lmandres commented 1 month ago

I'm experimenting with gsl-sys and the gsl_multifit_nlinear library as I've used it in C for some analysis. However, I'm getting a segmentation fault when I call a function to set the tunable parameters to default. I've isolated it to a Bus error in the following code snippet:

use gsl_sys::gsl_multifit_nlinear_default_parameters;
use gsl_sys::gsl_multifit_nlinear_parameters;

fn main() {
    let test_params: gsl_multifit_nlinear_parameters = unsafe { gsl_multifit_nlinear_default_parameters() };
}

The C code for this function is simple enough. However I'm new to Rust and haven't been able to figure out what are causing the Bus errors or Segmentation faults.

Link to C function for gsl_multifit_nlinear_default_parameters():

https://github.com/ampl/gsl/blob/60539d2e78ce297a8da2e326de0f10a0b435f774/multifit_nlinear/fdf.c#L134

GuillaumeGomez commented 1 month ago

It's likely that https://github.com/ampl/gsl/blob/master/multifit_nlinear/gsl_multifit_nlinear.h#L125 got updated, meaning that we write into non-existing code.

lmandres commented 1 month ago

So, to confirm, a fix would be to update gsl-sys according to the README below?

https://github.com/GuillaumeGomez/rust-GSL/blob/master/gsl-sys/README.md

GuillaumeGomez commented 1 month ago

Hopefully yes.

lmandres commented 1 month ago

I wasn't able to use GSL-sys out of the box for multifit_nlinear, so I had to write a little C to join GSL's multifit_nlinear functions with Rust. This isn't a final working version, but do you think something like the repo below could work for a pull request into rust-GSL if I fixed up the return values better?

https://github.com/lmandres/gslsys_multifit_nlinear.git

lmandres commented 1 month ago

I added the following PR:

https://github.com/GuillaumeGomez/rust-GSL/pull/159