void ConvNet::learn(dmatrix4 &stimulus, dmatrix2 &target, int lessons) { assert(stimulus.size()==target.size()); if(lessons==0) lessons=stimulus.size(); for(int n=0;n<lessons;n++) { if (n%10 == 0) std::cout << "Learning lesson #" << n+1 << std::endl; learn(stimulus[n], target[n]); } }
real ConvNet::validation(dmatrix4 &lessons, dmatrix2 &targets) { assert(lessons.size()==targets.size()); double rounds = (double)lessons.size(); int result; // Holds the networks' prediction of the category int answer; // Holds the actual number of the right category int right = 0; // Holds the number of right answers for(int n=0;n<rounds;n++) { result = predict(lessons[n]); answer = *std::find(targets[n].begin(), targets[n].end(), 1.0); //index of 1.0 in targets if (result==answer) right++; } return ((double)right/(double)lessons.size()); }
ThoughtBubble PoolLayer::max_pool(dmatrix2 slice) const { dvec fslice(4); ivec bslice(4, 0); double maxi; ThoughtBubble output; maxi = *std::max_element(slice.point(), slice.point()+slice.size()); bslice[*std::find(slice.point(), slice.point()+slice.size(), maxi)] = 1; output.excitation = bslice; output.activation = maxi; return output; }