jacobian

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

commit d21fb16b00ec4b51acc2cffc58828521d43695f3
parent 16b64229ee6e1bf7e0edfe779f6df94b39f7dd41
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Fri, 19 Jun 2020 17:43:24 -0700

More stats outputs, determined rough source of a bug

Diffstat:
Mbpnn.cpp | 14++++++++++----
Mmr_bpnn_2.cpp | 12++++++++----
2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/bpnn.cpp b/bpnn.cpp @@ -120,12 +120,15 @@ float Network::cost() float Network::accuracy() { float correct = 0; + int total = 0; for (int i = 0; i < layers[length-1].contents->rows(); i++) { - // printf("%lf vs %lf\n", (*labels)(i, 0), (*layers[length-1].contents)(i, 0)); if ((*labels)(i, 0) == round((*layers[length-1].contents)(i, 0))) { + // printf("Correct!\n"); correct += 1; } + total = i; } + // printf("CORRECT: %f/%i\n", correct, batch_size); // std::cout << (1.0/batch_size) * correct << "\n"; return (1.0/batch_size) * correct; } @@ -300,12 +303,15 @@ void demo(int total_epochs) break; } } - printf("Avg time spent across %i batches: %lf on feedforward, %lf on backprop, %lf on cost, %lf on acc, %lf on next batch\n", net.batches, times[0]/net.batches, times[1]/net.batches, times[2]/net.batches, times[3]/net.batches, times[4]/net.batches); - net.batches=1; epoch_accuracy = 1.0/((float) linecount/net.batch_size) * acc_sum; epoch_cost = 1.0/((float) linecount/net.batch_size) * cost_sum; auto ep_end = std::chrono::high_resolution_clock::now(); - printf("Epoch %i/%i - time %f - cost %f - acc %f\n", epochs+1, total_epochs, (double) std::chrono::duration_cast<std::chrono::nanoseconds>(ep_end-ep_begin).count() / pow(10,9), epoch_cost, epoch_accuracy); + double epochtime = (double) std::chrono::duration_cast<std::chrono::nanoseconds>(ep_end-ep_begin).count() / pow(10,9); + printf("───\nEpoch %i/%i - time %f - cost %f - acc %f\n", epochs+1, total_epochs, epochtime, epoch_cost, epoch_accuracy); + printf("Avg time spent across %i batches: %lf on feedforward, %lf on backprop, %lf on cost, %lf on acc, %lf on next batch.\n", net.batches, times[0]/net.batches, times[1]/net.batches, times[2]/net.batches, times[3]/net.batches, times[4]/net.batches); + printf("Time spent across epoch: %lf on feedforward, %lf on backprop, %lf on cost, %lf on acc, %lf on next batch, %lf other.\n", times[0], times[1], times[2], times[3], times[4], epochtime-times[0]-times[1]-times[2]-times[3]-times[4]); + + net.batches=1; epochs++; } printf("Test accuracy: %f\n", net.test("./test.txt")); diff --git a/mr_bpnn_2.cpp b/mr_bpnn_2.cpp @@ -5,7 +5,7 @@ struct pair* map (struct pair input_pair) char* path = new char[100]; path = (char*)input_pair.key; int linecount = prep_file(path); - Network* net = new Network (path, 4, 2, 1, 5, 1, 1); + Network* net = new Network (path, 4, 2, 1, 5, 10, 1); auto begin = std::chrono::high_resolution_clock::now(); // std::cout << "\n\n\n"; float epoch_cost = 1000; @@ -17,11 +17,11 @@ struct pair* map (struct pair input_pair) // std::cout << net.cost() << "\n"; printf("Beginning train on %i instances for %i epochs...\n", linecount, 50); - while (epochs < 50) { + while (epochs < 1) { auto ep_begin = std::chrono::high_resolution_clock::now(); float cost_sum = 0; float acc_sum = 0; - // int linecount = prep_file("./data_banknote_authentication.txt"); + int linecount = prep_file("./data_banknote_authentication.txt"); double times[5] = {0}; for (int i = 0; i <= linecount-net->batch_size; i+=net->batch_size) { auto feed_begin = std::chrono::high_resolution_clock::now(); @@ -32,6 +32,9 @@ struct pair* map (struct pair input_pair) cost_sum += net->cost(); // std::cout << acc_sum << " "<< net.accuracy() << " " << net.batch_size << "\n"; auto acc_begin = std::chrono::high_resolution_clock::now(); + if (i < 1*net->batch_size) { + printf("Batch accuracy: %f\n", net->accuracy()); + } acc_sum += net->accuracy(); // std::cout << net.cost() << " as it is " << net.labels[0] << " vs " << *net.layers[net.length-1].contents << "\n"; auto batch_begin = std::chrono::high_resolution_clock::now(); @@ -104,5 +107,6 @@ void translate(char* path) int main(int argc, char** argv) { - begin(argv[2], map, reduce, translate, strtol(argv[1], NULL, 10), 1, argv[3], strtol(argv[4], NULL, 10)); + // begin(argv[2], map, reduce, translate, strtol(argv[1], NULL, 10), 1, argv[3], strtol(argv[4], NULL, 10)); + demo(50); }