NN XoR FP

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

In [4]: ​

import matplotlib.pyplot as plt


import numpy as np
%matplotlib inline
#np.numpy_boxes.ArrayBox.__repr__ = lambda self: str(self._value)

In [5]: X = np.array([[0, 0],


[0, 1],
[1, 0],
[1, 1]
])

y = np.array([[0], [1], [1], [0]])

In [6]: X.shape, y.shape

Out[6]: ((4, 2), (4, 1))

In [7]: N, N_0 = X.shape


N, N_2 = y.shape
N_1 = 2

In [8]: W = [np.array([0]), np.array([[1, 1], [1, 1]]), np.array([[1, -2]])]



b = [np.array([0]), np.array([[0], [-1]]), np.array([[0]])]
B = []

In [9]: A = [X]
A.extend([None]*(len(W)-1))
Z = [None]*(len(W))

In [10]: def relu(z):


temp = z.copy()
temp[temp<0] = 0
return temp

def sigmoid(z):
return 1./(1+np.exp(-z))

In [11]: for i in range(1, len(W)):


Z[i] = A[i-1]@(W[i].T) + b[i].T
A[i] =relu(Z[i])

In [12]: A[2]==y

Out[12]: array([[ True],


[ True],
[ True],
[ True]])

You might also like