MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / learn

Method learn

src/RaceNet/Network.cpp:42–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42void Network::learn(std::vector<double> expectedOutput) {
43 Y = Matrix<double>({expectedOutput}); // row matrix
44
45 // Error E = 1/2 (expectedOutput - computedOutput)^2
46 // Then, we need to calculate the partial derivative of E with respect to W and B
47
48 // compute gradients
49 dEdB[hiddenLayersCount] = H[hiddenLayersCount + 1].subtract(Y).multiply(
50 H[hiddenLayersCount].dot(W[hiddenLayersCount]).add(B[hiddenLayersCount]).applyFunction(sigmoidePrime));
51 for (int i = hiddenLayersCount - 1; i >= 0; i--) {
52 dEdB[i] = dEdB[i + 1].dot(W[i + 1].transpose()).multiply(H[i].dot(W[i]).add(B[i]).applyFunction(sigmoidePrime));
53 }
54
55 for (int i = 0; i < hiddenLayersCount + 1; i++) {
56 dEdW[i] = H[i].transpose().dot(dEdB[i]);
57 }
58
59 // update weights
60 for (int i = 0; i < hiddenLayersCount + 1; i++) {
61 W[i] = W[i].subtract(dEdW[i].multiply(learningRate));
62 B[i] = B[i].subtract(dEdB[i].multiply(learningRate));
63 }
64}
65
66void Network::printToFile(Matrix<double> &m, std::ofstream &file) {
67 int h = m.getHeight();

Callers

nothing calls this directly

Calls 6

multiplyMethod · 0.80
subtractMethod · 0.80
applyFunctionMethod · 0.80
addMethod · 0.80
dotMethod · 0.80
transposeMethod · 0.80

Tested by

no test coverage detected