OpenNN
2.2
Open Neural Networks Library
|
#include <perceptron.h>
Public Types | |
enum | ActivationFunction { Threshold, SymmetricThreshold, Logistic, HyperbolicTangent, Linear } |
Public Member Functions | |
Perceptron (void) | |
Perceptron (const size_t &) | |
Perceptron (const size_t &, const double &) | |
Perceptron (const Perceptron &) | |
virtual | ~Perceptron (void) |
Perceptron & | operator= (const Perceptron &) |
bool | operator== (const Perceptron &) const |
size_t | get_inputs_number (void) const |
const ActivationFunction & | get_activation_function (void) const |
std::string | write_activation_function (void) const |
const double & | get_bias (void) const |
const Vector< double > & | arrange_synaptic_weights (void) const |
const double & | get_synaptic_weight (const size_t &) const |
size_t | count_parameters_number (void) const |
Vector< double > | arrange_parameters (void) const |
const bool & | get_display (void) const |
void | set (void) |
void | set (const size_t &) |
void | set (const size_t &, const double &) |
void | set (const Perceptron &) |
void | set_inputs_number (const size_t &) |
void | set_activation_function (const ActivationFunction &) |
void | set_activation_function (const std::string &) |
void | set_bias (const double &) |
void | set_synaptic_weights (const Vector< double > &) |
void | set_synaptic_weight (const size_t &, const double &) |
void | set_parameters (const Vector< double > &) |
void | set_display (const bool &) |
void | grow_input (void) |
void | prune_input (const size_t &) |
void | initialize_bias (const double &) |
void | initialize_bias_uniform (const double &, const double &) |
void | initialize_bias_normal (const double &, const double &) |
void | initialize_synaptic_weights (const double &) |
void | initialize_synaptic_weights_uniform (const double &, const double &) |
void | initialize_synaptic_weights_normal (const double &, const double &) |
void | initialize_parameters (const double &) |
double | calculate_combination (const Vector< double > &) const |
Vector< double > | calculate_combination_gradient (const Vector< double > &) const |
Matrix< double > | calculate_combination_Hessian (const Vector< double > &) const |
double | calculate_combination (const Vector< double > &, const Vector< double > &) const |
Vector< double > | calculate_combination_gradient (const Vector< double > &, const Vector< double > &) const |
Matrix< double > | calculate_combination_Hessian (const Vector< double > &, const Vector< double > &) const |
double | calculate_activation (const double &) const |
double | calculate_activation_derivative (const double &) const |
double | calculate_activation_second_derivative (const double &) const |
double | calculate_output (const Vector< double > &) const |
Vector< double > | calculate_gradient (const Vector< double > &) const |
Matrix< double > | calculate_Hessian (const Vector< double > &) const |
double | calculate_output (const Vector< double > &, const Vector< double > &) const |
Vector< double > | calculate_gradient (const Vector< double > &, const Vector< double > &) const |
Matrix< double > | calculate_Hessian (const Vector< double > &, const Vector< double > &) const |
std::string | write_expression (const Vector< std::string > &, const std::string &) const |
Private Attributes | |
double | bias |
Vector< double > | synaptic_weights |
ActivationFunction | activation_function |
bool | display |
This class represents the concept of perceptron neuron model. A perceptron will be used to construct layers of perceptrons, which will be used to construct multilayer perceptrons. The perceptron implemented here admits a variety of activation or transfer functions.
Definition at line 36 of file perceptron.h.
|
explicit |
Default constructor. It creates a perceptron object with zero inputs. The neuron's bias is initialized to zero. This constructor also initializes the rest of class members to their default values.
Definition at line 26 of file perceptron.cpp.
|
explicit |
Inputs number constructor. It creates a perceptron object with a given number of inputs. The neuron's free paramameters (bias and synaptic weights) are initialized at random with a normal distribution of mean 0 and standard deviation 1. This constructor also initializes the rest of class members to their default values.
new_inputs_number | Number of inputs in the neuron. |
Definition at line 39 of file perceptron.cpp.
|
explicit |
Inputs number and initialization constructor. This creates a perceptron with a given number of inputs. It also initializes the bias and synaptic weights with a given value.
new_inputs_number | Number of inputs in the neuron. |
new_parameters_value | Bias and synaptic weights initialization value. |
Definition at line 51 of file perceptron.cpp.
OpenNN::Perceptron::Perceptron | ( | const Perceptron & | other_perceptron | ) |
Copy constructor. It creates a percdeptron object by copying its members with those for other perceptron object.
other_perceptron | Perceptron object to be copied. |
Definition at line 61 of file perceptron.cpp.
|
virtual |
Destructor. This destructor does not delete any pointer.
Definition at line 70 of file perceptron.cpp.
double OpenNN::Perceptron::calculate_activation | ( | const double & | combination | ) | const |
Returns the activation from the neuron for a combination. The outputs depends on the activation function used.
combination | Combination of the neuron. |
Definition at line 791 of file perceptron.cpp.
double OpenNN::Perceptron::calculate_activation_derivative | ( | const double & | combination | ) | const |
Returns the activation derivative of the neuron for a combination. The activation derivative depends on the activation function used.
combination | Combination of the neuron. |
Definition at line 860 of file perceptron.cpp.
double OpenNN::Perceptron::calculate_activation_second_derivative | ( | const double & | combination | ) | const |
Returns the activation second derivative of the neuron for a combination. The second derivative of the outputs depends on the activation function used.
combination | Combination of the neuron. |
Definition at line 945 of file perceptron.cpp.
double OpenNN::Perceptron::calculate_combination | ( | const Vector< double > & | inputs | ) | const |
Returns the combination to the neuron for a set of inputs signals, using the dot product combination function.
inputs | Set of inputs signals to the neuron. |
Definition at line 683 of file perceptron.cpp.
double OpenNN::Perceptron::calculate_combination | ( | const Vector< double > & | inputs, |
const Vector< double > & | parameters | ||
) | const |
Returns which would be the combination for some inputs and for a potential set of parameters.
inputs | Vector of inputs to the perceptron. |
parameters | Potential bias and synaptic weights in the perceptron. |
Definition at line 736 of file perceptron.cpp.
Vector< double > OpenNN::Perceptron::calculate_combination_gradient | ( | const Vector< double > & | inputs, |
const Vector< double > & | |||
) | const |
Returns the partial derivatives of the combination with respect to the parameters at some inputs point.
inputs | Vector of inputs to the perceptron. |
Definition at line 1209 of file perceptron.cpp.
Matrix< double > OpenNN::Perceptron::calculate_combination_Hessian | ( | const Vector< double > & | , |
const Vector< double > & | |||
) | const |
Returns the second derivatives of the combination with respect to the parameters. The Hessian matrix of the combination parameters function is always a squared matrix of size the number of parameters and zero values.
Definition at line 1377 of file perceptron.cpp.
Returns the partial derivatives of the outputs with respect to the inputs.
inputs | Vector of inputs to the perceptron. |
Definition at line 1109 of file perceptron.cpp.
Vector< double > OpenNN::Perceptron::calculate_gradient | ( | const Vector< double > & | inputs, |
const Vector< double > & | parameters | ||
) | const |
Returns the partial derivatives of the outputs with respect to a given set of parameters and at a given inputs point.
inputs | Vector of inputs to the perceptron. |
parameters | Vector of potential parameters for the perceptron. |
Definition at line 1148 of file perceptron.cpp.
Returns the second partial derivatives of the outputs with respect to the inputs.
inputs | Vector of inputs to the perceptron. |
Definition at line 1256 of file perceptron.cpp.
Matrix< double > OpenNN::Perceptron::calculate_Hessian | ( | const Vector< double > & | inputs, |
const Vector< double > & | parameters | ||
) | const |
This method retuns the second derivatives of the outputs with respect to a given set of parameters, at some inputs point. This is called the Hessian of the outputs parameters function.
inputs | Input vector. |
parameters | Potential parameters vector. |
Definition at line 1293 of file perceptron.cpp.
double OpenNN::Perceptron::calculate_output | ( | const Vector< double > & | inputs | ) | const |
Returns the output from the neuron for a set of inputs signals. The output depends on the activation function used.
inputs | Set of input signals to the neuron. |
Definition at line 1028 of file perceptron.cpp.
double OpenNN::Perceptron::calculate_output | ( | const Vector< double > & | inputs, |
const Vector< double > & | parameters | ||
) | const |
Returns the output from the neuron for a set of inputs. The output depends on the activation function used.
inputs | Set of inputs signals to the neuron. |
parameters | Set of potential bias and synaptic weights in the perceptron. |
Definition at line 1063 of file perceptron.cpp.
const bool & OpenNN::Perceptron::get_display | ( | void | ) | const |
Returns true if messages from this class are to be displayed on the screen, or false if messages from this class are not to be displayed on the screen.
Definition at line 255 of file perceptron.cpp.
const double & OpenNN::Perceptron::get_synaptic_weight | ( | const size_t & | synaptic_weight_index | ) | const |
Returns the synaptic weight value with index i of the neuron.
synaptic_weight_index | Synaptic weight index. |
Definition at line 223 of file perceptron.cpp.
void OpenNN::Perceptron::grow_input | ( | void | ) |
Makes the perceptron to have one more input. The corresponding synaptic weight is initialized to zero.
Definition at line 1392 of file perceptron.cpp.
void OpenNN::Perceptron::initialize_bias | ( | const double & | value | ) |
Initializes the bias with a given value.
value | Initialization value. |
Definition at line 566 of file perceptron.cpp.
void OpenNN::Perceptron::initialize_bias_normal | ( | const double & | mean, |
const double & | standard_deviation | ||
) |
Initializes the neuron's bias with random values chosen from a normal distribution.
mean | Mean of normal distribution. |
standard_deviation | Standard deviation of normal distribution. |
Definition at line 630 of file perceptron.cpp.
void OpenNN::Perceptron::initialize_bias_uniform | ( | const double & | minimum, |
const double & | maximum | ||
) |
Initializes the neuron's bias with a random value chosen from a uniform distribution.
minimum | Minimum initialization value. |
maximum | Maximum initialization value. |
Definition at line 578 of file perceptron.cpp.
void OpenNN::Perceptron::initialize_parameters | ( | const double & | value | ) |
Initializes the bias and the synaptic weights with a given value.
value | Parameters initialization value. |
Definition at line 670 of file perceptron.cpp.
void OpenNN::Perceptron::initialize_synaptic_weights | ( | const double & | value | ) |
Initializes all the synaptic weights of the neuron with a given value.
value | Initialization value. |
Definition at line 606 of file perceptron.cpp.
void OpenNN::Perceptron::initialize_synaptic_weights_normal | ( | const double & | mean, |
const double & | standard_deviation | ||
) |
Initializes the neuron's synaptic weights with random values chosen from a normal distribution.
mean | Mean of normal distribution. |
standard_deviation | Standard deviation of normal distribution. |
Definition at line 659 of file perceptron.cpp.
void OpenNN::Perceptron::initialize_synaptic_weights_uniform | ( | const double & | minimum, |
const double & | maximum | ||
) |
Initializes the neuron's synaptic weights with random values chosen from an uniform distribution.
minimum | Minimum initialization value. |
maximum | Maximum initialization value. |
Definition at line 618 of file perceptron.cpp.
Perceptron & OpenNN::Perceptron::operator= | ( | const Perceptron & | other_perceptron | ) |
Assignment operator. It assigns to the current perceptron the members of an existing perceptron.
other_perceptron | Assigning perceptron object . |
Definition at line 81 of file perceptron.cpp.
bool OpenNN::Perceptron::operator== | ( | const Perceptron & | other_perceptron | ) | const |
Equal to operator. It compares this object with another object of the same class. It returns true if the members of the two objects have the same values, and false otherwise. @ param other_perceptron Perceptron to be compared with.
Definition at line 107 of file perceptron.cpp.
void OpenNN::Perceptron::prune_input | ( | const size_t & | index | ) |
This method removes a given input from the neuron.
index | Index of input to be removed. |
Definition at line 1403 of file perceptron.cpp.
void OpenNN::Perceptron::set | ( | const size_t & | new_inputs_number | ) |
Sets a new number of inputs. It also sets the other members of this object to their defaul values.
new_inputs_number | Number of inputs in the neuron. |
Definition at line 283 of file perceptron.cpp.
void OpenNN::Perceptron::set | ( | const size_t & | new_inputs_number, |
const double & | new_parameters_value | ||
) |
Sets the number of inputs to a given value and initializes the bias and the synaptic weights with a given value.
new_inputs_number | Number of inputs in the neuron. |
new_parameters_value | Parameters initialization value. |
Definition at line 304 of file perceptron.cpp.
void OpenNN::Perceptron::set | ( | const Perceptron & | other_perceptron | ) |
Sets the members of this perceptron object with those from other perceptron object.
other_perceptron | Setting perceptron object. |
Definition at line 320 of file perceptron.cpp.
void OpenNN::Perceptron::set_activation_function | ( | const ActivationFunction & | new_activation_function | ) |
Sets a new activation function in the neuron.
new_activation_function | Activation function. |
Definition at line 337 of file perceptron.cpp.
void OpenNN::Perceptron::set_activation_function | ( | const std::string & | new_activation_function_name | ) |
Sets a new activation function in the perceptron with a string containing the name of the activation function.
new_activation_function_name | String with name of activation function. |
Definition at line 349 of file perceptron.cpp.
void OpenNN::Perceptron::set_bias | ( | const double & | new_bias | ) |
Sets a new bias value for the perceptron.
new_bias | Bias value. |
Definition at line 389 of file perceptron.cpp.
void OpenNN::Perceptron::set_display | ( | const bool & | new_display | ) |
Sets a new display value. If it is set to true messages from this class are to be displayed on the screen; if it is set to false messages from this class are not to be displayed on the screen.
new_display | Display value. |
Definition at line 467 of file perceptron.cpp.
void OpenNN::Perceptron::set_inputs_number | ( | const size_t & | new_inputs_number | ) |
Sets a new number of inputs in the neuron. The new synaptic weights are initialized at random with a normal distribution of mean 0 and standard deviation 1.
new_inputs_number | Number of inputs in the neuton. |
Definition at line 480 of file perceptron.cpp.
void OpenNN::Perceptron::set_parameters | ( | const Vector< double > & | new_parameters | ) |
This method set a new set of parameters (bias and synaptic weights) to the perceptron.
new_parameters | New set of parameters |
Definition at line 529 of file perceptron.cpp.
void OpenNN::Perceptron::set_synaptic_weight | ( | const size_t & | synaptic_weight_index, |
const double & | new_synaptic_weight | ||
) |
Sets the synaptic weight value with index i for the neuron.
synaptic_weight_index | Synaptic weight index. |
new_synaptic_weight | Synaptic weight value. |
Definition at line 433 of file perceptron.cpp.
void OpenNN::Perceptron::set_synaptic_weights | ( | const Vector< double > & | new_synaptic_weights | ) |
This method a new set of synaptic weights for the perceptron.
new_synaptic_weights | Synaptic weight values. |
Definition at line 400 of file perceptron.cpp.
std::string OpenNN::Perceptron::write_expression | ( | const Vector< std::string > & | inputs_name, |
const std::string & | output_name | ||
) | const |
Returns a string with the mathematical expression represented by the perceptron.
inputs_name | Name of input variables to the neuron. |
output_name | Name of output variable from the neuron. |
Definition at line 1434 of file perceptron.cpp.