pub trait Criterion {
type ActFunc: ActivationFunc;
type Cost: CostFunc<Matrix<f64>>;
// Provided methods
fn activate(&self, mat: Matrix<f64>) -> Matrix<f64> { ... }
fn grad_activ(&self, mat: Matrix<f64>) -> Matrix<f64> { ... }
fn cost(&self, outputs: &Matrix<f64>, targets: &Matrix<f64>) -> f64 { ... }
fn cost_grad(
&self,
outputs: &Matrix<f64>,
targets: &Matrix<f64>,
) -> Matrix<f64> { ... }
fn regularization(&self) -> Regularization<f64> { ... }
fn is_regularized(&self) -> bool { ... }
fn reg_cost(&self, reg_weights: MatrixSlice<'_, f64>) -> f64 { ... }
fn reg_cost_grad(&self, reg_weights: MatrixSlice<'_, f64>) -> Matrix<f64> { ... }
}Expand description
Criterion for Neural Networks
Specifies an activation function and a cost function.
Required Associated Types§
Sourcetype ActFunc: ActivationFunc
type ActFunc: ActivationFunc
The activation function for the criterion.
Provided Methods§
Sourcefn activate(&self, mat: Matrix<f64>) -> Matrix<f64>
fn activate(&self, mat: Matrix<f64>) -> Matrix<f64>
The activation function applied to a matrix.
Sourcefn grad_activ(&self, mat: Matrix<f64>) -> Matrix<f64>
fn grad_activ(&self, mat: Matrix<f64>) -> Matrix<f64>
The gradient of the activation function applied to a matrix.
Sourcefn cost(&self, outputs: &Matrix<f64>, targets: &Matrix<f64>) -> f64
fn cost(&self, outputs: &Matrix<f64>, targets: &Matrix<f64>) -> f64
The cost function.
Returns a scalar cost.
Sourcefn cost_grad(&self, outputs: &Matrix<f64>, targets: &Matrix<f64>) -> Matrix<f64>
fn cost_grad(&self, outputs: &Matrix<f64>, targets: &Matrix<f64>) -> Matrix<f64>
The gradient of the cost function.
Returns a matrix of cost gradients.
Sourcefn regularization(&self) -> Regularization<f64>
fn regularization(&self) -> Regularization<f64>
Returns the regularization for this criterion.
Will return Regularization::None by default.
Sourcefn is_regularized(&self) -> bool
fn is_regularized(&self) -> bool
Checks if the current criterion includes regularization.
Will return false by default.
Sourcefn reg_cost(&self, reg_weights: MatrixSlice<'_, f64>) -> f64
fn reg_cost(&self, reg_weights: MatrixSlice<'_, f64>) -> f64
Returns the regularization cost for the criterion.
Will return 0 by default.
This method will not be invoked by the neural network if there is explicitly no regularization.
Sourcefn reg_cost_grad(&self, reg_weights: MatrixSlice<'_, f64>) -> Matrix<f64>
fn reg_cost_grad(&self, reg_weights: MatrixSlice<'_, f64>) -> Matrix<f64>
Returns the regularization gradient for the criterion.
Will return a matrix of zeros by default.
This method will not be invoked by the neural network if there is explicitly no regularization.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".