commit 20c4f7901d459a689c9c4201b3bb3fb83ff61c5d
parent 482219a024553a9bdb161894972e35c86f561e83
Author: David Freifeld <freifeld.david@gmail.com>
Date: Thu, 25 Jun 2020 14:26:20 -0700
Added Xavier initialization?
Diffstat:
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/bpnn.cpp b/bpnn.cpp
@@ -1,6 +1,7 @@
#include "bpnn.hpp"
#include "utils.hpp"
#include <ctime>
+#include <random>
Layer::Layer(float* vals, int batch_sz, int nodes)
{
@@ -41,8 +42,12 @@ void Layer::init_weights(Layer next)
{
weights = new Eigen::MatrixXd (contents->cols(), next.contents->cols());
int nodes = weights->cols();
+ int n = contents->cols() + next.contents->cols();
+ std::normal_distribution<float> d(0,sqrt(1.0/n));
for (int i = 0; i < (weights->rows()*weights->cols()); i++) {
- (*weights)((int)i / nodes, i%nodes) = rand() / double(RAND_MAX);
+ std::random_device rd;
+ std::mt19937 gen(rd());
+ (*weights)((int)i / nodes, i%nodes) = d(gen);
}
}
diff --git a/example.cpp b/example.cpp
@@ -3,14 +3,14 @@
int main()
{
- Network net ("./extra.txt", 10, 0.5, 0.1);
+ Network net ("./data_banknote_authentication.txt", 10, 0.0001, 0.000001);
net.add_layer(4, "linear");
+ //net.add_layer(3, "resig");
net.add_layer(5, "sigmoid");
- // net.add_layer(3, "sigmoid");
net.add_layer(1, "resig");
net.initialize();
- //net.list_net();
- net.train(50);
+ net.list_net();
+ net.train(500);
// net.list_net();
//char line[1024];
//net.stream->getline(line, 1024);