Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
!pip install jovian --upgrade --quiet
import numpy as np
z = np.array(([1,2], [3, 4], [5, 6]), dtype=float)
y = np.array(([12], [22], [32]), dtype=float)
z = z/np.amax(z,axis=0)
y = y/100
def sig(x):
return 1/(1 + np.exp(-x))
def sign(x):
return x * (1 - x)
a=1000
b =0.2
c = 2
d = 3
e = 1
wh=np.random.uniform(size=(c,d))
bh=np.random.uniform(size=(1,d))
wout=np.random.uniform(size=(d,e))
bout=np.random.uniform(size=(1,e))
for i in range(a):
h_ip=np.dot(z,wh) + bh
h_act = sig(h_ip)
o_ip=np.dot(h_act,wout) + bout
output = sig(o_ip)
f = y-output
g = sign(output)
d_output = f*g
eh = d_output.dot(wout.T)
hg = sign(h_act)
d_hidden = eh * hg
wout += h_act.T.dot(d_output) *b
wh += z.T.dot(d_hidden) *b
print("Normalized Input: \n" + str(z))
print("Actual Output: \n" + str(y))
print("Predicted Output: \n" ,output)
Normalized Input:
[[0.2 0.33333333]
[0.6 0.66666667]
[1. 1. ]]
Actual Output:
[[0.12]
[0.22]
[0.32]]
Predicted Output:
[[0.23813895]
[0.22128582]
[0.20710105]]
jovian.commit('ml-lab-program-4')