SuperNN  1.0.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
SuperNN::Network Struct Reference

Artificial neural network structure that supports arbitrary feedforward topologies, like multilayer perceptrons and fully connected cascade networks. More...

Public Member Functions

 Network ()
 
virtual ~Network ()
 
void add_layer (Layer &l)
 Adds a layer to the network. More...
 
void add_layers (unsigned n_layers)
 Adds a number of layers to the network. More...
 
double calc_class (const Data &data, double limit=0.5)
 Calculates the classification rate of the network related to a data. More...
 
double calc_class_higher (const Data &data)
 Calculates the classification rate of the network related to a data. More...
 
double calc_mae (const Data &data)
 Calculates the mean absolute error of the network related to a data. More...
 
double calc_mse (const Data &data)
 Calculates the mean squared error of the network related to a data. More...
 
unsigned calc_num_inputs () const
 Calculates the number of neurons on the first layer that aren't biases. More...
 
unsigned calc_num_neurons () const
 Calculates the current number of neurons. More...
 
unsigned calc_num_weights () const
 Calculates the current number of weights. More...
 
void clear_neurons (bool clear_delta, bool clear_run)
 Clears the neuron state. More...
 
void connect (unsigned from_layer, unsigned to_layer)
 Connects all the neurons from a layer to all the neurons of another layer. More...
 
void connect_neuron_to_layer (unsigned from_layer, unsigned from_neuron, unsigned to_layer)
 Connects a neuron to all the neurons of another layer. More...
 
void init_weights (double min=-0.5, double max=0.5)
 Initializes the weights with pseudo-ramdom numbers. More...
 
void load_file (const std::string &path)
 Loads the network contents from a file. More...
 
const Layeroperator[] (unsigned l) const
 Returns a const reference to a layer. More...
 
Layeroperator[] (unsigned l)
 Returns a reference to a layer. More...
 
const Rowrun (const Row &in, bool calc_error=false)
 Propagates an input in the network. More...
 
void save_file (const std::string &path) const
 Saves the network contents to a file, for latter use. More...
 
void set_activation (ActFuncType type, double s=1)
 Sets the activation function for all the neurons currently in the network. More...
 
unsigned size () const
 Returns the number of layers. More...
 

Static Public Member Functions

static Network make_fcc (unsigned input, unsigned hidden, unsigned output)
 Constructs a fully connected cascade neural network. More...
 
static Network make_mlp (unsigned input, unsigned hidden, unsigned output)
 Constructs a 'standard' feed forward neural network with one hidden layer. More...
 
static Network make_mlp (unsigned input, unsigned output)
 Constructs a 'standard' feed forward neural network without hidden layers. More...
 
static Network make_mlp (unsigned input, unsigned hidden1, unsigned hidden2, unsigned output)
 Constructs a 'standard' feed forward neural network with one hidden layer. More...
 

Public Attributes

Row last_output
 Structure that holds the last output values. More...
 
std::vector< Layerlayers
 Neuron layers. More...
 

Protected Attributes

unsigned n_input
 Last computed number of neurons in the input layer that aren't biases, computed by run(). More...
 

Detailed Description

Artificial neural network structure that supports arbitrary feedforward topologies, like multilayer perceptrons and fully connected cascade networks.

Definition at line 78 of file network.hpp.

Constructor & Destructor Documentation

SuperNN::Network::Network ( )

Definition at line 82 of file network.cpp.

SuperNN::Network::~Network ( )
virtual

Definition at line 86 of file network.cpp.

Member Function Documentation

void SuperNN::Network::add_layer ( Layer l)

Adds a layer to the network.

Parameters
lLayer to be added

Definition at line 66 of file network.cpp.

void SuperNN::Network::add_layers ( unsigned  n_layers)

Adds a number of layers to the network.

Parameters
n_layersNumber of layers to be added

Definition at line 71 of file network.cpp.

double SuperNN::Network::calc_class ( const Data data,
double  limit = 0.5 
)

Calculates the classification rate of the network related to a data.

Verifies if every output differ less than the limit with the expected value.

Parameters
dataData used in the evaluation
limitLimit between a correct classification and an incorrect one
Returns
Classification rate, in the range [0, 100]

Definition at line 275 of file network.cpp.

double SuperNN::Network::calc_class_higher ( const Data data)

Calculates the classification rate of the network related to a data.

Only shows usefull information for 'one of c-classes' codifications. Searches for the higher output and expected value and checks if the neuron match.

Parameters
dataData used in the evaluation
Returns
Classification rate, in the range [0, 100]

Definition at line 299 of file network.cpp.

double SuperNN::Network::calc_mae ( const Data data)

Calculates the mean absolute error of the network related to a data.

As it calls run(), it also erases the information about the last run.

Parameters
dataData used to evaluate the mean absolute error
Returns
Mean absolute error of the network related to the used data

Definition at line 254 of file network.cpp.

double SuperNN::Network::calc_mse ( const Data data)

Calculates the mean squared error of the network related to a data.

As it calls run(), it also erases the information about the last run.

Parameters
dataData used to evaluate the mean squared error
Returns
Mean squared error of the network related to the used data

Definition at line 233 of file network.cpp.

