/** * Artificial Neural Network header file. * * Vladimir Vacic * Computer Science and Engineering Department * University of California, Riverside * * May-6-2005 * */ #ifndef _NEURALNET_H_ #define _NEURALNET_H_ #include "Dataset.h" #include class NeuralNet { public: NeuralNet(); /** Neural Network constructor. * @param numNeurons vector of number of neurons per layer (first element * in the vector are the input neurons, then come the hidden layers, and * the last one is the output layer. * @ param outputFun vector of transition functions, one per layer. */ NeuralNet(vector numNeurons, vector outputFuns); ~NeuralNet(); /** Trains a neural network using the backpropagation algorithm. * @param epochs number of training epochs. */ void train(const Dataset &data, int epochs); /** Trains a neural network using the backpropagation algorithm. * @param epsilon mean squared error between targets and predictions */ void train(const Dataset &data, double epsilon); /** Predicts a single target based on the example vector. */ double predict(const vector data) const; /** Predicts a single target based on the exaple vector, and then assigns * the class label to be 0 if the target is below the threshold, and 1 * if the target is above the threshold. */ double predict(const vector data, double threshold) const; /** Predicts on the whole dataset. */ vector predict(const Dataset &data) const; /** Classifies the whole dataset based on the threshold. */ vector predict(const Dataset &data, double threshold) const; /** Returns a 2x2 confusion matrix containing: * * TP | FP * ----+---- * FN | TN * * TP are true positives, i.e. examples of class 1 predicted to be class 1 * FP are false positives, i.e. examples of class 0 prediceted to be class 1 * FN are false negatives, i.e. examples of class 1 predicted to be class 0 * TN are true negatives, i.e. examples of class 0 predicted to be class 0 */ double** test(const Dataset &data); /** Computes sensitivity of the prediction. */ double sensitivity(double** confusion); /** Computes specificity of the prediction. */ double specificity(double** confusion); private: vector numNeurons; vector outputFuns; // Here should come your data structures to store the weights, // biases and so forth. inline double tansig(double x) { return 2.0 / (1.0 + exp(-2.0 * x)) - 1.0; } inline double logsig(double x) { return 1.0 / (1.0 + exp(-x)); } }; #endif