jacobian

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

commit 1f3f753317f0f5e2699b27a64fbff9e32d5e82af
parent 576b6092063be05f05b8adb9c828702c1ba0b4fc
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Wed,  1 Jul 2020 14:55:55 -0700

Using wandb to measure things more properly

Diffstat:
Mbpnn.cpp | 7+++++++
Mbpnn.hpp | 3+++
Mexample.cpp | 11++---------
Mexample.py | 71++++++++++++++++++-----------------------------------------------------
Mmr_bpnn_2.cpp | 3++-
5 files changed, 32 insertions(+), 63 deletions(-)

diff --git a/bpnn.cpp b/bpnn.cpp @@ -294,6 +294,7 @@ void Network::train(int total_epochs) //t++; } epoch_accuracy = 1.0/((float) instances/batch_size) * acc_sum; + epoch_acc = epoch_accuracy; epoch_cost = 1.0/((float) instances/batch_size) * cost_sum; printf("Epoch %i/%i - cost %f - acc %f\n", epochs+1, total_epochs, epoch_cost, epoch_accuracy); batches=1; @@ -301,3 +302,9 @@ void Network::train(int total_epochs) rewind(data); } } + +float Network::get_info() +{ + return epoch_acc; +} + diff --git a/bpnn.hpp b/bpnn.hpp @@ -38,6 +38,7 @@ public: int length; int t; + float epoch_acc; float learning_rate; float bias_lr; int batch_size; @@ -60,6 +61,8 @@ public: int next_batch(); float test(char* path); void train(int total_epochs); + + float get_info(); }; void demo(int total_epochs); diff --git a/example.cpp b/example.cpp @@ -18,13 +18,6 @@ double bench(int batch_sz) int main() { - double x[1340]; - for(int i = 0; i < 3; i++) { - x[i] = bench(i); - } - printf("["); - for(int i = 0; i < 3; i++) { - printf("%d, ", x[i]); - } - printf("]"); + sleep(10); + bench(10); } diff --git a/example.py b/example.py @@ -3,56 +3,21 @@ import matplotlib.pyplot as plt import numpy import time -def bench(batch_sz, layers): - init = time.time() - net = mrbpnn.Network("./data_banknote_authentication.txt", batch_sz, 0.0155, 0.03) - net.add_layer(4, "linear") - for i in range(layers): - net.add_layer(5, "relu") - net.add_layer(1, "resig") - net.initialize() -# net.list_net() - net.train(50) - end = time.time() - return (end-init) - -# timesum=0 -# trials = 20 -# for i in range(trials): -# timesum+=bench(10,1) -# print("Averages over %s trials\n--------------\nTime: %s seconds.\n" % (trials, timesum/trials)) -x = [] -y = [] -i = 1 -while(i < 1340): - y.append(bench(i, 1)) - x.append(i) - i+=1 -plt.plot(x,y, label = "Jacobian (Sequential)") -i = 20 -otherlist = [] -while(i < 1340): - otherlist.append(i) - i += 20 - -plt.plot(otherlist, [2.3994078636169434, 1.2735769748687744, 1.0030598640441895, 0.8972160816192627, 0.801548957824707, 0.752018928527832, 0.7073678970336914, 0.6857280731201172, 0.6707980632781982, 0.6421489715576172, 0.6614980697631836, 0.6403779983520508, 0.7251319885253906, 0.6796879768371582, 0.6601080894470215, 0.6711599826812744, 0.6432759761810303, 0.6491389274597168, 0.6762490272521973, 0.6859049797058105, 0.7067179679870605, 0.7142889499664307, 0.7258059978485107, 0.7868969440460205, 0.7326970100402832, 0.7365641593933105, 0.7576079368591309, 0.7772500514984131, 0.8062641620635986, 0.7768490314483643, 0.8253629207611084, 0.8264601230621338, 0.8459320068359375, 0.9670729637145996, 0.8388969898223877, 0.9129719734191895, 0.9009649753570557, 0.8916170597076416, 0.8926799297332764, 0.9171609878540039, 0.9242072105407715, 0.9534740447998047, 0.947465181350708, 0.9723358154296875, 1.018247127532959, 1.1208629608154297, 1.014026165008545, 1.034980058670044, 1.0626468658447266, 1.080394983291626, 1.0627479553222656, 1.0839190483093262, 1.0938241481781006, 1.127730131149292, 1.1265759468078613, 1.136888027191162, 1.140428066253662, 1.1712510585784912, 1.206390142440796, 1.2087180614471436, 1.4066569805145264, 1.2425589561462402, 1.280066967010498, 1.2891559600830078, 1.3243582248687744, 1.3152379989624023], label="Keras") -plt.legend() -plt.show() - -# # sum = 0 -# # for i in range(10): -# # sum += bench(10, 1) -# # print(sum/10) - -# # x = ['Keras', 'MIP-Sequential'] -# # speed = [4.71297559738, 0.043680644035339354] - -# # x_pos = [i for i, _ in enumerate(x)] - -# # plt.bar(x_pos, speed, color='green') -# # plt.ylabel("Time (s)") -# # plt.title("Average Runtime (10 trials)") - -# # plt.xticks(x_pos, x) - -# # plt.show() +batch_sz = 10 +layers = 1 + +net = mrbpnn.Network("./data_banknote_authentication.txt", batch_sz, 0.0155, 0.03) +net.add_layer(4, "linear") +for i in range(layers): + net.add_layer(5, "relu") +net.add_layer(1, "resig") +net.initialize() + +import wandb +wandb.init(project="jacobian") +wandb.config.update({"epochs": 50, "batch_size": batch_sz, "hidden_layers": layers}) +for i in range(50): + net.train(1) + wandb.log({'accuracy': net.get_info()}) + +wandb.save('jacobian.h5') diff --git a/mr_bpnn_2.cpp b/mr_bpnn_2.cpp @@ -118,5 +118,6 @@ PYBIND11_MODULE(mrbpnn, m) { .def("accuracy", &Network::accuracy) .def("update_layer", &Network::update_layer, py::arg("vals"), py::arg("len"), py::arg("index")) .def("next_batch", &Network::next_batch) - .def("train", &Network::train, py::arg("epochs")); + .def("train", &Network::train, py::arg("epochs")) + .def("get_info", &Network::get_info); }