jacobian

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

commit fd2dd8912dbb784155fd3d46cf835c599b6458f9
parent 76ae33f01f4968537908cbbb4010d1444e974c37
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Mon, 29 Jun 2020 09:35:34 -0700

Poor attempts to benchmark more

Diffstat:
Mbpnn.cpp | 2+-
Mexample.cpp | 41+++++++++++++++++++----------------------
Mexample.py | 40++++++++++++++++++++--------------------
Mkerasdemo.py | 20++++++++++----------
4 files changed, 50 insertions(+), 53 deletions(-)

diff --git a/bpnn.cpp b/bpnn.cpp @@ -308,7 +308,7 @@ void Network::train(int total_epochs) } epoch_accuracy = 1.0/((float) instances/batch_size) * acc_sum; 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); + printf("Epoch %i/%i - cost %f - acc %f\n", epochs+1, total_epochs, epoch_cost, epoch_accuracy); batches=1; epochs++; rewind(data); diff --git a/example.cpp b/example.cpp @@ -3,31 +3,28 @@ #include "unistd.h" #include <ctime> -int main() +double bench(int batch_sz) { - Network net ("./data_banknote_authentication.txt", 10, 0.01, 0.001); + auto start = std::chrono::high_resolution_clock::now(); + Network net ("./data_banknote_authentication.txt", batch_sz, 0.0155, 0.03); net.add_layer(4, "linear"); - net.add_layer(5, "lecun_tanh"); + net.add_layer(5, "relu"); net.add_layer(1, "resig"); net.initialize(); - // net.list_net(); - net.train(1); - // net.list_net(); - //printf("%i\n", wc("./data_banknote_authentication.txt")); + net.train(50); + auto end = std::chrono::high_resolution_clock::now(); + return std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() / pow(10,9); +} - // double x = 0.4235; - // auto bench_start = std::chrono::high_resolution_clock::now(); - // x = tanh(x); - // printf("%lf", x); - // auto tanh_end = std::chrono::high_resolution_clock::now(); - // cosh(x); - // auto cosh_end = std::chrono::high_resolution_clock::now(); - // exp(x); - // auto exp_end = std::chrono::high_resolution_clock::now(); - // log(x); - // auto log_end = std::chrono::high_resolution_clock::now(); - // x = x - (1/3 * pow(x, 3)) + (2/15 * pow(x, 5)) - (17/315 * pow(x, 7)); - // printf("%lf", x); - // auto pow_end = std::chrono::high_resolution_clock::now(); - // std::cout << " TANH " << std::chrono::duration_cast<std::chrono::nanoseconds>(tanh_end - bench_start).count() << " COSH " << std::chrono::duration_cast<std::chrono::nanoseconds>(cosh_end - tanh_end).count() << " EXP " << std::chrono::duration_cast<std::chrono::nanoseconds>(exp_end - cosh_end).count() << " BETTER TANH? " << std::chrono::duration_cast<std::chrono::nanoseconds>(log_end - exp_end).count() << " POW " << std::chrono::duration_cast<std::chrono::nanoseconds>(pow_end - log_end).count() << "\n"; +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("]"); } diff --git a/example.py b/example.py @@ -11,7 +11,6 @@ def bench(batch_sz, layers): net.add_layer(5, "relu") net.add_layer(1, "resig") net.initialize() - initend = time.time() net.train(50) end = time.time() return (end-init) @@ -21,13 +20,14 @@ def bench(batch_sz, layers): # for i in range(trials): # timesum+=bench() # 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; +x = [] +y = [] +i = 1 +while(i < 1340): + y.append(bench(i, 1)) + x.append(i) + i+=1 +print(y) # plt.plot(x,y, label = "ML-in-Parallel (Sequential)") # i = 20 # otherlist = [] @@ -39,20 +39,20 @@ def bench(batch_sz, layers): # plt.legend() # plt.show() -sum = 0 -for i in range(10): - sum += bench(10, 1) -print(sum/10) +# sum = 0 +# for i in range(10): +# sum += bench(10, 1) +# print(sum/10) -x = ['Keras', 'MIP-Sequential'] -speed = [4.71297559738, 0.043680644035339354] +# x = ['Keras', 'MIP-Sequential'] +# speed = [4.71297559738, 0.043680644035339354] -x_pos = [i for i, _ in enumerate(x)] +# 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.bar(x_pos, speed, color='green') +# plt.ylabel("Time (s)") +# plt.title("Average Runtime (10 trials)") -plt.xticks(x_pos, x) +# plt.xticks(x_pos, x) -plt.show() +# plt.show() diff --git a/kerasdemo.py b/kerasdemo.py @@ -35,14 +35,14 @@ def kerasbench(batch_sz, layers): end = time.time() return (end-init) -sum = 0 -for i in range(10): - sum += kerasbench(10, 1) -print(sum/10) +# sum = 0 +# for i in range(10): +# sum += kerasbench(10, 1) +# print(sum/10) -# y2 = [] -# i = 20 -# while (i < 1340): -# y2.append(kerasbench(i, 1)) -# i+=20 -# print(y2) +y2 = [] +y2.append(kerasbench(1, 1)) +y2.append(kerasbench(5, 1)) +y2.append(kerasbench(10, 1)) +y2.append(kerasbench(15, 1)) +print(y2)