linear_no_bias.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_ANN_LAYER_LINEAR_NO_BIAS_HPP
14 #define MLPACK_METHODS_ANN_LAYER_LINEAR_NO_BIAS_HPP
15 
16 #include <mlpack/prereqs.hpp>
18 
19 #include "layer.hpp"
20 
21 namespace mlpack {
22 namespace ann {
23 
33 template<
34  typename MatType = arma::mat,
35  typename RegularizerType = NoRegularizer
36 >
37 class LinearNoBiasType : public Layer<MatType>
38 {
39  public:
42 
49  LinearNoBiasType(const size_t outSize,
50  RegularizerType regularizer = RegularizerType());
51 
53  LinearNoBiasType* Clone() const { return new LinearNoBiasType(*this); }
54 
56  void SetWeights(typename MatType::elem_type* weightsPtr);
57 
59  LinearNoBiasType(const LinearNoBiasType& layer);
60 
63 
66 
69 
71  virtual ~LinearNoBiasType() { }
72 
80  void Forward(const MatType& input, MatType& output);
81 
91  void Backward(const MatType& /* input */,
92  const MatType& gy,
93  MatType& g);
94 
102  void Gradient(const MatType& input,
103  const MatType& error,
104  MatType& gradient);
105 
107  const MatType& Parameters() const { return weight; }
109  MatType& Parameters() { return weight; }
110 
112  size_t WeightSize() const { return inSize * outSize; }
113 
116 
118  template<typename Archive>
119  void serialize(Archive& ar, const uint32_t /* version */);
120 
121  private:
123  size_t inSize;
124 
126  size_t outSize;
127 
129  MatType weight;
130 
132  RegularizerType regularizer;
133 }; // class LinearNoBiasType
134 
135 // Convenience typedefs.
136 
137 // Standard Linear without bias layer using no regularization.
139 
140 } // namespace ann
141 } // namespace mlpack
142 
143 // Include implementation.
144 #include "linear_no_bias_impl.hpp"
145 
146 #endif
LinearNoBiasType()
Create the LinearNoBias object.
Linear algebra utility functions, generally performed on matrices or vectors.
virtual ~LinearNoBiasType()
Virtual destructor.
LinearNoBiasType & operator=(const LinearNoBiasType &layer)
Copy assignment operator.
The core includes that mlpack expects; standard C++ includes and Armadillo.
LinearNoBiasType * Clone() const
Clone the LinearNoBiasType object. This handles polymorphism correctly.
void SetWeights(typename MatType::elem_type *weightsPtr)
Reset the layer parameter.
void Gradient(const MatType &input, const MatType &error, MatType &gradient)
Calculate the gradient using the output delta and the input activation.
Implementation of the LinearNoBias class.
void Forward(const MatType &input, MatType &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
size_t WeightSize() const
Get the number of weights in the layer.
LinearNoBiasType< arma::mat, NoRegularizer > LinearNoBias
MatType & Parameters()
Modify the parameters.
void ComputeOutputDimensions()
Compute the output dimensions of the layer using InputDimensions().
A layer is an abstract class implementing common neural networks operations, such as convolution...
Definition: layer.hpp:52
const MatType & Parameters() const
Get the parameters.
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 backw...