# HG changeset patch # User Joseph Turian # Date 1215808486 14400 # Node ID 8849eba5552051c9fb65a37c636d5305509f8d7c # Parent 319bf28c2dd5c8f4b09b94da8f1411aa51dacce3 Can now do minibatch update diff -r 319bf28c2dd5 -r 8849eba55520 sandbox/simple_autoassociator/globals.py --- a/sandbox/simple_autoassociator/globals.py Fri Jul 11 15:33:27 2008 -0400 +++ b/sandbox/simple_autoassociator/globals.py Fri Jul 11 16:34:46 2008 -0400 @@ -2,11 +2,11 @@ Global variables. """ -#INPUT_DIMENSION = 1000 +INPUT_DIMENSION = 1000 #INPUT_DIMENSION = 100 -INPUT_DIMENSION = 4 -#HIDDEN_DIMENSION = 10 -HIDDEN_DIMENSION = 1 +#INPUT_DIMENSION = 4 +HIDDEN_DIMENSION = 10 +#HIDDEN_DIMENSION = 1 LEARNING_RATE = 0.1 LR = LEARNING_RATE SEED = 666 diff -r 319bf28c2dd5 -r 8849eba55520 sandbox/simple_autoassociator/graph.py --- a/sandbox/simple_autoassociator/graph.py Fri Jul 11 15:33:27 2008 -0400 +++ b/sandbox/simple_autoassociator/graph.py Fri Jul 11 16:34:46 2008 -0400 @@ -6,7 +6,7 @@ from pylearn.nnet_ops import sigmoid, binary_crossentropy from theano import tensor as t from theano.tensor import dot -x = t.dvector() +x = t.dmatrix() w1 = t.dmatrix() b1 = t.dvector() w2 = t.dmatrix() diff -r 319bf28c2dd5 -r 8849eba55520 sandbox/simple_autoassociator/main.py --- a/sandbox/simple_autoassociator/main.py Fri Jul 11 15:33:27 2008 -0400 +++ b/sandbox/simple_autoassociator/main.py Fri Jul 11 16:34:46 2008 -0400 @@ -7,9 +7,6 @@ y = sigmoid(dot(h, w2) + b2) Binary xent loss. - - LIMITATIONS: - - Only does pure stochastic gradient (batchsize = 1). """ @@ -27,8 +24,8 @@ model = model.Model() for i in xrange(100000): - # Select an instance - instance = nonzero_instances[i % len(nonzero_instances)] +# # Select an instance +# instance = nonzero_instances[i % len(nonzero_instances)] - # SGD update over instance - model.update(instance) + # Update over instance + model.update(nonzero_instances) diff -r 319bf28c2dd5 -r 8849eba55520 sandbox/simple_autoassociator/model.py --- 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