Skip to main content

HigherOrderEngine

Struct HigherOrderEngine 

Source
pub struct HigherOrderEngine<T: Float + Debug + Default + Clone + Send + Sync + 'static + Sum + ScalarOperand> { /* private fields */ }
Expand description

Higher-order differentiation engine

Implementations§

Source§

impl<T: Float + Debug + Default + Clone + Send + Sync + 'static + Sum + ScalarOperand> HigherOrderEngine<T>

Source

pub fn new(_maxorder: usize) -> Self

Create a new higher-order differentiation engine

Source

pub fn with_config(config: HigherOrderConfig<T>) -> Self

Create a new engine with advanced configuration

Source

pub fn set_mixed_mode(&mut self, enabled: bool)

Enable/disable mixed-mode computation

Source

pub fn set_finite_diff_eps(&mut self, eps: T)

Set finite difference epsilon for numerical verification

Source

pub fn hessian_forward_over_reverse( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, config: &HessianConfig, ) -> Result<Array2<T>>

Compute Hessian matrix using forward-over-reverse mode.

When HessianConfig::sparse is set and the problem is large enough that sparsification pays for itself, entries below HessianConfig::sparsity_threshold are zeroed. Previously sparse/sparsity_threshold were accepted and ignored: the sparsity decision and the thresholding routine both existed but nothing called them.

The wall time is recorded on the engine’s profiler, so Self::get_derivative_stats’s performance_profile reports measured numbers rather than the zeros it returned when nothing was ever recorded.

Source

pub fn hessian_reverse_over_forward( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, _config: &HessianConfig, ) -> Result<Array2<T>>

Compute the Hessian column by column, by taking the gradient of each first partial derivative.

The name is historical — it describes the reverse-over-forward autodiff scheme this emulates, not the implementation, which is a nested central finite difference (see hvp for why autodiff cannot be threaded through this engine’s objective type). Distinct from Self::hessian_forward_over_reverse, which works row-wise from a directional derivative of the gradient.

Both nested steps use the order-2 step. With the old raw finite_diff_eps (1e-5) on both levels the roundoff floor was ε/h² ≈ 2e-6 in f64 and ≈ 1.2e3 in f32 — i.e. the f32 result was pure noise.

Source

pub fn hessian_diagonal( &self, function: &impl Fn(&Array1<T>) -> T, point: &Array1<T>, ) -> Result<Array2<T>>

Compute diagonal Hessian elements only

Source

pub fn sparse_hessian( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, config: &HessianConfig, ) -> Result<SparseHessian<T>>

Compute sparse Hessian representation

Source

pub fn third_order_derivatives( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, ) -> Result<ThirdOrderTensor<T>>

Compute third-order derivatives (tensor)

Source

pub fn mixed_partial( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, variables: &[usize], orders: &[usize], method: MixedPartialMethod, ) -> Result<MixedPartials<T>>

Compute mixed partial derivatives

Source

pub fn hessian_vector_product( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, vector: &Array1<T>, ) -> Result<Array1<T>>

Compute Hessian-vector product efficiently

Source

pub fn vector_hessian_vector_product( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, vector: &Array1<T>, ) -> Result<T>

Compute vector-Hessian-vector product (quadratic form)

Source

pub fn verify_derivatives( &self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, computed_hessian: &Array2<T>, ) -> Result<DerivativeVerification<T>>

Verify higher-order derivatives using finite differences

Source

pub fn get_derivative_stats(&self) -> HigherOrderStats

Get higher-order derivative statistics

Source

pub fn hessian_vector_product_advanced( &mut self, function: impl Fn(&Array1<T>) -> T + Send + Sync, point: &Array1<T>, vector: &Array1<T>, mode: Option<HvpMode>, ) -> Result<Array1<T>>

Advanced Hessian-vector product with automatic mode selection

Source

pub fn vector_hessian_vector_efficient( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, vector: &Array1<T>, ) -> Result<T>

Compute vector-Hessian-vector efficiently

Source

pub fn jacobian_efficient<F>( &mut self, function: F, point: &Array1<T>, output_dim: usize, ) -> Result<Array2<T>>
where F: Fn(&Array1<T>) -> Array1<T> + Send + Sync,

Compute Jacobian efficiently with automatic mode selection

Source

pub fn kfac_hessian_approximation( &mut self, layers: &[LayerInfo<T>], activations: &[Array1<T>], gradients: &[Array1<T>], ) -> Result<Array2<T>>

Compute K-FAC approximation to the Hessian

Source

pub fn natural_gradient( &mut self, log_likelihood: impl Fn(&Array1<T>) -> T, point: &Array1<T>, gradient: &Array1<T>, ) -> Result<Array1<T>>

Compute Natural Gradient using Fisher Information Matrix

Source

pub fn truncated_newton_direction( &mut self, function: impl Fn(&Array1<T>) -> T + Send + Sync, point: &Array1<T>, gradient: &Array1<T>, max_cg_iterations: usize, cg_tolerance: T, ) -> Result<Array1<T>>

Compute truncated Newton direction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V