Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3f75b82
Add rgsl-nlinear library to rust-GSL.
lmandres Oct 19, 2024
237f15a
Make changes to solver_progress function.
lmandres Oct 19, 2024
ac37199
Change return of parameter variance to parameter error.
lmandres Oct 19, 2024
b5dc9a4
Correcting return of parameter errors.
lmandres Oct 19, 2024
a32fb54
Added reason for stopping as part of return tuple.
lmandres Oct 19, 2024
4994b34
Changed setting df function to be referred by slice.
lmandres Oct 19, 2024
49dc542
Add error thing for short n.
lmandres Oct 20, 2024
1d499e3
Change function to pub extern C.
lmandres Oct 26, 2024
74e9426
Remove rgsl-cblib and move code to rgsl-nlinear.
lmandres Oct 27, 2024
5d3e7cb
Remove unused import.
lmandres Oct 27, 2024
3ddfc03
Allow lint of improper_ctypes warning.
lmandres Oct 27, 2024
34ecff8
Add functions and struct to avoid Segmentation fault.
lmandres Oct 28, 2024
71f87bd
Add first steps to nlinear resolver.
lmandres Oct 29, 2024
187167f
Allow multifit nlinear to call call_df().
lmandres Oct 30, 2024
cc19558
Return parameters, parameter errors, and status in Result().
lmandres Oct 30, 2024
39129a8
Point multifit nlinear functions to gslsys-mfnlin.
lmandres Oct 30, 2024
4432fe9
Remove rgsl-nlinear crate.
lmandres Oct 30, 2024
400c436
Add example for multifit_nlinear.
lmandres Oct 30, 2024
5bbfa9e
Remove gslsys-mfnlin and move to gsl-sys crate.
lmandres Oct 31, 2024
36bcb8c
Add error if params length greater than var length.
lmandres Oct 31, 2024
9559f4f
Modify rcond to only halt loop if not first iteration.
lmandres Oct 31, 2024
04927bf
Add updated files to repo.
lmandres Mar 23, 2025
7f72f66
Add updated files to repo.
lmandres Mar 23, 2025
6f7bce7
Remove rgsl-nlinear.
lmandres Mar 24, 2025
49a5d0a
Adding changes to lib.rs.
lmandres Mar 24, 2025
376372c
Adding changes to lib.rs.
lmandres Mar 24, 2025
a3fa87a
Fix bug to change residual to position.
lmandres Mar 24, 2025
a54ed2f
Add multilarge to lib.rs.
lmandres Mar 24, 2025
3b14fac
Add multilarge to lib.rs.
lmandres Mar 24, 2025
ec33f46
Add multilarge to lib.rs of rgsl.
lmandres Mar 24, 2025
cddb4e4
Fix merge conflicts from DOS.
lmandres Mar 24, 2025
afd4d48
Add weighted solvers for multifit and multilarge.
lmandres Mar 27, 2025
eaf4137
Change variable name from w to wts.
lmandres Mar 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2021"

[dependencies]
sys = { path = "gsl-sys", package = "GSL-sys", version = "3.0.0" }
sys_mfnlin = { path = "gslsys-mfnlin", package = "gslsys-mfnlin", version = "0.1.0" }
paste = "1.0"

[features]
Expand Down
4 changes: 4 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ name = "largefit"
path = "./largefit.rs"
required-features = ["GSL/v2_2"]

[[bin]]
name = "multifit_nlinear"
path = "./multifit_nlinear.rs"

[[bin]]
name = "rng"
path = "./rng.rs"
Expand Down
88 changes: 88 additions & 0 deletions examples/multifit_nlinear.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
extern crate rgsl;

use rgsl::gsl_multifit_nlinear_basic;
use rgsl::gsl_multifit_nlinear_basic_df;

use rgsl::types::rng::Rng;
use rgsl::types::rng::RngType;


#[no_mangle]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need or no_mangle in here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been removed.

fn expb_f(params: Vec<f64>, t: f64, _args: Vec<f64>) -> f64 {

let a = params.get(0).unwrap();
let lambda = params.get(1).unwrap();
let b = params.get(2).unwrap();

a * f64::exp(-lambda * t) + b
}

#[no_mangle]
fn expb_df_a(params: Vec<f64>, t: f64, _args: Vec<f64>) -> f64 {
let lambda = params.get(1).unwrap();
f64::exp(-lambda * t)
}

#[no_mangle]
fn expb_df_lambda(params: Vec<f64>, t: f64, _args: Vec<f64>) -> f64 {
let a = params.get(0).unwrap();
let lambda = params.get(1).unwrap();
-t * a * f64::exp(-lambda * t)
}

#[no_mangle]
fn expb_df_b(_params: Vec<f64>, _t: f64, _args: Vec<f64>) -> f64 {
1.0
}

fn main() {

let params_out = vec![1.0, 1.0, 0.0];
let mut ts = Vec::new();
let mut ys = Vec::new();
let args = vec![];
let expb_dfs = vec![expb_df_a, expb_df_lambda, expb_df_b];

let mut rng = Rng::new(RngType::default()).unwrap();

for i in 0..100 {

let rand_flt = rng.uniform();

let ti = (i as f64) * 3.0 / (100.0 - 1.0);
let yi = 1.0 + 5.0 * f64::exp(-1.5 * ti);
let si = 0.1 * yi;
let dy = si * rand_flt;

ts.push(ti);
ys.push(yi + dy);
}

let (params, parerr, status) = match unsafe {
gsl_multifit_nlinear_basic(expb_f, params_out.clone(), &ts, &ys, &args, 100)
} {
Ok(value) => value,
Err(_) => {
eprintln!("Error encountered during solve!");
return;
}
};

println!("{:?}", params);
println!("{:?}", parerr);
println!("{}", status);

let (params, parerr, status) = match unsafe {
gsl_multifit_nlinear_basic_df(expb_f, &expb_dfs, params_out.clone(), &ts, &ys, &args, 100)
} {
Ok(value) => value,
Err(_) => {
eprintln!("Error encountered during solve!");
return;
}
};

println!("{:?}", params);
println!("{:?}", parerr);
println!("{}", status);
}
17 changes: 17 additions & 0 deletions gslsys-mfnlin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "gslsys-mfnlin"
version = "0.1.0"
edition = "2021"

build = "build.rs"

[dependencies]
libc = "0.2"
GSL-sys = { version = "3.0.0", path = "../gsl-sys" }

[build-dependencies]
pkg-config = "0.3"

[lib]
name = "gslsys_mfnlin"
crate-type = ["dylib", "rlib"]
16 changes: 16 additions & 0 deletions gslsys-mfnlin/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extern crate pkg_config;

fn main() {
if std::process::Command::new("pkg-config").output().is_err() {
println!("cargo:rustc-link-lib=gsl");
println!("cargo:rustc-link-lib=gslcblas");
return;
}

if pkg_config::probe_library("gsl").is_err() {
println!("cargo:rustc-link-lib=gsl");
}
if pkg_config::probe_library("gslcblas").is_err() {
println!("cargo:rustc-link-lib=gslcblas");
}
}
Loading