diff sandbox/simple_autoassociator/model.py @ 416:8849eba55520

Can now do minibatch update
author Joseph Turian <turian@iro.umontreal.ca>
date Fri, 11 Jul 2008 16:34:46 -0400
parents faffaae0d2f9
children 4f61201fa9a9
line wrap: on
line diff
--- a/sandbox/simple_autoassociator/model.py	Fri Jul 11 15:33:27 2008 -0400
+++ b/sandbox/simple_autoassociator/model.py	Fri Jul 11 16:34:46 2008 -0400
@@ -13,20 +13,26 @@
 import random
 random.seed(globals.SEED)
 
+import pylearn.sparse_instance
+
 class Model:
     def __init__(self):
         self.parameters = parameters.Parameters(randomly_initialize=True)
 
-    def update(self, instance):
+#    def deterministic_reconstruction(self, x):
+#        (y, h, loss, gw1, gb1, gw2, gb2) = trainfn(x, self.parameters.w1, self.parameters.b1, self.parameters.w2, self.parameters.b2)
+#        return y
+
+    def update(self, instances):
         """
         Update the L{Model} using one training instance.
-        @param instance: A dict from feature index to (non-zero) value.
+        @param instances: A list of dict from feature index to (non-zero) value.
         @todo: Should assert that nonzero_indices and zero_indices
         are correct (i.e. are truly nonzero/zero).
         """
-        x = numpy.zeros(globals.INPUT_DIMENSION)
-        for idx in instance.keys():
-            x[idx] = instance[idx]
+        minibatch = len(instances)
+#        x = pylearn.sparse_instance.to_vector(instances, self.input_dimension)
+        x = pylearn.sparse_instance.to_vector(instances, globals.INPUT_DIMENSION)
 
         (y, h, loss, gw1, gb1, gw2, gb2) = trainfn(x, self.parameters.w1, self.parameters.b1, self.parameters.w2, self.parameters.b2)
 #        print