MCPcopy Create free account
hub / github.com/FidoProject/Fido / train

Method train

src/SGDTrainer.cpp:23–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23double SGDTrainer::train(net::NeuralNet *network, const std::vector< std::vector<double> > &input, const std::vector< std::vector<double> > &correctOutput) {
24 double totalError = 0;
25 int iterations = 0;
26 resetNetworkVectors(network);
27
28 do {
29 for(unsigned int a = 0; a < input.size(); a++) {
30 trainOnDataPoint(network, input[a], correctOutput[a]);
31 }
32
33 totalError = 0;
34 for(unsigned int trialIndex = 0; trialIndex < input.size(); trialIndex++) {
35 std::vector<double> output = network->getOutput(input[trialIndex]);
36 for(unsigned int outputIndex = 0; outputIndex < output.size(); outputIndex++) {
37 totalError += pow(correctOutput[trialIndex][outputIndex] - output[outputIndex], 2);
38 }
39 }
40 iterations++;
41 } while(totalError > targetErrorLevel && iterations < maximumEpochs);
42
43 //if(iterations >= maximumEpochs-1) std::cout << "SGDTrainer hit max epochs with an error level of " << totalError << ".\n";
44
45 finalWeights = network->getWeights3D();
46
47 return totalError;
48}
49
50double SGDTrainer::trainEpocs(double numberOfEpochs, net::NeuralNet *network, const std::vector< std::vector<double> > &input, const std::vector< std::vector<double> > &correctOutput) {
51 resetNetworkVectors(network);

Callers 7

trainOnHistoriesMethod · 0.80
pruning.cppFile · 0.80
backprop.cppFile · 0.80
adadelta.cppFile · 0.80
mainFunction · 0.80

Calls 3

getWeights3DMethod · 0.80
sizeMethod · 0.45
getOutputMethod · 0.45

Tested by

no test coverage detected