unsigned SuperNN::Network::calc_num_inputs ( ) const

Calculates the number of neurons on the first layer that aren't biases.

Definition at line 512 of file network.cpp.

unsigned SuperNN::Network::calc_num_neurons ( ) const

Calculates the current number of neurons.

Returns
Number of neurons

Definition at line 502 of file network.cpp.

unsigned SuperNN::Network::calc_num_weights ( ) const

Calculates the current number of weights.

Returns
Number of weights

Definition at line 487 of file network.cpp.

void SuperNN::Network::clear_neurons ( bool  clear_delta,
bool  clear_run 
)

Clears the neuron state.

Parameters
clear_deltaIf it should clear the calculated delta
clear_runIf it should clear the last run info

Definition at line 463 of file network.cpp.

void SuperNN::Network::connect ( unsigned  from_layer,
unsigned  to_layer 
)

Connects all the neurons from a layer to all the neurons of another layer.

Parameters
from_layerFirst layer
to_layerSecond layer

Definition at line 449 of file network.cpp.

void SuperNN::Network::connect_neuron_to_layer ( unsigned  from_layer,
unsigned  from_neuron,
unsigned  to_layer 
)

Connects a neuron to all the neurons of another layer.

Parameters
from_layerFrom layer id
from_neuronNeuron id
to_layerTarget layer id

Definition at line 455 of file network.cpp.

void SuperNN::Network::init_weights ( double  min = -0.5,
double  max = 0.5 
)

Initializes the weights with pseudo-ramdom numbers.

Parameters
minMinimum weight
maxMaximum weight

Definition at line 327 of file network.cpp.

void SuperNN::Network::load_file ( const std::string &  path)

Loads the network contents from a file.

Parameters
pathInput file path
Exceptions
Exceptionif the input file couldn't be opened

Definition at line 381 of file network.cpp.

Network SuperNN::Network::make_fcc ( unsigned  input,
unsigned  hidden,
unsigned  output 
)
static

Constructs a fully connected cascade neural network.

Parameters
inputNumber of neurons in the input layer
hiddenNumber of hidden layers
outputNumber of neurons in the output layer
Returns
Network instance

Definition at line 155 of file network.cpp.

Network SuperNN::Network::make_mlp ( unsigned  input,
unsigned  hidden,
unsigned  output 
)
static

Constructs a 'standard' feed forward neural network with one hidden layer.

Parameters
inputNumber of neurons in the input layer
hiddenNumber of neurons in the hidden layer
outputNumber of neurons in the output layer
Returns
Network instance

Definition at line 90 of file network.cpp.

Network SuperNN::Network::make_mlp ( unsigned  input,
unsigned  output 
)
static

Constructs a 'standard' feed forward neural network without hidden layers.

Parameters
inputNumber of neurons in the input layer
outputNumber of neurons in the output layer
Returns
Network instance

Definition at line 138 of file network.cpp.

Network SuperNN::Network::make_mlp ( unsigned  input,
unsigned  hidden1,
unsigned  hidden2,
unsigned  output 
)
static

Constructs a 'standard' feed forward neural network with one hidden layer.

Parameters
inputNumber of neurons in the input layer
hidden1Number of neurons in the first hidden layer
hidden2Number of neurons in the second hidden layer
outputNumber of neurons in the output layer
Returns
Network instance

Definition at line 111 of file network.cpp.

const Layer & SuperNN::Network::operator[] ( unsigned  l) const

Returns a const reference to a layer.

Parameters
lLayer position
Returns
Const reference to the layer

Definition at line 525 of file network.cpp.

Layer & SuperNN::Network::operator[] ( unsigned  l)

Returns a reference to a layer.

Parameters
lLayer position
Returns
Reference to the layer

Definition at line 530 of file network.cpp.

const Row & SuperNN::Network::run ( const Row in,
bool  calc_error = false 
)

Propagates an input in the network.

Note that this overwrites informations about the last run.

Parameters
inData row to run the network with
calc_errorIf the output error and the MSE must be updated on the run
Returns
Reference to the output

Definition at line 176 of file network.cpp.

void SuperNN::Network::save_file ( const std::string &  path) const

Saves the network contents to a file, for latter use.

Parameters
pathOutput file path
Exceptions
Exceptionif the output file couldn't be written

Definition at line 347 of file network.cpp.

void SuperNN::Network::set_activation ( ActFuncType  type,
double  s = 1 
)

Sets the activation function for all the neurons currently in the network.

Parameters
typeActivation function type
sActivation function steepness

Definition at line 341 of file network.cpp.

unsigned SuperNN::Network::size ( ) const

Returns the number of layers.

Returns
Number of layers

Definition at line 535 of file network.cpp.

Member Data Documentation

Row SuperNN::Network::last_output

Structure that holds the last output values.

Definition at line 295 of file network.hpp.

std::vector<Layer> SuperNN::Network::layers

Neuron layers.

Definition at line 292 of file network.hpp.

unsigned SuperNN::Network::n_input
protected

Last computed number of neurons in the input layer that aren't biases, computed by run().

For internal use. The user should refer to calc_num_inputs, that is a pure function.

Definition at line 303 of file network.hpp.