Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
machine_learning::neural_network::layers::DenseLayer Class Reference
Collaboration diagram for machine_learning::neural_network::layers::DenseLayer:
[legend]

Public Member Functions

 DenseLayer (const int &neurons, const std::string &activation, const std::pair< size_t, size_t > &kernal_shape, const bool &random_kernal)
 
 DenseLayer (const int &neurons, const std::string &activation, const std::vector< std::valarray< double >> &kernal)
 
 DenseLayer (const DenseLayer &layer)=default
 
 ~DenseLayer ()=default
 
DenseLayeroperator= (const DenseLayer &layer)=default
 
 DenseLayer (DenseLayer &&)=default
 
DenseLayeroperator= (DenseLayer &&)=default
 

Public Attributes

double(* activation_function )(const double &)
 
double(* dactivation_function )(const double &)
 
int neurons
 
std::string activation
 
std::vector< std::valarray< double > > kernal
 

Detailed Description

neural_network::layers::DenseLayer class is used to store all necessary information about the layers (i.e. neurons, activation and kernal). This class is used by NeuralNetwork class to store layers.

Constructor & Destructor Documentation

◆ DenseLayer() [1/4]

machine_learning::neural_network::layers::DenseLayer::DenseLayer ( const int &  neurons,
const std::string activation,
const std::pair< size_t, size_t > &  kernal_shape,
const bool &  random_kernal 
)
inline

Constructor for neural_network::layers::DenseLayer class

Parameters
neuronsnumber of neurons
activationactivation function for layer
kernal_shapeshape of kernal
random_kernalflag for whether to intialize kernal randomly
153  {
154  // Choosing activation (and it's derivative)
155  if (activation == "sigmoid") {
156  activation_function = neural_network::activations::sigmoid;
157  dactivation_function = neural_network::activations::sigmoid;
158  }
159  else if (activation == "relu") {
160  activation_function = neural_network::activations::relu;
161  dactivation_function = neural_network::activations::drelu;
162  }
163  else if (activation == "tanh") {
164  activation_function = neural_network::activations::tanh;
165  dactivation_function = neural_network::activations::dtanh;
166  }
167  else if (activation == "none") {
168  // Set identity function in casse of none is supplied
169  activation_function = neural_network::util_functions::identity_function;
170  dactivation_function = neural_network::util_functions::identity_function;
171  }
172  else {
173  // If supplied activation is invalid
174  std::cerr << "ERROR: Invalid argument for layer -> constructor -> activation, ";
175  std::cerr << "Expected from {none, sigmoid, relu, tanh} got ";
176  std::cerr << activation << std::endl;
177  std::exit(EXIT_FAILURE);
178  }
179  this -> activation = activation; // Setting activation name
180  this -> neurons = neurons; // Setting number of neurons
181  // Initialize kernal according to flag
182  if(random_kernal) {
183  uniform_random_initialization(kernal, kernal_shape, -1.0, 1.0);
184  }
185  else {
186  unit_matrix_initialization(kernal, kernal_shape);
187  }
188  }
Here is the call graph for this function:

◆ DenseLayer() [2/4]

machine_learning::neural_network::layers::DenseLayer::DenseLayer ( const int &  neurons,
const std::string activation,
const std::vector< std::valarray< double >> &  kernal 
)
inline

Constructor for neural_network::layers::DenseLayer class

Parameters
neuronsnumber of neurons
activationactivation function for layer
kernalvalues of kernal (useful in loading model)
197  {
198  // Choosing activation (and it's derivative)
199  if (activation == "sigmoid") {
200  activation_function = neural_network::activations::sigmoid;
201  dactivation_function = neural_network::activations::sigmoid;
202  }
203  else if (activation == "relu") {
204  activation_function = neural_network::activations::relu;
205  dactivation_function = neural_network::activations::drelu;
206  }
207  else if (activation == "tanh") {
208  activation_function = neural_network::activations::tanh;
209  dactivation_function = neural_network::activations::dtanh;
210  }
211  else if (activation == "none") {
212  // Set identity function in casse of none is supplied
213  activation_function = neural_network::util_functions::identity_function;
214  dactivation_function = neural_network::util_functions::identity_function;
215  }
216  else {
217  // If supplied activation is invalid
218  std::cerr << "ERROR: Invalid argument for layer -> constructor -> activation, ";
219  std::cerr << "Expected from {none, sigmoid, relu, tanh} got ";
220  std::cerr << activation << std::endl;
221  std::exit(EXIT_FAILURE);
222  }
223  this -> activation = activation; // Setting activation name
224  this -> neurons = neurons; // Setting number of neurons
225  this -> kernal = kernal; // Setting supplied kernal values
226  }
Here is the call graph for this function:

◆ DenseLayer() [3/4]

machine_learning::neural_network::layers::DenseLayer::DenseLayer ( const DenseLayer layer)
default

Copy Constructor for class DenseLayer.

Parameters
modelinstance of class to be copied.

◆ ~DenseLayer()

machine_learning::neural_network::layers::DenseLayer::~DenseLayer ( )
default

Destructor for class DenseLayer.

◆ DenseLayer() [4/4]

machine_learning::neural_network::layers::DenseLayer::DenseLayer ( DenseLayer &&  )
default

Move constructor for class DenseLayer

Member Function Documentation

◆ operator=() [1/2]

DenseLayer& machine_learning::neural_network::layers::DenseLayer::operator= ( const DenseLayer layer)
default

Copy assignment operator for class DenseLayer

◆ operator=() [2/2]

DenseLayer& machine_learning::neural_network::layers::DenseLayer::operator= ( DenseLayer &&  )
default

Move assignment operator for class DenseLayer


The documentation for this class was generated from the following file:
machine_learning::uniform_random_initialization
void uniform_random_initialization(std::vector< std::valarray< T >> &A, const std::pair< size_t, size_t > &shape, const T &low, const T &high)
Definition: vector_ops.hpp:162
machine_learning::unit_matrix_initialization
void unit_matrix_initialization(std::vector< std::valarray< T >> &A, const std::pair< size_t, size_t > &shape)
Definition: vector_ops.hpp:189
std::cerr
std::endl
T endl(T... args)
std::exit
T exit(T... args)