OpenNN  2.2
Open Neural Networks Library
Public Types | Public Member Functions | Private Attributes | List of all members
OpenNN::Perceptron Class Reference

#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)
 
Perceptronoperator= (const Perceptron &)
 
bool operator== (const Perceptron &) const
 
size_t get_inputs_number (void) const
 
const ActivationFunctionget_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
 

Detailed Description

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.

Constructor & Destructor Documentation

OpenNN::Perceptron::Perceptron ( void  )
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.

OpenNN::Perceptron::Perceptron ( const size_t &  new_inputs_number)
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.

Parameters
new_inputs_numberNumber of inputs in the neuron.

Definition at line 39 of file perceptron.cpp.

OpenNN::Perceptron::Perceptron ( const size_t &  new_inputs_number,
const double &  new_parameters_value 
)
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.

Parameters
new_inputs_numberNumber of inputs in the neuron.
new_parameters_valueBias 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.

Parameters
other_perceptronPerceptron object to be copied.

Definition at line 61 of file perceptron.cpp.

OpenNN::Perceptron::~Perceptron ( void  )
virtual

Destructor. This destructor does not delete any pointer.

Definition at line 70 of file perceptron.cpp.

Member Function Documentation

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.

Parameters
combinationCombination 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.

Parameters
combinationCombination 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.

Parameters
combinationCombination 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.

Parameters
inputsSet 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.

Parameters
inputsVector of inputs to the perceptron.
parametersPotential 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.

Parameters
inputsVector 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.

Vector< double > OpenNN::Perceptron::calculate_gradient ( const Vector< double > &  inputs) const

Returns the partial derivatives of the outputs with respect to the inputs.

Parameters
inputsVector 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.

Parameters
inputsVector of inputs to the perceptron.
parametersVector of potential parameters for the perceptron.

Definition at line 1148 of file perceptron.cpp.

Matrix< double > OpenNN::Perceptron::calculate_Hessian ( const Vector< double > &  inputs) const

Returns the second partial derivatives of the outputs with respect to the inputs.

Parameters
inputsVector 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.

Parameters
inputsInput vector.
parametersPotential 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.

Parameters
inputsSet 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.

Parameters
inputsSet of inputs signals to the neuron.
parametersSet 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.

Parameters
synaptic_weight_indexSynaptic 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.

Parameters
valueInitialization 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.

Parameters
meanMean of normal distribution.
standard_deviationStandard 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.

Parameters
minimumMinimum initialization value.
maximumMaximum 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.

Parameters
valueParameters 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.

Parameters
valueInitialization 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.

Parameters
meanMean of normal distribution.
standard_deviationStandard 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.

Parameters
minimumMinimum initialization value.
maximumMaximum 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.

Parameters
other_perceptronAssigning 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.

Parameters
indexIndex 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.

Parameters
new_inputs_numberNumber 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.

Parameters
new_inputs_numberNumber of inputs in the neuron.
new_parameters_valueParameters 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.

Parameters
other_perceptronSetting 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.

Parameters
new_activation_functionActivation 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.

Parameters
new_activation_function_nameString 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.

Parameters
new_biasBias 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.

Parameters
new_displayDisplay 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.

Parameters
new_inputs_numberNumber 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.

Parameters
new_parametersNew 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.

Parameters
synaptic_weight_indexSynaptic weight index.
new_synaptic_weightSynaptic 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.

Parameters
new_synaptic_weightsSynaptic 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.

Parameters
inputs_nameName of input variables to the neuron.
output_nameName of output variable from the neuron.

Definition at line 1434 of file perceptron.cpp.


The documentation for this class was generated from the following files: