Skip to content

Commit 4af45b7

Browse files
qoocrabkkweon
authored andcommitted
Update lab-09-3-xor-nn-wide-deep.py (#238)
* Update lab-09-3-xor-nn-wide-deep.py Removed unnecessary codes. * Update lab-09-3-xor-nn-wide-deep.py Add numpy again. * Update lab-09-3-xor-nn-wide-deep.py Add numpy again. * Update lab-09-3-xor-nn-wide-deep.py Co-Authored-By: qoocrab <[email protected]> * Update lab-09-3-xor-nn-wide-deep.py Co-Authored-By: qoocrab <[email protected]>
1 parent c644f04 commit 4af45b7

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

lab-09-3-xor-nn-wide-deep.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,9 @@
33
import numpy as np
44

55
tf.set_random_seed(777) # for reproducibility
6-
learning_rate = 0.1
76

8-
x_data = [[0, 0],
9-
[0, 1],
10-
[1, 0],
11-
[1, 1]]
12-
y_data = [[0],
13-
[1],
14-
[1],
15-
[0]]
16-
x_data = np.array(x_data, dtype=np.float32)
17-
y_data = np.array(y_data, dtype=np.float32)
7+
x_data = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.float32)
8+
y_data = np.array([[0], [1], [1], [0]], dtype=np.float32)
189

1910
X = tf.placeholder(tf.float32, [None, 2])
2011
Y = tf.placeholder(tf.float32, [None, 1])
@@ -36,10 +27,8 @@
3627
hypothesis = tf.sigmoid(tf.matmul(layer3, W4) + b4)
3728

3829
# cost/loss function
39-
cost = -tf.reduce_mean(Y * tf.log(hypothesis) + (1 - Y) *
40-
tf.log(1 - hypothesis))
41-
42-
train = tf.train.GradientDescentOptimizer(learning_rate=learning_rate).minimize(cost)
30+
cost = -tf.reduce_mean(Y * tf.log(hypothesis) + (1 - Y) * tf.log(1 - hypothesis))
31+
train = tf.train.GradientDescentOptimizer(learning_rate=0.1).minimize(cost)
4332

4433
# Accuracy computation
4534
# True if hypothesis>0.5 else False
@@ -52,14 +41,14 @@
5241
sess.run(tf.global_variables_initializer())
5342

5443
for step in range(10001):
55-
sess.run(train, feed_dict={X: x_data, Y: y_data})
44+
_, cost_val = sess.run([train, cost], feed_dict={X: x_data, Y: y_data})
5645
if step % 100 == 0:
57-
print(step, sess.run(cost, feed_dict={
58-
X: x_data, Y: y_data}), sess.run([W1, W2]))
46+
print(step, cost_val)
5947

6048
# Accuracy report
61-
h, c, a = sess.run([hypothesis, predicted, accuracy],
62-
feed_dict={X: x_data, Y: y_data})
49+
h, c, a = sess.run(
50+
[hypothesis, predicted, accuracy], feed_dict={X: x_data, Y: y_data}
51+
)
6352
print("\nHypothesis: ", h, "\nCorrect: ", c, "\nAccuracy: ", a)
6453

6554

0 commit comments

Comments
 (0)