Skip to main content

RegularizationOps

Trait RegularizationOps 

Source
pub trait RegularizationOps {
    type Output;
    type OutputMeta;

    // Required methods
    fn dropout(&self, rate: f64) -> Result<Self::Output, TensorError>
       where f64: Cast<Self::OutputMeta>,
             bool: Cast<Self::OutputMeta>,
             Self::OutputMeta: NormalOut<bool, Output = Self::OutputMeta>;
    fn shrinkage(
        &self,
        bias: Self::OutputMeta,
        lambda: Self::OutputMeta,
    ) -> Result<Self::Output, TensorError>;
}
Expand description

A trait contains regularization operations

Required Associated Types§

Source

type Output

The type of the output tensor

Source

type OutputMeta

The type of the output meta

Required Methods§

Source

fn dropout(&self, rate: f64) -> Result<Self::Output, TensorError>
where f64: Cast<Self::OutputMeta>, bool: Cast<Self::OutputMeta>, Self::OutputMeta: NormalOut<bool, Output = Self::OutputMeta>,

Randomly zeroes some of the elements of the input tensor with probability rate using samples from a Bernoulli distribution. Each element is zeroed independently.

§Parameters:

rate: Probability of an element to be zeroed. The value must be between 0 and 1.

§Example:
let x = Tensor::<f32>::ones(&[3, 4])?;
let dropped = x.dropout(0.5)?;
Source

fn shrinkage( &self, bias: Self::OutputMeta, lambda: Self::OutputMeta, ) -> Result<Self::Output, TensorError>

Applies the shrinkage function to the input tensor. The shrinkage function is a soft thresholding operator commonly used in signal processing and optimization algorithms, defined as: sign(x - bias) * max(abs(x - bias) - lambda, 0)

§Parameters:

bias: Bias value to subtract from each element before applying shrinkage.

lambda: Threshold parameter controlling the amount of shrinkage.

§Example:
let x = Tensor::<f32>::new(&[[-3.0, -1.0, 0.0, 2.0, 5.0]]);
let result = x.shrinkage(0.0, 1.5)?; // [[-1.5, 0.0, 0.0, 0.5, 3.5]]

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§