Skip to content

Commit

Permalink
Adding minimization with derivatives to multimin
Browse files Browse the repository at this point in the history
  • Loading branch information
hugohp committed Mar 25, 2024
1 parent 07c2c99 commit 35fae9e
Show file tree
Hide file tree
Showing 3 changed files with 316 additions and 18 deletions.
15 changes: 14 additions & 1 deletion gsl-sys/src/auto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21926,8 +21926,21 @@ pub struct gsl_multimin_function_struct {
pub type gsl_multimin_function = gsl_multimin_function_struct;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct gsl_multimin_function_fdf_struct;
pub struct gsl_multimin_function_fdf_struct {
pub f: ::std::option::Option<
unsafe extern "C" fn(x: *const gsl_vector, params: *mut ::std::os::raw::c_void) -> f64,
>,
pub df: ::std::option::Option<
unsafe extern "C" fn(x: *const gsl_vector, params: *mut ::std::os::raw::c_void, g: *mut gsl_vector) -> (),
>,
pub fdf: ::std::option::Option<
unsafe extern "C" fn(x: *const gsl_vector, params: *mut ::std::os::raw::c_void, f: *mut f64,g: *mut gsl_vector) -> (),
>,
pub n: usize,
pub params: *mut ::std::os::raw::c_void,
}
pub type gsl_multimin_function_fdf = gsl_multimin_function_fdf_struct;

extern "C" {
pub fn gsl_multimin_diff(
f: *const gsl_multimin_function,
Expand Down
11 changes: 10 additions & 1 deletion src/multimin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
// A rust binding for the GSL library by Guillaume Gomez ([email protected])
//

use crate::ffi::FFI;
use crate::Value;

/// This function tests the minimizer specific characteristic size (if applicable to the used minimizer) against absolute tolerance `epsabs`.
/// The test returns `crate::Value::Success` if the size is smaller than tolerance, otherwise crate::Value::Continue is returned.
#[doc(alias = "gsl_multimin_test_size")]
pub fn test_size(size: f64, epsabs: f64) -> Value {
Value::from(unsafe { sys::gsl_multimin_test_size(size, epsabs) })
}

/// This function tests the norm of the gradient `g` against the absolute tolerance `epsabs`.
/// The gradient of a multidimensional function goes to zero at a minimum. The test returns `crate::Value::Success` if the following condition is achieved, |g| < epsabs
/// and returns `crate::Value::Continue` otherwise. A suitable choice of `epsabs` can be made from the desired accuracy in the function for small variations in `x`.
/// The relationship between these quantities is given by \delta{f} = g\,\delta{x}.
#[doc(alias = "gsl_multimin_test_gradient")]
pub fn test_gradient(g: &crate::VectorF64, epsabs: f64) -> Value {
Value::from(unsafe { sys::gsl_multimin_test_gradient(g.unwrap_shared(), epsabs) })
}
Loading

0 comments on commit 35fae9e

Please sign in to comment.