In [4]:
import math
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [5]:
# Layer 1:
print("Layer 1:")
x1 = np.array([1,2.00,0.26]) #Inputs
print("X1=", x1)
# Layer 2:
print("Layer 2:")
w12 = np.array([[-0.18,-0.16,-0.03,-0.15],
[0.166,-0.18,0.01,-0.06],
[0.14,-0.14,-0.065,-0.06]])
print("W12 =", w12)
In [6]:
z2 = x1.dot(w12) # z2 = [x1].[w12]
print("Y2 =", z2)
a2 = 1/(1+np.exp(-z2)) # a2 = f(z2) where f = sigmoid fn
print("A2 =", a2)
# Layer 3:
print("Layer 3:")
w23 = np.array([-1.01,-1.99,-0.25,-1.64]).T
print("W23 =", w23)
z3 = a2.dot(w23) # z3 = [a2].[w23]
print("Z3 =", z3)
a3 = 1/(1+np.exp(-z3)) # a3 = f(z3)
yhat = a3
y = 1
print("h(x) =", yhat)
print("e =", (y-yhat))
In [7]:
# Layer 1:
print("Layer 1:")
x2 = np.array([1,2.00,0.26]) #Inputs
print("X1=", x2)
# Layer 2:
print("Layer 2:")
w2_12 = np.array([[12.70,-0.20,-0.74,-0.19],
[-1.49,-8.85,7.08,-8.29],
[-19.85,-2.61,-3.59,-2.70]])
print("W12 =", w2_12)
z2_2 = x2.dot(w2_12) # z2 = [x1].[w12]
print("Y2 =", z2_2)
a2_2 = 1/(1+np.exp(-z2_2)) # a2 = f(z2) where f = sigmoid fn
print("A2 =", a2_2)
# Layer 3:
print("Layer 3")
w2_23 = np.array([7.44,2.78,-4.31,2.70]).T
print("W23 =", w2_23)
z2_3 = a2_2.dot(w2_23) # z3 = [a2].[w23]
print("Z3 =", z2_3)
a2_3 = 1/(1+np.exp(-z2_3)) # a3 = f(z3)
yhat2 = a2_3
print("h(x) =", yhat2)
print("e =", (y-yhat2))