neural net python sleep study -
neural net python sleep study -
import numpy as np
import matplotlib. pyplot as plt
# Normalize
X = X / np.amax(X, axis=0)
y = y / 100 # Max test score is 100
class Neural_Network(object):
def __init__(self):
# Define Hyperparameters
self.inputLayerSize = 2
self.outputLayerSize = 1
self.hiddenLayerSize = 3
# Weights (parameters)
self.W1 = np.random.randn(self.inputLayerSize, self.hiddenLayerSize)
self.W2 = np.random.randn(self.hiddenLayerSize, self.outputLayerSize)
for p in range(len(paramsInitial)):
# Set perturbation vector
perturb[p] = e
N.setParams(paramsInitial + perturb)
loss2 = N.costFunction(X, y)
N.setParams(paramsInitial - perturb)
loss1 = N.costFunction(X, y)
return numgrad
params0 = self.N.getParams()
self.N.setParams(_res.x)
self.optimizationResults = _res
print('_res = ',_res)
print(Neural_Network())
nn = Neural_Network()
tt= trainer(nn)
tt.train(X,y)
print("X= ",X)
print("y=",y)
Y2=nn.forward(X)
print("Y2=",Y2)
print("W1=", nn.W1)
print("W2=", nn.W2)
X= [[0.13, 1. ]]
Y2=nn.forward(X)
print("Y2=",Y2)
x = np.arange(-1.,1.00,.010)
Y2=nn.forward(X)
for x1 in x :
plt.plot(x1,nn.forward([x1,1]),'bo')
plt.plot(x1, nn.forward([x1, 0]),'go')
plt.plot(x1, nn.forward([x1, .5]), 'ro')
plt.show()