In [ ]:
import matplotlib as mpl
mpl.use('Agg')
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd
import scipy as sp
import seaborn as sns
import sys

In [ ]:
sys.path.append('../code')

In [ ]:
from NeuralNet import NeuralNet
from TransferFunctions import LinearTF

In [ ]:
# columns are data points and rows are features
X = np.array([[1, 0], [1, 0], [0, 1]]).T
y = np.array([0, 0, 1])
d, N = np.shape(X)
C = np.unique(y).shape[0]

In [ ]:
np.array([[-1, 0], [0,1]]).T

In [ ]:
n = NeuralNet(X=X, y=y, hidden_nodes=2, 
              hiddenTF=LinearTF, outputTF=LinearTF,
              minibatch_size=3,
              summarise_frequency=3,
              eta0 = 0.1,
              convergence_delta=1e-4)

Manually set weights


In [ ]:
print(n.W1.shape)
n.W1 = np.array([[0.01161103, 0],[0, 1]])
print(n.W1.shape)
n.W1

In [ ]:
print(n.W2.shape)
n.W2 = np.array([[-0.012, 0],[0, 1]])
print(n.W2.shape)
n.W2

Ready to run


In [ ]:
def point(vector, point_number):
    return vector[:, point_number-1:point_number]

In [ ]:
point(X,1)

In [ ]:
p = point(X,1)
print(p)
n.feed_forward_and_predict_Y(p)

In [ ]:
point(n.Y,1)

In [ ]:
n.Y

In [ ]:
point(n.Y, 3)

In [ ]:
p_num = 3
n.feed_forward(point(X, p_num))
dW1, dW2 = n.backprop(point(X, p_num), point(n.Y, p_num))
print(dW1)
print("")
print(dW2)

In [ ]:
# send two training points in 
X[:, 1:3]

In [ ]:
dW1, dW2 = n.gradients(X[:, 1:3], n.Y[:, 1:3])
print(dW1)
print("")
print(dW2)

In [ ]:
n.run(epochs=100)

In [ ]:
n.results

In [ ]:
sl = n.plot_square_loss()

In [ ]:
l01 = n.plot_01_loss()

In [ ]:
p1 = n.plot_sum_of_weights('W1')
p2 = n.plot_sum_of_weights('W2')

In [ ]:
n.feed_forward_and_predict_Y(n.X)

In [ ]:
n.predict_y(n.X)

In [ ]:
n.W1_tracking.tail()

In [ ]:
f = n.plot_weight_evolution()

In [ ]:
n.feed_forward(n.X)
dW1, dW2 = n.backprop(n.X, n.Y)
print(dW1)
print("")
print(dW2)

In [ ]:
dW1_num, dW2_num = n.numerical_derivatives()
print(dW1)
print(dW2)

In [ ]:
np.sum(np.abs(dW1 - dW1_num))

In [ ]:
np.sum(np.abs(dW2 - dW2_num))

In [ ]:
n.W1_tracking

In [ ]:
p = n.plot_sum_of_weights()

In [ ]:
n.W1_dot_prod_checking

In [ ]:
n.plot_sample_dot_prods()