Mercurial > pylearn
comparison algorithms/stacker.py @ 516:2b0e10ac6929
misc
author | Olivier Breuleux <breuleuo@iro.umontreal.ca> |
---|---|
date | Mon, 03 Nov 2008 00:10:18 -0500 |
parents | c7ce66b4e8f4 |
children |
comparison
equal
deleted
inserted
replaced
515:dc2d93590da0 | 516:2b0e10ac6929 |
---|---|
1 | |
2 # for example in examples: | |
3 # repr = example | |
4 # for layer in stacked.layers: | |
5 # layer.update(repr) | |
6 # repr = layer.representation(repr) | |
1 | 7 |
2 import theano | 8 import theano |
3 from theano import tensor as T | 9 from theano import tensor as T |
4 import sys | 10 import sys |
5 import numpy as N | 11 import numpy as N |
22 self.layers = layers | 28 self.layers = layers |
23 | 29 |
24 self.input = self.layers[0].input | 30 self.input = self.layers[0].input |
25 self.output = current | 31 self.output = current |
26 | 32 |
33 representation = [] | |
27 local_update = [] | 34 local_update = [] |
28 global_update = [] | 35 global_update = [] |
29 to_update = [] | 36 to_update = [] |
30 all_kits = [] | 37 all_kits = [] |
31 for layer in layers: | 38 for layer, (submodule, outname) in zip(layers, submodules): |
32 u = layer.update | 39 u = layer.update |
33 u.resolve_all() | 40 u.resolve_all() |
34 to_update += u.updates.keys() | 41 to_update += u.updates.keys() |
35 all_kits += u.kits | 42 all_kits += u.kits |
36 # the input is the whole deep model's input instead of the layer's own | 43 # the input is the whole deep model's input instead of the layer's own |
44 # we update the params of the previous layers too but wrt | 51 # we update the params of the previous layers too but wrt |
45 # this layer's cost | 52 # this layer's cost |
46 dict((param, param - layer.lr * T.grad(layer.cost, param)) | 53 dict((param, param - layer.lr * T.grad(layer.cost, param)) |
47 for param in to_update), | 54 for param in to_update), |
48 list(all_kits))) | 55 list(all_kits))) |
56 representation.append(theano.Method(self.input, layer[outname])) | |
49 | 57 |
50 # @todo: Add diagnostics | 58 # @todo: Add diagnostics |
51 # self.diagnose_from_input = Method([self.input], self.layers[0].diagnose.outputs + self.layers[1].diagnose.outputs ... | 59 # self.diagnose_from_input = Method([self.input], self.layers[0].diagnose.outputs + self.layers[1].diagnose.outputs ... |
52 | 60 |
53 self.local_update = local_update | 61 self.local_update = local_update |
54 self.global_update = global_update | 62 self.global_update = global_update |
63 self.representation = representation | |
55 self.update = self.global_update[-1] | 64 self.update = self.global_update[-1] |
56 self.compute = theano.Method(self.input, self.output) | 65 self.compute = theano.Method(self.input, self.output) |
57 ll = self.layers[-1] | 66 ll = self.layers[-1] |
58 for name, method in ll.components_map(): | 67 for name, method in ll.components_map(): |
59 if isinstance(method, theano.Method) and not hasattr(self, name): | 68 if isinstance(method, theano.Method) and not hasattr(self, name): |