jacobian

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

commit 323a3c0100d2a1acb2098db6fbd70a32b68f2da5
parent 94a504a457a856654cc9edd8fc8a2b99604246cb
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Fri, 31 Jul 2020 19:05:06 -0700

Add more sklearn benchmarks

Diffstat:
Mbench/benchmark.py | 2++
Mbench/scikit.py | 13++++++++++---
Dpictures/metrics.png | 0
Apictures/metrics_updated.png | 0
Msrc/bpnn.cpp | 4++--
5 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/bench/benchmark.py b/bench/benchmark.py @@ -52,12 +52,14 @@ axs[0,0].plot([0.147248, 0.0459116, 0.0426555, 0.0399301, 0.038506, 0.0373933, 0 # axs[0,1].plot([0.6614238410596026, 0.8857615894039735, 0.9461920529801324, 0.9718543046357616, 0.9834437086092715, 0.9867549668874173, 0.9950331125827815, 0.9942052980132451, 0.9950331125827815, 0.9966887417218543, 0.9975165562913907, 0.9975165562913907, 0.9983443708609272, 0.9983443708609272, 0.9991721854304636, 0.9983443708609272, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 1.0, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 1.0, 0.9991721854304636, 1.0, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 1.0, 0.9991721854304636, 1.0, 0.9991721854304636, 0.9991721854304636, 0.9975165562913907, 0.9991721854304636, 0.9966887417218543, 0.9991721854304636], label="Keras", color="r") axs[0,1].plot([0.7425496688741722, 0.9130794701986755, 0.918046357615894, 0.9619205298013245, 0.9693708609271523, 0.9701986754966887, 0.9668874172185431, 0.9685430463576159, 0.9627483443708609, 0.9735099337748344, 0.9693708609271523, 0.9710264900662252, 0.9677152317880795, 0.9644039735099338, 0.9751655629139073, 0.9759933774834437, 0.9718543046357616, 0.9685430463576159, 0.9677152317880795, 0.9677152317880795, 0.9735099337748344, 0.9718543046357616, 0.9768211920529801, 0.972682119205298, 0.9735099337748344, 0.9743377483443708, 0.9718543046357616, 0.9751655629139073, 0.9759933774834437, 0.9710264900662252, 0.9743377483443708, 0.9759933774834437, 0.9743377483443708, 0.9759933774834437, 0.9751655629139073, 0.9735099337748344, 0.972682119205298, 0.9751655629139073, 0.9743377483443708, 0.9718543046357616, 0.9768211920529801, 0.9793046357615894, 0.9817880794701986, 0.9776490066225165, 0.9776490066225165, 0.9776490066225165, 0.9776490066225165, 0.9751655629139073, 0.9751655629139073, 0.9759933774834437], label="Keras", color="r") axs[0,1].plot([0.6614238410596026, 0.8857615894039735, 0.9461920529801324, 0.9718543046357616, 0.9834437086092715, 0.9867549668874173, 0.9950331125827815, 0.9942052980132451, 0.9950331125827815, 0.9966887417218543, 0.9975165562913907, 0.9975165562913907, 0.9983443708609272, 0.9983443708609272, 0.9991721854304636, 0.9983443708609272, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 1.0, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 1.0, 0.9991721854304636, 1.0, 0.9991721854304636, 0.9991721854304636, 0.9991721854304636, 1.0, 0.9991721854304636, 1.0, 0.9991721854304636, 0.9991721854304636, 0.9975165562913907, 0.9991721854304636, 0.9966887417218543, 0.9991721854304636], label="Keras (w/ val split)") +axs[0,1].plot([0.7014147431124349, 0.7967237527922562, 0.9009679821295606, 0.9635145197319435, 0.9746835443037974, 0.9806403574087863, 0.9888309754281459, 0.9851079672375279, 0.992553983618764, 0.9932985852568875, 0.9955323901712584, 0.996276991809382, 0.9970215934475056, 0.9970215934475056, 0.9970215934475056, 0.9970215934475056, 0.9977661950856291, 0.9977661950856291, 0.9985107967237528, 0.9985107967237528, 0.9985107967237528, 0.9985107967237528, 0.9985107967237528, 0.9985107967237528, 0.9985107967237528, 0.9985107967237528, 0.9985107967237528, 0.9985107967237528, 0.9992553983618764, 0.9992553983618764, 0.9992553983618764, 0.9992553983618764, 0.9992553983618764, 0.9992553983618764, 0.9992553983618764, 0.9992553983618764, 0.9992553983618764, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], label="SciKit Learn", color="orange") axs[0,1].plot([0.942975, 0.980992, 0.983471, 0.98595, 0.98595, 0.985124, 0.98595, 0.984298, 0.985124, 0.985124, 0.985124, 0.98595, 0.98595, 0.98595, 0.986777, 0.98595, 0.98595, 0.98595, 0.98595, 0.98595, 0.986777, 0.986777, 0.986777, 0.98595, 0.986777, 0.986777, 0.986777, 0.98595, 0.98595, 0.98595, 0.986777, 0.98595, 0.986777, 0.98595, 0.98595, 0.98595, 0.98595, 0.98595, 0.98595, 0.98595, 0.98595, 0.985124, 0.98595, 0.984298, 0.985124, 0.98595, 0.984298, 0.985124, 0.984298, 0.984298], label="Jacobian", color="g") axs[1,0].plot([0.10888315538565317, 0.06680880729798917, 0.053077199889553915, 0.07688223214613067, 0.045733443758002035, 0.03640310698085361, 0.031724032787261186, 0.04391241666895372, 0.031088130314041066, 0.026419770469268165, 0.026483222897405977, 0.02286748499781997, 0.023777789181029355, 0.01819943821540585, 0.021010621030021596, 0.017266716283780556, 0.015340352886252934, 0.016395327476439653, 0.01578087834296403, 0.015752164343440973, 0.01598852108474131, 0.01501362330659672, 0.016887195642899585, 0.016618405779202778, 0.011775514552438702, 0.013678248254237352, 0.011577272056429475, 0.011427491268625967, 0.014759536873963143, 0.011453486385720748, 0.013112282615017007, 0.012316111875353036, 0.017063750271443967, 0.010874567663779965, 0.011459515726676694, 0.011196554424586119, 0.010264440970840278, 0.011569284523526827, 0.009628297457540477, 0.009635593286818928, 0.01166622194427031, 0.016940338909626006, 0.014556518707562376, 0.01091362305537418, 0.019304899429833447, 0.014454653472812088, 0.018006062010924022, 0.018680620772971047, 0.014109227254434867, 0.011193500597167899], label="Keras (w/ val split)") axs[1,0].plot([0.0234097, 0.0141612, 0.0114124, 0.00986921, 0.00872293, 0.00805279, 0.00776756, 0.00758032, 0.00742217, 0.00729374, 0.0071354, 0.00701655, 0.0068978, 0.00680974, 0.00674059, 0.00668204, 0.00665047, 0.00661398, 0.00658959, 0.00655535, 0.00652, 0.00649501, 0.00647428, 0.00644689, 0.00643667, 0.00639617, 0.00637101, 0.00636733, 0.00634465, 0.00632476, 0.00632126, 0.00630413, 0.00628944, 0.00627891, 0.00626959, 0.0062554, 0.00623879, 0.00623331, 0.00622584, 0.00621284, 0.00620501, 0.00619419, 0.00618274, 0.00617308, 0.00616499, 0.00615112, 0.00612101, 0.00609225, 0.00607023, 0.0060534], label="Jacobian", color="g") axs[1,1].plot([0.8518518527348836, 0.9481481481481482, 1.0, 0.9481481481481482, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0], label="Keras (w/ val split)") +axs[1,1].plot([0.6888888888888889, 0.837037037037037, 0.9259259259259259, 0.9407407407407408, 0.9777777777777777, 0.9777777777777777, 0.9777777777777777, 0.9777777777777777, 0.9851851851851852, 0.9851851851851852, 0.9851851851851852, 0.9851851851851852, 0.9851851851851852, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] + ([1.0] * 25), label="SciKit Learn", color="orange") axs[1,1].plot([0.954887, 0.954887, 0.954887, 0.954887, 0.954887, 0.954887, 0.954887, 0.954887, 0.954887, 0.954887, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406, 0.962406], label="Jacobian", color="g") axs[0,0].legend(loc="upper right") diff --git a/bench/scikit.py b/bench/scikit.py @@ -2,6 +2,7 @@ from sklearn.neural_network import MLPClassifier import csv import matplotlib.pyplot as plt import time +import numpy as np def bench(batch_sz): start = time.time() @@ -18,11 +19,17 @@ def bench(batch_sz): X_train.append(i[:-1]) y_train.append(i[-1]) - clf = MLPClassifier(solver="sgd", momentum=0, learning_rate_init=0.0155, batch_size=batch_sz, max_iter=50, hidden_layer_sizes=(5)) - clf.fit(X_train, y_train) + clf = MLPClassifier(solver="sgd", momentum=0, learning_rate_init=0.0155, batch_size=batch_sz, max_iter=1, hidden_layer_sizes=(5), warm_start=True) + accuracy = [] + for i in range(50): + clf.fit(X_train, y_train) + accuracy.append(clf.score(X_train,y_train)) + end = time.time() print(clf.loss_curve_) - print(len(clf.loss_curve_)) + #print(clf.validation_scores_) + print(accuracy) + print(len(clf.loss_curve_), len(accuracy)) return end-start # i = 1 diff --git a/pictures/metrics.png b/pictures/metrics.png Binary files differ. diff --git a/pictures/metrics_updated.png b/pictures/metrics_updated.png Binary files differ. diff --git a/src/bpnn.cpp b/src/bpnn.cpp @@ -317,7 +317,7 @@ void Network::backpropagate() else if (reg_type == 1) *layers[length-2-i].weights -= ((lambda/(2*batch_size)) * l1_deriv(*layers[length-2-i].weights)); *layers[length-1-i].bias -= bias_lr * gradients[i]; - //std::cout << *layers[length-2-i].v << "\n\n" << *layers[length-2-i].weights << "\n\n" << deltas[i] << "\n\n\n\n"; + std::cout << *layers[length-2-i].v << "\n\n" << *layers[length-2-i].weights << "\n\n" << deltas[i] << "\n\n\n\n"; *layers[length-2-i].v = deltas[i]; if (strcmp(layers[length-2-i].activation_str, "prelu") == 0) { @@ -344,6 +344,7 @@ void Network::backpropagate() }; } } + std::cout << "---------------------------------------------------------\n"; } void Network::update_layer(float* vals, int datalen, int index) @@ -466,7 +467,6 @@ void Network::train() acc_sum += accuracy(); batches++; if (i > batch_size * 10) { - list_net(); exit(1); } // layers[10000000].alpha = 2;