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>
impl<T: Float + Debug + Default + Clone + Send + Sync + 'static + Sum + ScalarOperand> HigherOrderEngine<T>
Sourcepub fn with_config(config: HigherOrderConfig<T>) -> Self
pub fn with_config(config: HigherOrderConfig<T>) -> Self
Create a new engine with advanced configuration
Sourcepub fn set_mixed_mode(&mut self, enabled: bool)
pub fn set_mixed_mode(&mut self, enabled: bool)
Enable/disable mixed-mode computation
Sourcepub fn set_finite_diff_eps(&mut self, eps: T)
pub fn set_finite_diff_eps(&mut self, eps: T)
Set finite difference epsilon for numerical verification
Sourcepub fn hessian_forward_over_reverse(
&mut self,
function: impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
config: &HessianConfig,
) -> Result<Array2<T>>
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.
Sourcepub fn hessian_reverse_over_forward(
&mut self,
function: impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
_config: &HessianConfig,
) -> Result<Array2<T>>
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.
Sourcepub fn hessian_diagonal(
&self,
function: &impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
) -> Result<Array2<T>>
pub fn hessian_diagonal( &self, function: &impl Fn(&Array1<T>) -> T, point: &Array1<T>, ) -> Result<Array2<T>>
Compute diagonal Hessian elements only
Sourcepub fn sparse_hessian(
&mut self,
function: impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
config: &HessianConfig,
) -> Result<SparseHessian<T>>
pub fn sparse_hessian( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, config: &HessianConfig, ) -> Result<SparseHessian<T>>
Compute sparse Hessian representation
Sourcepub fn third_order_derivatives(
&mut self,
function: impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
) -> Result<ThirdOrderTensor<T>>
pub fn third_order_derivatives( &mut self, function: impl Fn(&Array1<T>) -> T, point: &Array1<T>, ) -> Result<ThirdOrderTensor<T>>
Compute third-order derivatives (tensor)
Sourcepub fn mixed_partial(
&mut self,
function: impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
variables: &[usize],
orders: &[usize],
method: MixedPartialMethod,
) -> Result<MixedPartials<T>>
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
Sourcepub fn hessian_vector_product(
&mut self,
function: impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
vector: &Array1<T>,
) -> Result<Array1<T>>
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
Sourcepub fn vector_hessian_vector_product(
&mut self,
function: impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
vector: &Array1<T>,
) -> Result<T>
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)
Sourcepub fn verify_derivatives(
&self,
function: impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
computed_hessian: &Array2<T>,
) -> Result<DerivativeVerification<T>>
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
Sourcepub fn get_derivative_stats(&self) -> HigherOrderStats
pub fn get_derivative_stats(&self) -> HigherOrderStats
Get higher-order derivative statistics
Sourcepub 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>>
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
Sourcepub fn vector_hessian_vector_efficient(
&mut self,
function: impl Fn(&Array1<T>) -> T,
point: &Array1<T>,
vector: &Array1<T>,
) -> Result<T>
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
Sourcepub fn jacobian_efficient<F>(
&mut self,
function: F,
point: &Array1<T>,
output_dim: usize,
) -> Result<Array2<T>>
pub fn jacobian_efficient<F>( &mut self, function: F, point: &Array1<T>, output_dim: usize, ) -> Result<Array2<T>>
Compute Jacobian efficiently with automatic mode selection
Sourcepub fn kfac_hessian_approximation(
&mut self,
layers: &[LayerInfo<T>],
activations: &[Array1<T>],
gradients: &[Array1<T>],
) -> Result<Array2<T>>
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
Auto Trait Implementations§
impl<T> Freeze for HigherOrderEngine<T>
impl<T> RefUnwindSafe for HigherOrderEngine<T>
impl<T> Send for HigherOrderEngine<T>where
ComputationProfiler<T>: Send,
impl<T> Sync for HigherOrderEngine<T>where
ComputationProfiler<T>: Sync,
impl<T> Unpin for HigherOrderEngine<T>
impl<T> UnsafeUnpin for HigherOrderEngine<T>
impl<T> UnwindSafe for HigherOrderEngine<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.