Skip to content

Commit 8dbe960

Browse files
finally it works
But in the worst code structure:v
1 parent 6def42d commit 8dbe960

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

NN/FFN/basicFFN/include/ffn.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BasicFFN {
6363
template <size_t inSize, size_t outSize>
6464
void init_layer(FP k, FP **w, FP *b) {
6565
// setup normal distribution
66-
std::uniform_real_distribution<FP> dis(-1, 1);
66+
std::normal_distribution<FP> dis(0, std::sqrt(2 / k));
6767

6868
for (size_t i = 0; i < outSize; ++i) {
6969
for (size_t j = 0; j < inSize; ++j) w[j][i] = dis(gen);

NN/FFN/basicFFN/src/basicFFN.cxx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@
1818
*/
1919

2020
#include <cmath>
21+
#include <cstring>
2122
#include <ffn.hxx>
2223
#include <iostream>
24+
#include <map>
25+
#include <string>
2326

24-
int main() {
27+
int main(int argc, const char **argv) {
2528
using namespace NN;
2629
using namespace std;
2730
BasicFFN<double, 1, 1024, 1024, 1> ffn;
2831
ffn.set_learning_rate(1e-3);
2932
ffn.set_epsilon(1e-12);
30-
ffn.set_debug_mode(true);
33+
ffn.set_weights_filename("wb.bin");
34+
// ffn.set_debug_mode(true);
3135
std::cout << std::fixed << std::setprecision(32) << std::endl;
3236
double inputcond[1]{(double)rand() / RAND_MAX};
3337
double targetcond[1]{std::sin(inputcond[0])};
@@ -38,6 +42,7 @@ int main() {
3842
std::cout << "inputData\t" << inputData[0] << std::endl;
3943
std::cout << "targetData\t" << targetData[0] << std::endl;
4044
std::cout << "realforward\t" << *ffn.forward(inputData) << "\n\n";
45+
ffn.save_weights();
4146
}
4247
double input[2]{rand() / (double)RAND_MAX, rand() / (double)RAND_MAX};
4348
std::cout << "inputcond\t" << inputcond[0] << std::endl;

wb.bin

8.03 MB
Binary file not shown.

0 commit comments

Comments
 (0)