LinearType< MatType, RegularizerType > Class Template Reference

Implementation of the Linear layer class. More...

Inheritance diagram for LinearType< MatType, RegularizerType >:

Public Member Functions

 LinearType ()
 Create the Linear object. More...

 
 LinearType (const size_t outSize, RegularizerType regularizer=RegularizerType())
 Create the Linear layer object with the specified number of output dimensions. More...

 
 LinearType (const LinearType &layer)
 Copy the other Linear layer (but not weights). More...

 
 LinearType (LinearType &&layer)
 Take ownership of the members of the other Linear layer (but not weights). More...

 
virtual ~LinearType ()
 
void Backward (const MatType &, const MatType &gy, MatType &g)
 Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backwards trough f. More...

 
MatType const & Bias () const
 Get the bias of the layer. More...

 
MatType & Bias ()
 Modify the bias weights of the layer. More...

 
LinearTypeClone () const
 Clone the LinearType object. This handles polymorphism correctly. More...

 
void ComputeOutputDimensions ()
 Compute the output dimensions of the layer given InputDimensions(). More...

 
void Forward (const MatType &input, MatType &output)
 Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activity forward through f. More...

 
void Gradient (const MatType &input, const MatType &error, MatType &gradient)
 Calculate the gradient using the output delta and the input activation. More...

 
LinearTypeoperator= (const LinearType &layer)
 Copy the other Linear layer (but not weights). More...

 
LinearTypeoperator= (LinearType &&layer)
 Take ownership of the members of the other Linear layer (but not weights). More...

 
const MatType & Parameters () const
 Get the parameters. More...

 
MatType & Parameters ()
 Modify the parameters. More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t)
 Serialize the layer. More...

 
void SetWeights (typename MatType::elem_type *weightsPtr)
 Reset the layer parameter (weights and bias). More...

 
MatType const & Weight () const
 Get the weight of the layer. More...

 
MatType & Weight ()
 Modify the weight of the layer. More...

 
size_t WeightSize () const
 Get the size of the weights. More...

 
- Public Member Functions inherited from Layer< MatType >
 Layer ()
 Default constructor. More...

 
 Layer (const Layer &layer)
 Copy constructor. This is not responsible for copying weights! More...

 
 Layer (Layer &&layer)
 Move constructor. This is not responsible for moving weights! More...

 
virtual ~Layer ()
 Default deconstructor. More...

 
virtual void CustomInitialize (MatType &, const size_t)
 Override the weight matrix of the layer. More...

 
virtual void Forward (const MatType &, const MatType &)
 Takes an input and output object, and computes the corresponding loss of the layer. More...

 
const std::vector< size_t > & InputDimensions () const
 Get the input dimensions. More...

 
std::vector< size_t > & InputDimensions ()
 Modify the input dimensions. More...

 
virtual double Loss ()
 Get the layer loss. More...

 
virtual Layeroperator= (const Layer &layer)
 Copy assignment operator. This is not responsible for copying weights! More...

 
virtual Layeroperator= (Layer &&layer)
 Move assignment operator. This is not responsible for moving weights! More...

 
const std::vector< size_t > & OutputDimensions ()
 Get the output dimensions. More...

 
virtual size_t OutputSize () final
 Get the number of elements in the output from this layer. More...

 
template
<
typename
Archive
>
void serialize (Archive &ar, const uint32_t)
 Serialize the layer. More...

 
virtual bool const & Training () const
 Get whether the layer is currently in training mode. More...

 
virtual bool & Training ()
 Modify whether the layer is currently in training mode. More...

 

Additional Inherited Members

- Protected Attributes inherited from Layer< MatType >
std::vector< size_t > inputDimensions
 Logical input dimensions of each point. More...

 
std::vector< size_t > outputDimensions
 Logical output dimensions of each point. More...

 
bool training
 If true, the layer is in training mode; otherwise, it is in testing mode. More...

 
bool validOutputDimensions
 This is true if ComputeOutputDimensions() has been called, and outputDimensions can be considered to be up-to-date. More...

 

Detailed Description


template
<
typename
MatType
=
arma::mat
,
typename
RegularizerType
=
NoRegularizer
>

class mlpack::ann::LinearType< MatType, RegularizerType >

Implementation of the Linear layer class.

The Linear class represents a single layer of a neural network.

The linear layer applies a linear transformation to the incoming data (input), i.e. y = Ax + b. The input matrix given in Forward(input, output) must be either a vector or matrix. If the input is a matrix, then each column is assumed to be an input sample of given batch.

Template Parameters
MatTypeMatrix representation to accept as input and use for computation.
RegularizerTypeType of the regularizer to be used (Default no regularizer).

Definition at line 42 of file linear.hpp.

Constructor & Destructor Documentation

◆ LinearType() [1/4]

