pub trait Hessian {
type Param;
type Hessian;
// Required method
fn hessian(&self, param: &Self::Param) -> Result<Self::Hessian, Error>;
// Provided methods
fn bulk_hessian<P>(&self, params: &[P]) -> Result<Vec<Self::Hessian>, Error>
where P: Borrow<Self::Param> + SyncAlias,
Self::Hessian: SendAlias,
Self: SyncAlias { ... }
fn parallelize(&self) -> bool { ... }
}
Expand description
Defines the computation of the Hessian.
§Example
use argmin::core::{Hessian, Error};
struct Rosenbrock {}
impl Hessian for Rosenbrock {
type Param = Vec<f64>;
type Hessian = Vec<f64>;
/// Compute gradient of rosenbrock function
fn hessian(&self, param: &Self::Param) -> Result<Self::Hessian, Error> {
Ok(compute_hessian(¶m))
}
}
Required Associated Types§
Required Methods§
Provided Methods§
sourcefn bulk_hessian<P>(&self, params: &[P]) -> Result<Vec<Self::Hessian>, Error>
fn bulk_hessian<P>(&self, params: &[P]) -> Result<Vec<Self::Hessian>, Error>
Compute hessian
in bulk. If the rayon
feature is enabled, multiple calls to hessian
will be run in parallel using rayon
, otherwise they will execute sequentially. If the rayon
feature is enabled, parallelization can still be turned off by overwriting parallelize
to return false
. This can be useful in cases where it is preferable to parallelize only certain parts. Note that even if parallelize
is set to false, the parameter vectors and the problem are still required to be Send
and Sync
. Those bounds are linked to the rayon
feature. This method can be overwritten.
sourcefn parallelize(&self) -> bool
fn parallelize(&self) -> bool
Indicates whether to parallelize calls to hessian
when using bulk_hessian
. By default returns true, but can be set manually to false
if needed. This allows users to turn off parallelization for certain traits implemented on their problem. Note that parallelization requires the rayon
feature to be enabled, otherwise calls to hessian
will be executed sequentially independent of how parallelize
is set.