jacobian

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

commit 1c820db25f3367af48b601704371484eaa0821da
parent 10f02ed24559e9f9f766c32f59798a4a42d3c90f
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Sun, 20 Sep 2020 12:39:02 -0700

Check fixes + more experiments with file read

Diffstat:
Mchecks.cpp | 12++++++------
Msrc/experimental/fileread.cpp | 81+++++++++++++++++++++++++++++++++++--------------------------------------------
2 files changed, 42 insertions(+), 51 deletions(-)

diff --git a/checks.cpp b/checks.cpp @@ -13,7 +13,7 @@ // Simple example network to be used in each check. Network default_net() { - Network net ("./data_banknote_authentication.txt", 16, 0.0155, 0.03, 2, 0, 0.9); + Network net ("./data_banknote_authentication.txt", 16, 0.0155, 0.03, L2, 0, 0.9); net.add_layer(4, "linear", linear, linear_deriv); net.add_layer(5, "lecun_tanh", lecun_tanh, lecun_tanh_deriv); net.add_layer(2, "linear", linear, linear_deriv); @@ -26,7 +26,7 @@ Network default_net() // Proper cloning of networks for providing a reference point. Network explicit_copy(Network src) { - Network dst ("./data_banknote_authentication.txt", 16, 0.0155, 0.03, 2, 0, 0.9); + Network dst ("./data_banknote_authentication.txt", 16, 0.0155, 0.03, L2, 0, 0.9); dst = src; for (int i = 0; i < src.layers.size(); i++) { dst.layers[i] = src.layers[i]; @@ -109,8 +109,8 @@ void floating_point_check(int& sanity_passed, int& total_checks) void update_check(int& sanity_passed, int& total_checks) { // std::cout << "Layer updates sanity check..."; - // Network copy6 ("./data_banknote_authentication.txt", 16, 0.05, 0.03, 0, 0.9); - // Network copy7 ("./data_banknote_authentication.txt", 16, 0.05, 0.03, 0, 0.9); + // Network copy6 ("./data_banknote_authentication.txt", 16, 0.05, 0.03, L2, 0, 0.9); + // Network copy7 ("./data_banknote_authentication.txt", 16, 0.05, 0.03, L2, 0, 0.9); // //copy2.list_net(); // //copy1.list_net(); // int passed; @@ -173,7 +173,7 @@ void optimizers_check(int& basic_passed, int& total_checks) try { std::string optimizers [5] = {"momentum", "demon", "adam", "adamax", "sgd"}; for (std::string optimizer : optimizers) { - Network net ("./data_banknote_authentication.txt", 16, 0.0155, 0.03, 2, 0, 0.9); + Network net ("./data_banknote_authentication.txt", 16, 0.0155, 0.03, L2, 0, 0.9); net.add_layer(4, "linear", linear, linear_deriv); net.add_layer(5, "lecun_tanh", lecun_tanh, lecun_tanh_deriv); net.add_layer(2, "linear", linear, linear_deriv); @@ -205,7 +205,7 @@ void prelu_check(int& basic_passed, int& total_checks) try { Network net = default_net(); for (int i = 0; i < 50; i++) { - Network net ("./data_banknote_authentication.txt", 16, 0.0155, 0.03, 2, 0, 0.9); + Network net ("./data_banknote_authentication.txt", 16, 0.0155, 0.03, L2, 0, 0.9); net.add_layer(4, "linear", linear, linear_deriv); net.add_prelu_layer(5, 0.01); net.add_layer(2, "linear", linear, linear_deriv); diff --git a/src/experimental/fileread.cpp b/src/experimental/fileread.cpp @@ -3,63 +3,54 @@ // Jacobian // // Created by David Freifeld -// Copyright © 2020 David Freifeld. All rights reserved. // +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <string.h> +#include <fcntl.h> +#include <ctime> +#include <chrono> +#include <iostream> -uintmax_t wc(char const *fname) -{ - static const auto BUFFER_SIZE = 1024; - int fd = open(fname, O_RDONLY); - if(fd == -1) - exit(1); +int main (){ + auto start = std::chrono::high_resolution_clock::now(); + static const auto BUFFER_SIZE = 16*1024; + int fd = open("../../data_banknote_authentication.txt", O_RDONLY); + if(fd == -1) { + printf("fd == -1\n"); + return 1; + } /* Advise the kernel of our access pattern. */ - //posix_fadvise(fd, 0, 0, 1); // FDADVICE_SEQUENTIAL + // posix_fadvise(fd, 0, 0, 1); // FDADVICE_SEQUENTIAL char buf[BUFFER_SIZE + 1]; uintmax_t lines = 0; while(size_t bytes_read = read(fd, buf, BUFFER_SIZE)) { - if(bytes_read == (size_t)-1) - exit(1); - if (!bytes_read) - break; + if(bytes_read == (size_t)-1) { + printf("bytes_read == (size_t)-1\n"); + return 1; + } + if (!bytes_read) break; for(char *p = buf; (p = (char*) memchr(p, '\n', (buf + bytes_read) - p)); ++p) { - printf("About to segfault? It's simple - just don't!\n"); - // printf("%s", p) - for (int i = 1; i < BUFFER_SIZE; i++) { - printf("%c", p[i]); - } - printf("\nGlad you heeded my advice.\n"); - printf("\n\nDONE\n\n"); - ++lines; - //printf(" DONE \n"); + ++lines; } } - - return lines; -} - -int istreamtest () { - std::filebuf fb; - if (fb.open ("extra.txt",std::ios::in)) - { - std::istream is(&fb); - char fchar = '-'; + auto end = std::chrono::high_resolution_clock::now(); + double time = std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count(); - const int MAX_LENGTH = 1024; - char* line = new char[MAX_LENGTH]; - auto get_begin = std::chrono::high_resolution_clock::now(); - int i = 0; - auto get_end = std::chrono::high_resolution_clock::now(); - while (is.getline(line, MAX_LENGTH) && strlen(line) > 0 && i < 10) { - auto get_end = std::chrono::high_resolution_clock::now(); - std::cout << line << "\n"; - i++; - } - std::cout << " GET " << std::chrono::duration_cast<std::chrono::nanoseconds>(get_end - get_begin).count() << "\n"; - fb.close(); - } - return 0; + auto f_start = std::chrono::high_resolution_clock::now(); + int flines = 0; + FILE* fptr = fopen("../../data_banknote_authentication.txt", "r"); + char fbuf[1024]; + while (fgets(fbuf, 1024, fptr) != NULL) flines++; + auto f_end = std::chrono::high_resolution_clock::now(); + std::cout << flines << " " << lines << "\n"; + double ftime = std::chrono::duration_cast<std::chrono::nanoseconds>(f_end - f_start).count(); + std::cout << ftime << " " << time << " " << ftime/time << "\n"; }