26 lines
980 B
Python
26 lines
980 B
Python
import numpy as np
|
|
|
|
|
|
class Neural_Network(object):
|
|
# inspired from https://enlight.nyc/projects/neural-network/
|
|
def __init__(self):
|
|
#parameters
|
|
self.inputSize = 3
|
|
self.outputSize = 2
|
|
self.hiddenSize = 3
|
|
|
|
#weights
|
|
self.W1 = np.random.randn(self.inputSize, self.hiddenSize) # weights from input to hidden layer
|
|
self.W2 = np.random.randn(self.hiddenSize, self.outputSize) # weights from hidden to output layer
|
|
|
|
def predict(self, X):
|
|
#forward propagation through our network
|
|
self.z = np.dot(X, self.W1) # dot product of X (input) and first set of 3x2 weights
|
|
self.z2 = self.sigmoid(self.z) # activation function
|
|
self.z3 = np.dot(self.z2, self.W2) # dot product of hidden layer (z2) and second set of 3x1 weights
|
|
o = self.sigmoid(self.z3) # final activation function
|
|
return o
|
|
|
|
def sigmoid(self, s):
|
|
# activation function
|
|
return 1/(1+np.exp(-s)) -0.5 |