forked from njblur/mini_neural
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcage.py
34 lines (28 loc) · 830 Bytes
/
cage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import sys
import numpy as np
from neural import *
heads = 18
legs = 50
if(len(sys.argv)==3):
heads = int(sys.argv[1])
legs = int(sys.argv[2])
n = network("square",learning_rate=0.3)
l = layer(2,2,"liner",bias_rate=0.0)
l2 = layer(2,1,"liner",bias_rate=0.0)
# n.add_layer(l)
n.add_layer(l2)
x1 = np.array([[1,2],[1,4]]).reshape(2,-1)
y1 = np.array([[heads],[legs]]).reshape(1,-1)
# x2 = np.array([[2,4]]).reshape(2,-1)
# y2 = np.array([legs]).reshape(1,-1)
for _ in range(2500):
# loss1 = n.learn(x2,y2)
loss2 = n.learn(x1,y1)
loss = (loss2)
n.set_learning_rate(n.learning_rate*0.8)
if(loss<0.1):
break
# loss = n.learn(x,y)
print loss
print "{} heads with {} legs ".format(heads,legs)
print "there are {} chicken {} rabbits,maybe, we guess ".format (l2.weights[0,0],l2.weights[0,1])