jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 8b2996b83953d4a1a973a01ed848cd03812b3509
parent d1986de5b3a05f971ab067bffd789e188e3b760b
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Sun, 20 Sep 2020 20:32:42 -0700

CNN tweaks and more fileread business

Diffstat:
Msrc/cnn.cpp | 12++++++------
Msrc/experimental/fileread.cpp | 28++++++++++++----------------
2 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/src/cnn.cpp b/src/cnn.cpp @@ -8,7 +8,7 @@ #include "bpnn.hpp" #include "utils.hpp" -#include <Eigen/unsupported/CXX11/Tensor> +//#include <Eigen/unsupported/CXX11/Tensor> #define LARGE_NUM 1000000 // Remove me. @@ -211,7 +211,7 @@ public: void initialize(); }; -ConvNet::ConvNet(char* path, float learn_rate, float bias_rate, int reg, float l, float ratio) +ConvNet::ConvNet(char* path, float learn_rate, float bias_rate, int reg, Regularization l, float ratio) : Network(path, 1, learn_rate, bias_rate, reg, l, ratio), preprocess_length{0} { ReadMNIST(10000,784,data); @@ -391,15 +391,15 @@ void ConvNet::train() int main() { - ConvNet net ("../data_banknote_authentication.txt", 0.05, 0.01, 2, 0, 0.9); + ConvNet net ("../data_banknote_authentication.txt", 0.05, 0.01, L2, 0, 0.9); Eigen::MatrixXf labels (1,1); net.add_conv_layer(28,28,1,9,9,0); // net.add_pool_layer(20,20,1,6,6,0); net.add_conv_layer(15,15,1,6,6,0); //net.add_pool_layer(10,10,1,2,2,0); - net.add_layer(400, "sigmoid"); - net.add_layer(5, "lecun_tanh"); - net.add_layer(10, "resig"); + net.add_layer(400, "sigmoid", sigmoid, sigmoid_deriv); + net.add_layer(5, "lecun_tanh", lecun_tanh, lecun_tanh_deriv); + net.add_layer(10, "resig", rectifier(sigmoid), rectifier(sigmoid_deriv)); // net.list_net(); // net.init_decay("step", 1, 2); net.initialize(); diff --git a/src/experimental/fileread.cpp b/src/experimental/fileread.cpp @@ -47,29 +47,24 @@ int main () { } if (!bytes_read) break; for(char *p = buf; (p = (char*) memchr(p, '\n', (buf + bytes_read) - p)); ++p) { - //long bound = (char*) memchr(p+1, '\n', (buf + bytes_read) - p+1) - p; + long bound = (char*) memchr(p+1, '\n', (buf + bytes_read) - p+1) - p; + if (bound < 0) break; // Stop. + // printf("%p (%p + %ld) vs %p\n", p+bound, p, bound, buf+BUFFER_SIZE); tmp = strtod(p, NULL); // Read first float - int delims = 0; - printf("%p out of %p\n", p-buf, BUFFER_SIZE); - for (int i = 0; delims < 4; i++) { // 3 is placeholder for now, but we know number of floats on each line - //printf("%p out of %p", p-buf, BUFFER_SIZE); + //int delims = 0; + // printf("%f\n", tmp); + for (int i = 0; i < bound; i++) { if (*(p+i) == ',') { tmp = strtod(p+i+1, NULL); // Read float following delimiter - delims++; - printf("Comma: %f %d\n", tmp, delims); + //printf("%f\n", tmp); + // delims++; + // printf("Comma: %f %d\n", tmp, delims); } } ++lines; } } - // delims = 0; - // for (int i = 0; i < delims; i++) { - // if (*(buf+bytes_read+i) == ',') { - // tmp = strtod(buf+bytes_read+i+1, NULL); - // } - // } - // printf("%zu %d\n", bytes_read, BUFFER_SIZE); printf("Final %f\n", tmp); auto end = std::chrono::high_resolution_clock::now(); double time = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count(); @@ -86,11 +81,12 @@ int main () { ftmp = strtod(p, NULL); p = strtok(NULL,","); } + ftmp = strtod(p, NULL); flines++; } auto f_end = std::chrono::high_resolution_clock::now(); - std::cout << flines << " " << lines << "\n"; - std::cout << ftmp << " " << tmp << "\n"; + if (flines == lines) std::cout << "Linecount is valid!" << "\n"; + if (ftmp == tmp) std::cout << "Final value read is valid!" << "\n"; double ftime = std::chrono::duration_cast<std::chrono::nanoseconds>(f_end - f_start).count(); std::cout << ftime << " " << time << " " << ftime/time << "\n"; }