5
5
import time
6
6
7
7
8
- def make_neural_network (layer_sizes , layer_activations , learning_rate = 0.2 , low = - 2 , high = 2 ):
8
+ def make_neural_network (layer_sizes , layer_activations , learning_rate = 0.05 , low = - 2 , high = 2 ):
9
9
10
10
# Initialize typed layer sizes list.
11
11
typed_layer_sizes = typed .List ()
@@ -118,6 +118,18 @@ def train(self, test_input_data, test_desired_output_data, validate_input_data,
118
118
current_mse = self .calculate_MSE (validate_input_data , validate_output_data )
119
119
return epochs , current_mse
120
120
121
+ def evaluate (self , input_data , desired_output_data ):
122
+ corrects , wrongs = 0 , 0
123
+ for i in range (len (input_data )):
124
+ output = self .calculate_output (input_data [i ])
125
+ output_max = output .argmax ()
126
+ desired_output_max = desired_output_data [i ].argmax ()
127
+ if output_max == desired_output_max :
128
+ corrects += 1
129
+ else :
130
+ wrongs += 1
131
+ return corrects / (corrects + wrongs )
132
+
121
133
def print_weights_and_biases (self ):
122
134
print (self .weights )
123
135
print (self .biases )
@@ -135,7 +147,7 @@ def print_weights_and_biases(self):
135
147
end_time = time .time_ns ()
136
148
print ("Compile time:" , (end_time - begin_time ) / 1e9 )
137
149
138
- for i in range (3 ):
150
+ for i in range (10 ):
139
151
140
152
random_seed = np .random .randint (10 , 1010 )
141
153
np .random .seed (random_seed )
@@ -151,4 +163,6 @@ def print_weights_and_biases(self):
151
163
152
164
train_mse = nn .calculate_MSE (train_input , train_output )
153
165
test_mse = nn .calculate_MSE (test_input , test_output )
154
- print ("Seed:" , random_seed , "Epochs:" , epochs , "Time:" , (end_time - begin_time )/ 1e9 , "Tr:" , train_mse , "V:" , current_mse , "T:" , test_mse )
166
+
167
+ accuracy_test = nn .evaluate (test_input , test_output )
168
+ print ("Seed:" , random_seed , "Epochs:" , epochs , "Time:" , (end_time - begin_time )/ 1e9 , "Accuracy:" , accuracy_test , "Tr:" , train_mse , "V:" , current_mse , "T:" , test_mse )
0 commit comments