pub struct Linear { /* private fields */ }
Expand description
Linear network layer
Represents a fully connected layer with optional bias term
The parameters are a matrix of weights of size I x N where N is the dimensionality of the output and I the dimensionality of the input
Implementations
Trait Implementations
sourceimpl NetLayer for Linear
impl NetLayer for Linear
sourcefn forward(
&self,
input: &Matrix<f64>,
params: MatrixSlice<'_, f64>
) -> LearningResult<Matrix<f64>>
fn forward(
&self,
input: &Matrix<f64>,
params: MatrixSlice<'_, f64>
) -> LearningResult<Matrix<f64>>
Computes a matrix product
input should have dimensions N x I where N is the number of samples and I is the dimensionality of the input
sourcefn default_params(&self) -> Vec<f64>
fn default_params(&self) -> Vec<f64>
Initializes weights using Xavier initialization
weights drawn from gaussian distribution with 0 mean and variance 2/(input_size+output_size)
sourcefn back_input(
&self,
out_grad: &Matrix<f64>,
_: &Matrix<f64>,
_: &Matrix<f64>,
params: MatrixSlice<'_, f64>
) -> Matrix<f64>
fn back_input(
&self,
out_grad: &Matrix<f64>,
_: &Matrix<f64>,
_: &Matrix<f64>,
params: MatrixSlice<'_, f64>
) -> Matrix<f64>
The gradient of the output of this layer with respect to its input
sourcefn back_params(
&self,
out_grad: &Matrix<f64>,
input: &Matrix<f64>,
_: &Matrix<f64>,
_: MatrixSlice<'_, f64>
) -> Matrix<f64>
fn back_params(
&self,
out_grad: &Matrix<f64>,
input: &Matrix<f64>,
_: &Matrix<f64>,
_: MatrixSlice<'_, f64>
) -> Matrix<f64>
The gradient of the output of this layer with respect to its parameters
sourcefn param_shape(&self) -> (usize, usize)
fn param_shape(&self) -> (usize, usize)
The shape of the parameters used by this layer
sourcefn num_params(&self) -> usize
fn num_params(&self) -> usize
The number of parameters used by this layer
impl Copy for Linear
Auto Trait Implementations
impl RefUnwindSafe for Linear
impl Send for Linear
impl Sync for Linear
impl Unpin for Linear
impl UnwindSafe for Linear
Blanket Implementations
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstablefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> ToOwned for Twhere
T: Clone,
impl<T> ToOwned for Twhere
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
fn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
Uses borrowed data to replace owned data, usually by cloning. Read more