20 #ifndef SUPERNN_NETWORK_HPP
21 #define SUPERNN_NETWORK_HPP
26 #include "activation_type.hpp"
36 struct Layer :
public std::vector<Neuron>
54 void add_neurons(
unsigned n_neurons,
bool bias =
false);
71 void connect(
unsigned to_layer,
unsigned to_neuron);
89 static Network make_mlp(
unsigned input,
unsigned hidden,
unsigned output);
111 static Network make_mlp(
unsigned input,
unsigned hidden1,
unsigned hidden2,
unsigned output);
121 static Network make_fcc(
unsigned input,
unsigned hidden,
unsigned output);
148 const Row &
run(
const Row &in,
bool calc_error =
false);
213 void save_file(
const std::string &path)
const;
230 void connect(
unsigned from_layer,
unsigned to_layer);
289 unsigned size()
const;
Neuron, that can contain connections to neurons in the next layers.
double calc_class(const Data &data, double limit=0.5)
Calculates the classification rate of the network related to a data.
void connect_neuron_to_layer(unsigned from_layer, unsigned from_neuron, unsigned to_layer)
Connects a neuron to all the neurons of another layer.
unsigned calc_num_weights() const
Calculates the current number of weights.
void add_neurons(unsigned n_neurons, bool bias=false)
Adds a number of neurons to the layer.
void set_activation(ActFuncType type, double s=1)
Sets the activation function for all the neurons currently in the network.
double calc_mse(const Data &data)
Calculates the mean squared error of the network related to a data.
std::vector< Layer > layers
Neuron layers.
unsigned calc_num_inputs() const
Calculates the number of neurons on the first layer that aren't biases.
void add_layer(Layer &l)
Adds a layer to the network.
double calc_mae(const Data &data)
Calculates the mean absolute error of the network related to a data.
void add_neuron(Neuron &n)
Adds a neuron to the layer.
static Network make_mlp(unsigned input, unsigned hidden, unsigned output)
Constructs a 'standard' feed forward neural network with one hidden layer.
void add_layers(unsigned n_layers)
Adds a number of layers to the network.
static Network make_fcc(unsigned input, unsigned hidden, unsigned output)
Constructs a fully connected cascade neural network.
unsigned n_input
Last computed number of neurons in the input layer that aren't biases, computed by run()...
void init_weights(double min=-0.5, double max=0.5)
Initializes the weights with pseudo-ramdom numbers.
void connect(unsigned from_layer, unsigned to_layer)
Connects all the neurons from a layer to all the neurons of another layer.
unsigned calc_num_neurons() const
Calculates the current number of neurons.
const Row & run(const Row &in, bool calc_error=false)
Propagates an input in the network.
double calc_class_higher(const Data &data)
Calculates the classification rate of the network related to a data.
Artificial neural network structure that supports arbitrary feedforward topologies, like multilayer perceptrons and fully connected cascade networks.
void set_activation(ActFuncType type, double s=1)
Sets the activation function for all the neurons currently in the layer.
const Layer & operator[](unsigned l) const
Returns a const reference to a layer.
ActFuncType
Activation functions built-in in the library.
void connect(unsigned to_layer, unsigned to_neuron)
Connects all the neurons of the layer to a neuron.
void load_file(const std::string &path)
Loads the network contents from a file.
std::vector< double > Row
Data row.
unsigned size() const
Returns the number of layers.
Row last_output
Structure that holds the last output values.
Data used in training, validation and testing.
void clear_neurons(bool clear_delta, bool clear_run)
Clears the neuron state.
void save_file(const std::string &path) const
Saves the network contents to a file, for latter use.