Skip to content

Commit b5ee3ad

Browse files
committed
Reparameterizing the weight initialization results
1 parent 07e1389 commit b5ee3ad

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

fig/weight_initialization.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# Standard library
1313
import json
14+
import random
1415
import sys
1516

1617
# My library
@@ -22,32 +23,31 @@
2223
import matplotlib.pyplot as plt
2324
import numpy as np
2425

25-
# Make results more easily reproducible
26-
import random
27-
random.seed(12345678)
28-
29-
def main(filename):
30-
run_network(filename)
26+
def main(filename, n, eta):
27+
run_network(filename, n, eta)
3128
make_plot(filename)
3229

33-
def run_network(filename):
30+
def run_network(filename, n, eta):
3431
"""Train the network using both the default and the large starting
3532
weights. Store the results in the file with name ``filename``,
3633
where they can later be used by ``make_plots``.
3734
3835
"""
36+
# Make results more easily reproducible
37+
random.seed(12345678)
38+
np.random.seed(12345678)
3939
training_data, validation_data, test_data = mnist_loader.load_data_wrapper()
40-
net = network2.Network([784, 30, 10], cost=network2.CrossEntropyCost())
40+
net = network2.Network([784, n, 10], cost=network2.CrossEntropyCost)
4141
print "Train the network using the default starting weights."
4242
default_vc, default_va, default_tc, default_ta \
43-
= net.SGD(training_data, 30, 10, 0.01,
44-
evaluation_data=validation_data, lmbda = 0.001,
43+
= net.SGD(training_data, 30, 10, eta, lmbda=5.0,
44+
evaluation_data=validation_data,
4545
monitor_evaluation_accuracy=True)
4646
print "Train the network using the large starting weights."
4747
net.large_weight_initializer()
4848
large_vc, large_va, large_tc, large_ta \
49-
= net.SGD(training_data, 30, 10, 0.01,
50-
evaluation_data=validation_data, lmbda = 0.001,
49+
= net.SGD(training_data, 30, 10, eta, lmbda=5.0,
50+
evaluation_data=validation_data,
5151
monitor_evaluation_accuracy=True)
5252
f = open(filename, "w")
5353
json.dump({"default_weight_initialization":

fig/weight_initialization_100.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"default_weight_initialization": [[], [9549, 9694, 9682, 9693, 9738, 9738, 9740, 9742, 9770, 9747, 9743, 9756, 9745, 9749, 9744, 9747, 9726, 9764, 9778, 9773, 9742, 9773, 9770, 9761, 9771, 9776, 9779, 9742, 9759, 9777], [], []], "large_weight_initialization": [[], [9373, 9501, 9583, 9648, 9694, 9705, 9628, 9710, 9717, 9734, 9749, 9710, 9710, 9759, 9727, 9740, 9731, 9773, 9742, 9755, 9766, 9761, 9763, 9778, 9736, 9736, 9735, 9751, 9750, 9740], [], []]}
1+
{"default_weight_initialization": [[], [9295, 9481, 9547, 9592, 9664, 9673, 9702, 9719, 9726, 9726, 9732, 9732, 9730, 9734, 9745, 9751, 9757, 9761, 9764, 9766, 9758, 9767, 9756, 9752, 9777, 9775, 9770, 9770, 9771, 9781], [], []], "large_weight_initialization": [[], [8994, 9181, 9260, 9364, 9427, 9449, 9497, 9512, 9560, 9578, 9603, 9616, 9626, 9629, 9644, 9671, 9674, 9679, 9700, 9708, 9707, 9717, 9729, 9720, 9719, 9745, 9751, 9754, 9755, 9742], [], []]}

fig/weight_initialization_100.png

554 Bytes
Loading

fig/weight_initialization_30.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"default_weight_initialization": [[], [9284, 9395, 9440, 9481, 9527, 9548, 9552, 9560, 9567, 9580, 9604, 9589, 9590, 9595, 9602, 9603, 9612, 9615, 9616, 9625, 9626, 9628, 9622, 9618, 9639, 9628, 9630, 9615, 9633, 9632], [], []], "large_weight_initialization": [[], [8672, 8982, 9147, 9254, 9306, 9362, 9381, 9409, 9463, 9463, 9493, 9503, 9509, 9535, 9512, 9540, 9571, 9567, 9575, 9594, 9607, 9609, 9600, 9609, 9615, 9613, 9645, 9616, 9635, 9605], [], []]}
1+
{"default_weight_initialization": [[], [9270, 9414, 9470, 9504, 9537, 9550, 9587, 9594, 9596, 9594, 9616, 9595, 9622, 9630, 9636, 9641, 9625, 9652, 9637, 9634, 9642, 9639, 9649, 9646, 9646, 9653, 9646, 9653, 9640, 9650], [], []], "large_weight_initialization": [[], [8643, 9044, 9141, 9231, 9299, 9327, 9385, 9416, 9433, 9449, 9476, 9489, 9500, 9535, 9521, 9548, 9564, 9573, 9585, 9592, 9596, 9615, 9607, 9605, 9606, 9622, 9637, 9648, 9635, 9637], [], []]}

fig/weight_initialization_30.png

603 Bytes
Loading

0 commit comments

Comments
 (0)