pub struct KFACUtils;Expand description
K-FAC utilities for layer-specific operations
Implementations§
Source§impl KFACUtils
impl KFACUtils
Sourcepub fn conv_kfac_update<T: Float + ScalarOperand + 'static>(
input_patches: &Array2<T>,
output_gradients: &Array2<T>,
kernel_size: (usize, usize),
_stride: (usize, usize),
_padding: (usize, usize),
) -> Result<Array2<T>>
pub fn conv_kfac_update<T: Float + ScalarOperand + 'static>( input_patches: &Array2<T>, output_gradients: &Array2<T>, kernel_size: (usize, usize), _stride: (usize, usize), _padding: (usize, usize), ) -> Result<Array2<T>>
Compute the K-FAC weight-gradient statistic for a convolutional layer
from already-extracted patches — the same quantity
super::layer_state::KFACLayerState::weight_gradient computes for dense
layers. This is the un-preconditioned gradient; feed the result through
super::core::KFAC::apply_update_weight (G⁻¹ · grad · A⁻¹) to get the
actual K-FAC parameter update.
input_patches is the im2col-style patch matrix [samples, in_channels * kh * kw] (one row per (batch element, output spatial location) pair), optionally
with one extra trailing bias column, and output_gradients is the matching
per-location output gradient [samples, out_channels]; the two must
therefore share the same row count.
kernel_size, stride and padding describe how the caller produced
input_patches and are accepted as provenance metadata / a light
consistency check on input_patches’s column count. This function has no
super::config::LayerInfo to consult, so — unlike the dense path — it
cannot know whether the caller included a bias column; kernel_size is
therefore checked loosely (with or without one trailing bias column) rather
than rejected outright. stride/padding do not otherwise enter the
computation: the covariance of already-extracted patches doesn’t depend on
how they were extracted. This function does not perform patch
extraction itself — pass already-extracted patches.
The result is output_gradients^T @ input_patches / samples, the same
[out_features, in_features] convention used by
super::layer_state::KFACLayerState::weight_gradient for dense layers.
§Errors
Returns crate::error::OptimError::DimensionMismatch when input_patches
and output_gradients disagree on the sample count, or
crate::error::OptimError::InvalidParameter when input_patches’s column
count is not kernel_size.0 * kernel_size.1 * in_channels for any positive
in_channels, with or without one trailing bias column.
Sourcepub fn batchnorm_statistics<T: Float + FromPrimitive>(
input: &Array2<T>,
eps: T,
) -> Result<(Array1<T>, Array1<T>)>
pub fn batchnorm_statistics<T: Float + FromPrimitive>( input: &Array2<T>, eps: T, ) -> Result<(Array1<T>, Array1<T>)>
Compute batch normalization statistics for K-FAC
Sourcepub fn grouped_conv_kfac<T: Float + ScalarOperand>(
input: &Array2<T>,
gradients: &Array2<T>,
num_groups: usize,
) -> Result<Array2<T>>
pub fn grouped_conv_kfac<T: Float + ScalarOperand>( input: &Array2<T>, gradients: &Array2<T>, num_groups: usize, ) -> Result<Array2<T>>
Compute K-FAC update for grouped convolution layers
Sourcepub fn eigenvalue_regularization<T: Float + Debug + Send + Sync + 'static>(
matrix: &Array2<T>,
min_eigenvalue: T,
) -> Array2<T>
pub fn eigenvalue_regularization<T: Float + Debug + Send + Sync + 'static>( matrix: &Array2<T>, min_eigenvalue: T, ) -> Array2<T>
Compute eigenvalue-based regularization
Sourcepub fn kronecker_product_approx<T: Float + Debug + Send + Sync + 'static>(
a: &Array2<T>,
b: &Array2<T>,
) -> Array2<T>
pub fn kronecker_product_approx<T: Float + Debug + Send + Sync + 'static>( a: &Array2<T>, b: &Array2<T>, ) -> Array2<T>
Compute Kronecker product approximation for two matrices
Sourcepub fn trace<T: Float + Debug + Send + Sync + 'static>(matrix: &Array2<T>) -> T
pub fn trace<T: Float + Debug + Send + Sync + 'static>(matrix: &Array2<T>) -> T
Compute trace of a matrix
Sourcepub fn frobenius_norm<T: Float + Sum>(matrix: &Array2<T>) -> T
pub fn frobenius_norm<T: Float + Sum>(matrix: &Array2<T>) -> T
Compute Frobenius norm of a matrix
Sourcepub fn matrices_approx_equal<T: Float + Debug + Send + Sync + 'static>(
a: &Array2<T>,
b: &Array2<T>,
tolerance: T,
) -> bool
pub fn matrices_approx_equal<T: Float + Debug + Send + Sync + 'static>( a: &Array2<T>, b: &Array2<T>, tolerance: T, ) -> bool
Check if two matrices are approximately equal
Sourcepub fn exponential_moving_average<T: Float + Debug + Send + Sync + 'static>(
current_value: T,
new_value: T,
decay: T,
) -> T
pub fn exponential_moving_average<T: Float + Debug + Send + Sync + 'static>( current_value: T, new_value: T, decay: T, ) -> T
Compute running average with exponential decay
Sourcepub fn clamp_eigenvalues<T: Float + Debug + Send + Sync + 'static>(
eigenvalues: &mut Array1<T>,
min_val: T,
max_val: T,
)
pub fn clamp_eigenvalues<T: Float + Debug + Send + Sync + 'static>( eigenvalues: &mut Array1<T>, min_val: T, max_val: T, )
Clamp eigenvalues to prevent numerical instability
Sourcepub fn condition_number_svd_approx<T: Float + Debug + Send + Sync + 'static>(
matrix: &Array2<T>,
) -> T
pub fn condition_number_svd_approx<T: Float + Debug + Send + Sync + 'static>( matrix: &Array2<T>, ) -> T
Compute condition number using singular values (approximation)
Auto Trait Implementations§
impl Freeze for KFACUtils
impl RefUnwindSafe for KFACUtils
impl Send for KFACUtils
impl Sync for KFACUtils
impl Unpin for KFACUtils
impl UnsafeUnpin for KFACUtils
impl UnwindSafe for KFACUtils
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.