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
DenseLayer & | operator= (const DenseLayer &layer)=default
| DenseLayer (DenseLayer &&)=default
DenseLayer & | operator= (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

  neurons | number of neurons
  activation | activation function for layer
  kernel_shape | shape of kernel
  random_kernel | flag for whether to intialize kernel randomly

{
// Choosing activation (and it's derivative)
if (activation == "sigmoid") {
activation_function = neural_network::activations::sigmoid;
dactivation_function = neural_network::activations::sigmoid;
} else if (activation == "relu") {
activation_function = neural_network::activations::relu;
dactivation_function = neural_network::activations::drelu;
} else if (activation == "tanh") {
activation_function = neural_network::activations::tanh;
dactivation_function = neural_network::activations::dtanh;
} else if (activation == "none") {
// Set identity function in casse of none is supplied
activation_function =
neural_network::util_functions::identity_function;
dactivation_function =
neural_network::util_functions::identity_function;
} else {
// If supplied activation is invalid
std::cerr << "ERROR (" << __func__ << ") : ";
std::cerr << "Invalid argument. Expected {none, sigmoid, relu, "
"tanh} got ";
std::cerr << activation << std::endl;
std::exit(EXIT_FAILURE);
}
this->activation = activation; // Setting activation name
this->neurons = neurons; // Setting number of neurons
// Initialize kernel according to flag
if (random_kernel) {
uniform_random_initialization(kernel, kernel_shape, -1.0, 1.0);
} else {
unit_matrix_initialization(kernel, kernel_shape);
}
}
std::cerr
std::endl
T endl(T... args)
std::exit
T exit(T... args)
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:166
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:193
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

  neurons | number of neurons
  activation | activation function for layer
  kernel | values of kernel (useful in loading model)

{
// Choosing activation (and it's derivative)
if (activation == "sigmoid") {
activation_function = neural_network::activations::sigmoid;
dactivation_function = neural_network::activations::sigmoid;
} else if (activation == "relu") {
activation_function = neural_network::activations::relu;
dactivation_function = neural_network::activations::drelu;
} else if (activation == "tanh") {
activation_function = neural_network::activations::tanh;
dactivation_function = neural_network::activations::dtanh;
} else if (activation == "none") {
// Set identity function in casse of none is supplied
activation_function =
neural_network::util_functions::identity_function;
dactivation_function =
neural_network::util_functions::identity_function;
} else {
// If supplied activation is invalid
std::cerr << "ERROR (" << __func__ << ") : ";
std::cerr << "Invalid argument. Expected {none, sigmoid, relu, "
"tanh} got ";
std::cerr << activation << std::endl;
std::exit(EXIT_FAILURE);
}
this->activation = activation; // Setting activation name
this->neurons = neurons; // Setting number of neurons
this->kernel = kernel; // Setting supplied kernel values
}
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

  model | instance 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/neural_network.cpp