-
-
Notifications
You must be signed in to change notification settings - Fork 49
Add rgsl-nlinear library to rust-GSL. #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lmandres
wants to merge
33
commits into
GuillaumeGomez:master
Choose a base branch
from
lmandres:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 237f15a
Make changes to solver_progress function.
lmandres ac37199
Change return of parameter variance to parameter error.
lmandres b5dc9a4
Correcting return of parameter errors.
lmandres a32fb54
Added reason for stopping as part of return tuple.
lmandres 4994b34
Changed setting df function to be referred by slice.
lmandres 49dc542
Add error thing for short n.
lmandres 1d499e3
Change function to pub extern C.
lmandres 74e9426
Remove rgsl-cblib and move code to rgsl-nlinear.
lmandres 5d3e7cb
Remove unused import.
lmandres 3ddfc03
Allow lint of improper_ctypes warning.
lmandres 34ecff8
Add functions and struct to avoid Segmentation fault.
lmandres 71f87bd
Add first steps to nlinear resolver.
lmandres 187167f
Allow multifit nlinear to call call_df().
lmandres cc19558
Return parameters, parameter errors, and status in Result().
lmandres 39129a8
Point multifit nlinear functions to gslsys-mfnlin.
lmandres 4432fe9
Remove rgsl-nlinear crate.
lmandres 400c436
Add example for multifit_nlinear.
lmandres 5bbfa9e
Remove gslsys-mfnlin and move to gsl-sys crate.
lmandres 36bcb8c
Add error if params length greater than var length.
lmandres 9559f4f
Modify rcond to only halt loop if not first iteration.
lmandres 04927bf
Add updated files to repo.
lmandres 7f72f66
Add updated files to repo.
lmandres 6f7bce7
Remove rgsl-nlinear.
lmandres 49a5d0a
Adding changes to lib.rs.
lmandres 376372c
Adding changes to lib.rs.
lmandres a3fa87a
Fix bug to change residual to position.
lmandres a54ed2f
Add multilarge to lib.rs.
lmandres 3b14fac
Add multilarge to lib.rs.
lmandres ec33f46
Add multilarge to lib.rs of rgsl.
lmandres cddb4e4
Fix merge conflicts from DOS.
lmandres afd4d48
Add weighted solvers for multifit and multilarge.
lmandres eaf4137
Change variable name from w to wts.
lmandres File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] | ||
| 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); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_manglein here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been removed.