Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
Loading...
Searching...
No Matches
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 > &kernel_shape, const bool &random_kernel)
 
 DenseLayer (const int &neurons, const std::string &activation, const std::vector< std::valarray< double > > &kernel)
 
 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 > > kernel
 

Detailed Description

neural_network::layers::DenseLayer class is used to store all necessary information about the layers (i.e. neurons, activation and kernel). 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 > & kernel_shape,
const bool & random_kernel )
inline

Constructor for neural_network::layers::DenseLayer class

Parameters
neuronsnumber of neurons
activationactivation function for layer
kernel_shapeshape of kernel
random_kernelflag for whether to intialize kernel randomly
143 {
144 // Choosing activation (and it's derivative)
145 if (activation == "sigmoid") {
146 activation_function = neural_network::activations::sigmoid;
147 dactivation_function = neural_network::activations::sigmoid;
148 } else if (activation == "relu") {
149 activation_function = neural_network::activations::relu;
150 dactivation_function = neural_network::activations::drelu;
151 } else if (activation == "tanh") {
152 activation_function = neural_network::activations::tanh;
153 dactivation_function = neural_network::activations::dtanh;
154 } else if (activation == "none") {
155 // Set identity function in casse of none is supplied
156 activation_function =
157 neural_network::util_functions::identity_function;
158 dactivation_function =
159 neural_network::util_functions::identity_function;
160 } else {
161 // If supplied activation is invalid
162 std::cerr << "ERROR (" << __func__ << ") : ";
163 std::cerr << "Invalid argument. Expected {none, sigmoid, relu, "
164 "tanh} got ";
165 std::cerr << activation << std::endl;
166 std::exit(EXIT_FAILURE);
167 }
168 this->activation = activation; // Setting activation name
169 this->neurons = neurons; // Setting number of neurons
170 // Initialize kernel according to flag
171 if (random_kernel) {
172 uniform_random_initialization(kernel, kernel_shape, -1.0, 1.0);
173 } else {
174 unit_matrix_initialization(kernel, kernel_shape);
175 }
176 }
T endl(T... args)
T exit(T... args)
void unit_matrix_initialization(std::vector< std::valarray< T > > &A, const std::pair< size_t, size_t > &shape)
Definition vector_ops.hpp:193
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:166
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 > > & kernel )
inline

Constructor for neural_network::layers::DenseLayer class

Parameters
neuronsnumber of neurons
activationactivation function for layer
kernelvalues of kernel (useful in loading model)
184 {
185 // Choosing activation (and it's derivative)
186 if (activation == "sigmoid") {
187 activation_function = neural_network::activations::sigmoid;
188 dactivation_function = neural_network::activations::sigmoid;
189 } else if (activation == "relu") {
190 activation_function = neural_network::activations::relu;
191 dactivation_function = neural_network::activations::drelu;
192 } else if (activation == "tanh") {
193 activation_function = neural_network::activations::tanh;
194 dactivation_function = neural_network::activations::dtanh;
195 } else if (activation == "none") {
196 // Set identity function in casse of none is supplied
197 activation_function =
198 neural_network::util_functions::identity_function;
199 dactivation_function =
200 neural_network::util_functions::identity_function;
201 } else {
202 // If supplied activation is invalid
203 std::cerr << "ERROR (" << __func__ << ") : ";
204 std::cerr << "Invalid argument. Expected {none, sigmoid, relu, "
205 "tanh} got ";
206 std::cerr << activation << std::endl;
207 std::exit(EXIT_FAILURE);
208 }
209 this->activation = activation; // Setting activation name
210 this->neurons = neurons; // Setting number of neurons
211 this->kernel = kernel; // Setting supplied kernel values
212 }
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: