Skip to content

Commit dc6ace4

Browse files
authoredSep 23, 2017
from homebrew sigmoid() to scipy.special.expit()
1 parent 0c36383 commit dc6ace4

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed
 

‎main.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import numpy as np
2+
import scipy.special as sp
23
import matplotlib.pyplot as plt
34

4-
# import scipy.special as sp
5-
# scipy is broken in Windows PyCharm environment. Use np.exp instead.
6-
def sigmoid(x):
7-
return 1/(1+np.exp(-x))
8-
95
class NeuralNetwork:
106
def __init__(self, input_nodes, hidden_nodes, output_nodes, learning_rate):
117
# three layers
@@ -21,7 +17,8 @@ def __init__(self, input_nodes, hidden_nodes, output_nodes, learning_rate):
2117
self.who = np.random.normal(0.0, pow(self.onodes, -0.5), (self.onodes, self.hnodes))
2218

2319
# activation function - sigmoid
24-
self.activation_function = lambda x: sigmoid(x)
20+
# scipy.special.expit()
21+
self.activation_function = lambda x: sp.expit(x)
2522

2623
def train(self, inputs_list, targets_list):
2724
# same as query()
@@ -83,10 +80,13 @@ def query(self, inputs_list):
8380
query_input = test_data_list[np.random.randint(len(test_data_list))].split(',')
8481
scaled_query_input = (np.asfarray(query_input[1:])/255.0 * 0.99) + 0.01
8582

83+
digit = int(query_input[0])
8684
# show the digit
87-
print('Target digit: %s'%(query_input[0]))
85+
print('Target digit: %d'%(digit))
8886
# show the output
89-
print n.query(scaled_query_input)
87+
result = n.query(scaled_query_input)
88+
print result
89+
print result[digit][0] / np.sum(result)
9090

9191
# image_array = np.asfarray(scaled_query_input).reshape((28, 28))
9292
# plt.imshow(image_array, cmap='binary', interpolation='None')

0 commit comments

Comments
 (0)
Please sign in to comment.