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

Method loadNetworkParams

src/RaceNet/Network.cpp:97–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95}
96
97void Network::loadNetworkParams(const char *filepath) {
98 std::ifstream in(filepath);
99 std::vector<Matrix<double> > params;
100 double val;
101 int h, w;
102
103 if (in) {
104 in >> hiddenLayersCount;
105 in >> learningRate;
106
107 H = std::vector<Matrix<double> >(hiddenLayersCount + 2);
108 W = std::vector<Matrix<double> >(hiddenLayersCount + 1);
109 B = std::vector<Matrix<double> >(hiddenLayersCount + 1);
110 dEdW = std::vector<Matrix<double> >(hiddenLayersCount + 1);
111 dEdB = std::vector<Matrix<double> >(hiddenLayersCount + 1);
112
113 for (int i = 0; i < 2 * hiddenLayersCount + 2; i++) {
114 in >> h;
115 in >> w;
116 Matrix<double> m(h, w);
117 for (int hh = 0; hh < h; hh++) {
118 for (int ww = 0; ww < w; ww++) {
119 in >> val;
120 m.put(hh, ww, val);
121 }
122 }
123
124 params.push_back(m);
125 }
126 }
127 in.close();
128
129 // assign values
130 for (int i = 0; i < hiddenLayersCount + 1; i++) {
131 W[i] = params[i];
132 }
133
134 for (int i = hiddenLayersCount + 1; i < params.size(); i++) {
135 B[i - hiddenLayersCount - 1] = params[i];
136 }
137}
138
139double Network::random(double x) {
140 return (double) (rand() % 10000 + 1) / 10000 - 0.5;

Callers 1

CarMethod · 0.80

Calls 1

putMethod · 0.80

Tested by

no test coverage detected