A classic backpropagation SGD Trainer. */
| 14 | |
| 15 | /** A classic backpropagation SGD Trainer. */ |
| 16 | class SGDTrainer : public Trainer { |
| 17 | public: |
| 18 | |
| 19 | /** |
| 20 | * \brief Initialize empty Backpropagation object |
| 21 | */ |
| 22 | SGDTrainer(); |
| 23 | |
| 24 | /** |
| 25 | * \brief Initialize the object with necessary constants. |
| 26 | * \param targetErrorLevel_ at this error level, a net will be considered trained |
| 27 | * \param maximumEpochs_ after this number of training iterations (one pass through all of the data points), a net will stop being trained no matter what |
| 28 | */ |
| 29 | SGDTrainer(double targetErrorLevel_, int maximumEpochs_); |
| 30 | |
| 31 | /** |
| 32 | * \brief Trains a neural network on a training set until the target error level is reached. |
| 33 | * |
| 34 | * Edits the weights of the neural network until its error in predicting the correctOutput of each input reaches the value of targetErrorLevel |
| 35 | * or the number of training cycles reaches the value of maximumIterations. |
| 36 | * NOTE: If learning rate is not low enough, the weights of the neural network may got to infinity due to the nature of backpropagation. |
| 37 | * |
| 38 | * \param network the neural network to be trained |
| 39 | * \param input a vector of neural network inputs; each element in input, should have a corresponding output in correctOutput |
| 40 | * \param correctOutput network is trained to output an element of correctOutput when fed a corresponding element of the input vector |
| 41 | */ |
| 42 | double train(net::NeuralNet *network, const std::vector< std::vector<double> > &input, const std::vector< std::vector<double> > &correctOutput); |
| 43 | |
| 44 | /** |
| 45 | * \brief Trains a neural network on a training set for a specified number of epochs. |
| 46 | * |
| 47 | * Edits the weights of the neural network until its error in predicting the correctOutput of each input reaches the value of targetErrorLevel |
| 48 | * or the number of training cycles reaches the value of maximumIterations. |
| 49 | * NOTE: If learning rate is not low enough, the weights of the neural network may got to infinity due to the nature of backpropagation. |
| 50 | * |
| 51 | * \param numberOfEpochs the number of training passes that will be made through the data |
| 52 | * \param network the neural network to be trained |
| 53 | * \param input a vector of neural network inputs; each element in input, should have a corresponding output in correctOutput |
| 54 | * \param correctOutput network is trained to output an element of correctOutput when fed a corresponding element of the input vector |
| 55 | */ |
| 56 | double trainEpocs(double numberOfEpochs, net::NeuralNet *network, const std::vector< std::vector<double> > &input, const std::vector< std::vector<double> > &correctOutput); |
| 57 | |
| 58 | void store(std::ofstream *out); |
| 59 | |
| 60 | bool initFromStream(std::ifstream *in); |
| 61 | |
| 62 | |
| 63 | double targetErrorLevel; /**< The target error level, set by constructor */ |
| 64 | int maximumEpochs; /**< The maximum number of iterations, set by constructor */ |
| 65 | |
| 66 | protected: |
| 67 | |
| 68 | /** |
| 69 | * \brief Gets the output of the neural network, calculates the error of each neuron, and edits the weights of the neurons to reduce error |
| 70 | * |
| 71 | * \param network the neural network to be trained |
| 72 | * \param input the input fed to the neural network |
| 73 | * \param correctOutput network is trained to output this when fed the input vector |
nothing calls this directly
no outgoing calls
no test coverage detected