SuperNN
1.0.0
|
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 Layer & | operator[] (unsigned l) const |
Returns a const reference to a layer. More... | |
Layer & | operator[] (unsigned l) |
Returns a reference to a layer. More... | |
const Row & | run (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< Layer > | layers |
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... | |
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.
SuperNN::Network::Network | ( | ) |
Definition at line 82 of file network.cpp.
|
virtual |
Definition at line 86 of file network.cpp.
void SuperNN::Network::add_layer | ( | Layer & | l | ) |
Adds a layer to the network.
l | Layer 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.
n_layers | Number 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.
data | Data used in the evaluation |
limit | Limit between a correct classification and an incorrect one |
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.
data | Data used in the evaluation |
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.
data | Data used to evaluate the mean absolute error |
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.
data | Data used to evaluate the mean squared error |
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.
Definition at line 502 of file network.cpp.
unsigned SuperNN::Network::calc_num_weights | ( | ) | const |
Calculates the current 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.
clear_delta | If it should clear the calculated delta |
clear_run | If 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.
from_layer | First layer |
to_layer | Second 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.
from_layer | From layer id |
from_neuron | Neuron id |
to_layer | Target 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.
min | Minimum weight |
max | Maximum 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.
path | Input file path |
Exception | if the input file couldn't be opened |
Definition at line 381 of file network.cpp.
|
static |
Constructs a fully connected cascade neural network.
input | Number of neurons in the input layer |
hidden | Number of hidden layers |
output | Number of neurons in the output layer |
Definition at line 155 of file network.cpp.
|
static |
Constructs a 'standard' feed forward neural network with one hidden layer.
input | Number of neurons in the input layer |
hidden | Number of neurons in the hidden layer |
output | Number of neurons in the output layer |
Definition at line 90 of file network.cpp.
|
static |
Constructs a 'standard' feed forward neural network without hidden layers.
input | Number of neurons in the input layer |
output | Number of neurons in the output layer |
Definition at line 138 of file network.cpp.
|
static |
Constructs a 'standard' feed forward neural network with one hidden layer.
input | Number of neurons in the input layer |
hidden1 | Number of neurons in the first hidden layer |
hidden2 | Number of neurons in the second hidden layer |
output | Number of neurons in the output layer |
Definition at line 111 of file network.cpp.
const Layer & SuperNN::Network::operator[] | ( | unsigned | l | ) | const |
Returns a const reference to a layer.
l | Layer position |
Definition at line 525 of file network.cpp.
Layer & SuperNN::Network::operator[] | ( | unsigned | l | ) |
Returns a reference to a layer.
l | Layer position |
Definition at line 530 of file network.cpp.
Propagates an input in the network.
Note that this overwrites informations about the last run.
in | Data row to run the network with |
calc_error | If the output error and the MSE must be updated on the run |
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.
path | Output file path |
Exception | if 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.
type | Activation function type |
s | Activation function steepness |
Definition at line 341 of file network.cpp.
unsigned SuperNN::Network::size | ( | ) | const |
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.
|
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.