annotate test_mlp.py @ 183:25d0a0c713da

did some debugging of test_mlp
author Olivier Breuleux <breuleuo@iro.umontreal.ca>
date Tue, 13 May 2008 18:30:08 -0400
parents 2698c0feeb54
children 562f308873f0
rev   line source
121
2ca8dccba270 debugging mlp.py
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff changeset
1
2ca8dccba270 debugging mlp.py
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff changeset
2 from mlp import *
133
b4657441dd65 Corrected typos
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 121
diff changeset
3 import dataset
121
2ca8dccba270 debugging mlp.py
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff changeset
4
183
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
5
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
6 from functools import partial
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
7 def separator(debugger, i, node, *ths):
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
8 print "==================="
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
9
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
10 def what(debugger, i, node, *ths):
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
11 print "#%i" % i, node
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
12
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
13 def parents(debugger, i, node, *ths):
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
14 print [input.step for input in node.inputs]
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
15
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
16 def input_shapes(debugger, i, node, *ths):
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
17 print "input shapes: ",
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
18 for r in node.inputs:
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
19 if hasattr(r.value, 'shape'):
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
20 print r.value.shape,
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
21 else:
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
22 print "no_shape",
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
23 print
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
24
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
25 def input_types(debugger, i, node, *ths):
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
26 print "input types: ",
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
27 for r in node.inputs:
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
28 print r.type,
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
29 print
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
30
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
31 def output_shapes(debugger, i, node, *ths):
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
32 print "output shapes:",
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
33 for r in node.outputs:
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
34 if hasattr(r.value, 'shape'):
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
35 print r.value.shape,
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
36 else:
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
37 print "no_shape",
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
38 print
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
39
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
40 def output_types(debugger, i, node, *ths):
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
41 print "output types:",
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
42 for r in node.outputs:
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
43 print r.type,
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
44 print
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
45
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
46
121
2ca8dccba270 debugging mlp.py
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff changeset
47 def test0():
183
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
48 linker = 'c|py'
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
49 #linker = partial(theano.gof.DebugLinker, linkers = [theano.gof.OpWiseCLinker],
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
50 # debug_pre = [separator, what, parents, input_types, input_shapes],
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
51 # debug_post = [output_shapes, output_types],
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
52 # compare_fn = lambda x, y: numpy.all(x == y))
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
53
25d0a0c713da did some debugging of test_mlp
Olivier Breuleux <breuleuo@iro.umontreal.ca>
parents: 180
diff changeset
54 nnet = OneHiddenLayerNNetClassifier(10,2,.001,1000, linker = linker)
133
b4657441dd65 Corrected typos
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 121
diff changeset
55 training_set = dataset.ArrayDataSet(numpy.array([[0, 0, 0],
b4657441dd65 Corrected typos
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 121
diff changeset
56 [0, 1, 1],
b4657441dd65 Corrected typos
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 121
diff changeset
57 [1, 0, 1],
b4657441dd65 Corrected typos
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 121
diff changeset
58 [1, 1, 1]]),
b4657441dd65 Corrected typos
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 121
diff changeset
59 {'input':slice(2),'target':2})
b4657441dd65 Corrected typos
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 121
diff changeset
60 fprop=nnet(training_set)
121
2ca8dccba270 debugging mlp.py
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff changeset
61
135
0d8e721cc63c Fixed bugs in dataset to make test_mlp.py work
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 133
diff changeset
62 output_ds = fprop(training_set)
0d8e721cc63c Fixed bugs in dataset to make test_mlp.py work
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 133
diff changeset
63
0d8e721cc63c Fixed bugs in dataset to make test_mlp.py work
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 133
diff changeset
64 for fieldname in output_ds.fieldNames():
0d8e721cc63c Fixed bugs in dataset to make test_mlp.py work
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents: 133
diff changeset
65 print fieldname+"=",output_ds[fieldname]
121
2ca8dccba270 debugging mlp.py
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff changeset
66
2ca8dccba270 debugging mlp.py
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff changeset
67 test0()
2ca8dccba270 debugging mlp.py
Yoshua Bengio <bengioy@iro.umontreal.ca>
parents:
diff changeset
68