17#ifndef NEURALNETWORK_H
18#define NEURALNETWORK_H
126 int const*
const& numNeuronsPerLayer,
223 void setInput(
double const*
const& input)
const;
230 double const value)
const;
309 double const*
const& dGdxyz)
const;
353 std::vector<std::string>
info()
const;
469 double const*
const& dEdb,
470 double* d2EdGdc)
const;
483 int numNeuronsPrevLayer,
This class implements a feed-forward neural network.
ActivationFunction
List of available activation function types.
@ AF_UNSET
Unset activation function.
@ AF_RELU
(NOT recommended for HDNNPs!)
int getNumConnections() const
Return total number of connections.
Layer * inputLayer
Pointer to input layer.
void setInput(double const *const &input) const
Set neural network input layer node values.
int getNumNeurons() const
Return total number of neurons.
int * biasOnlyOffset
Offset adress of biases per layer in bias only array.
void modifyConnections(ModificationScheme modificationScheme)
Change connections according to a given modification scheme.
int numLayers
Total number of layers (includes input and output layers).
void calculateDEdb(double *dEdb) const
Calculate derivative of output neuron with respect to biases.
int getNumWeights() const
Return number of weights.
void setConnections(double const *const &connections)
Set neural network weights and biases.
void setInput(std::size_t const index, double const value) const
Set neural network input layer node values.
void writeConnections(std::ofstream &file) const
Write connections to file.
bool normalizeNeurons
If neurons are normalized.
void calculateDFdc(double *dFdc, double const *const &dGdxyz) const
Calculate "second" derivative of output with respect to connections.
void propagateLayer(Layer &layer, Layer &layerPrev)
Propagate information from one layer to the next.
void allocateLayer(Layer &layer, int numNeuronsPrevLayer, int numNeurons, ActivationFunction activationFunction)
Allocate a single layer.
int * weightOffset
Offset adress of weights per layer in combined weights+bias array.
void initializeConnectionsRandomUniform(unsigned int seed)
Initialize connections with random numbers.
int * biasOffset
Offset adress of biases per layer in combined weights+bias array.
void calculateD2EdGdc(int index, double const *const &dEdb, double *d2EdGdc) const
Calculate second derivative of output neuron with respect to input neuron and connections.
void getNeuronStatistics(long *count, double *min, double *max, double *sum, double *sum2) const
Return gathered neuron statistics.
int numBiases
Number of NN biases only.
void resetNeuronStatistics()
Reset neuron statistics.
ModificationScheme
List of available connection modification schemes.
@ MS_ZEROOUTPUTWEIGHTS
Set all weights connecting to the output layer to zero.
@ MS_ZEROBIAS
Set all bias values to zero.
@ MS_PRECONDITIONOUTPUT
Apply preconditioning to output layer connections.
@ MS_FANIN
Normalize weights via number of neuron inputs (fan-in).
@ MS_GLOROTBENGIO
Normalize connections according to Glorot and Bengio.
@ MS_NGUYENWIDROW
Initialize connections according to Nguyen-Widrow scheme.
void getConnections(double *connections) const
Get neural network weights and biases.
int numConnections
Number of NN connections (weights + biases).
void propagate()
Propagate input information through all layers.
void calculateDEdc(double *dEdc) const
Calculate derivative of output neuron with respect to connections.
void setNormalizeNeurons(bool normalizeNeurons)
Turn on/off neuron normalization.
int getNumBiases() const
Return number of biases.
void calculateDEdG(double *dEdG) const
Calculate derivative of output neuron with respect to input neurons.
void calculateDxdG(int index) const
Calculate derivative of neuron values before activation function with respect to input neuron.
Layer * layers
Neural network layers.
int numWeights
Number of NN weights only.
void getOutput(double *output) const
Get neural network output layer node values.
Layer * outputLayer
Pointer to output layer.
NeuralNetwork(int numLayers, int const *const &numNeuronsPerLayer, ActivationFunction const *const &activationFunctionsPerLayer)
Neural network class constructor.
int numHiddenLayers
Number of hidden layers.
std::vector< std::string > info() const
Print neural network architecture.
NeuralNetwork::ActivationFunction activationFromString(std::string c)
Convert string to activation function.
One neural network layer.
int numNeurons
Number of neurons in this layer .
Neuron * neurons
Array of neurons in this layer.
ActivationFunction activationFunction
Common activation function for all neurons in this layer.
int numNeuronsPrevLayer
Number of neurons in previous layer .
double * weights
NN weights assigned to neuron.
double bias
Bias value assigned to this neuron (if this is neuron this bias value is ).
double max
Maximum neuron value over data set (neuron statistics).
double sum
Sum of neuron values over data set (neuron statistics).
double dxdG
Derivative of neuron value before application of activation function with respect to input layer neur...
double value
Neuron value.
long count
How often the value of this neuron has been evaluated.
double d2fdx2
Second derivative of activation function with respect to its argument .
double dfdx
Derivative of activation function with respect to its argument .
double min
Minimum neuron value over data set (neuron statistics).
double x
Neuron value before application of activation function.
double sum2
Sum of squared neuron values over data set (neuron statistics).