Create the Linear object.

Referenced by LinearType< MatType, RegularizerType >::Clone().

◆ LinearType() [2/4]

LinearType ( const size_t  outSize,
RegularizerType  regularizer = RegularizerType() 
)

Create the Linear layer object with the specified number of output dimensions.

Parameters
outSizeThe output dimension.
regularizerThe regularizer to use, optional (default: no regularizer).

◆ ~LinearType()

virtual ~LinearType ( )
inlinevirtual

Definition at line 59 of file linear.hpp.

◆ LinearType() [3/4]

LinearType ( const LinearType< MatType, RegularizerType > &  layer)

Copy the other Linear layer (but not weights).

◆ LinearType() [4/4]

LinearType ( LinearType< MatType, RegularizerType > &&  layer)

Take ownership of the members of the other Linear layer (but not weights).

Member Function Documentation

◆ Backward()

void Backward ( const MatType &  ,
const MatType &  gy,
MatType &  g 
)
virtual

Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backwards trough f.

Using the results from the feed forward pass.

To compute the downstream gradient (g) the chain rule is used.

Parameters
*(input) The propagated input activation.
gyThe backpropagated error.
gThe calculated gradient.

Reimplemented from Layer< MatType >.

Referenced by LinearType< MatType, RegularizerType >::Clone().

◆ Bias() [1/2]

MatType const& Bias ( ) const
inline

Get the bias of the layer.

Definition at line 131 of file linear.hpp.

◆ Bias() [2/2]

MatType& Bias ( )
inline

Modify the bias weights of the layer.

Definition at line 133 of file linear.hpp.

◆ Clone()

◆ ComputeOutputDimensions()

void ComputeOutputDimensions ( )
virtual

Compute the output dimensions of the layer given InputDimensions().

Reimplemented from Layer< MatType >.

Referenced by LinearType< MatType, RegularizerType >::WeightSize().

◆ Forward()

void Forward ( const MatType &  input,
MatType &  output 
)
virtual

Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activity forward through f.

f(x) is a linear transformation: Ax + b, where x is the given input, x are the layer weights and b is the layer bias.

Parameters
inputInput data used for evaluating the specified function.
outputResulting output activation.

Reimplemented from Layer< MatType >.

Referenced by LinearType< MatType, RegularizerType >::Clone().

◆ Gradient()

void Gradient ( const MatType &  input,
const MatType &  error,
MatType &  gradient 
)
virtual

Calculate the gradient using the output delta and the input activation.

Parameters
inputThe input parameter used for calculating the gradient.
errorThe calculated error.
gradientThe calculated gradient.

Reimplemented from Layer< MatType >.

Referenced by LinearType< MatType, RegularizerType >::Clone().

◆ operator=() [1/2]

LinearType& operator= ( const LinearType< MatType, RegularizerType > &  layer)

Copy the other Linear layer (but not weights).

Referenced by LinearType< MatType, RegularizerType >::Clone().

◆ operator=() [2/2]

LinearType& operator= ( LinearType< MatType, RegularizerType > &&  layer)

Take ownership of the members of the other Linear layer (but not weights).

◆ Parameters() [1/2]

const MatType& Parameters ( ) const
inlinevirtual

Get the parameters.

Reimplemented from Layer< MatType >.

Definition at line 121 of file linear.hpp.

◆ Parameters() [2/2]

MatType& Parameters ( )
inlinevirtual

Modify the parameters.

Reimplemented from Layer< MatType >.

Definition at line 123 of file linear.hpp.

◆ serialize()

void serialize ( Archive &  ar,
const uint32_t   
)

Serialize the layer.

Referenced by LinearType< MatType, RegularizerType >::WeightSize().

◆ SetWeights()

void SetWeights ( typename MatType::elem_type *  weightsPtr)
virtual

Reset the layer parameter (weights and bias).

The method is called to assign the allocated memory to the internal learnable parameters.

Reimplemented from Layer< MatType >.

Referenced by LinearType< MatType, RegularizerType >::Clone().

◆ Weight() [1/2]

MatType const& Weight ( ) const
inline

Get the weight of the layer.

Definition at line 126 of file linear.hpp.

◆ Weight() [2/2]

MatType& Weight ( )
inline

Modify the weight of the layer.

Definition at line 128 of file linear.hpp.

◆ WeightSize()

size_t WeightSize ( ) const
inlinevirtual

Get the size of the weights.

Reimplemented from Layer< MatType >.

Definition at line 136 of file linear.hpp.

References LinearType< MatType, RegularizerType >::ComputeOutputDimensions(), and LinearType< MatType, RegularizerType >::serialize().


The documentation for this class was generated from the following file:
  • /home/jenkins-mlpack/mlpack.org/_src/mlpack-git/src/mlpack/methods/ann/layer/linear.hpp