def __init__(self): self.mnist = MNIST.full() # first_10k() datasets = load_data(dataset) train_set_x, train_set_y = datasets[0] test_set_x, test_set_y = datasets[2] batch_size = 100 # size of the minibatch # compute number of minibatches for training, validation and testing n_train_batches = train_set_x.value.shape[0] / batch_size # allocate symbolic variables for the data index = T.lscalar() # index to a [mini]batch x = T.matrix("x") # the data is presented as rasterized images rng = numpy.random.RandomState(123) theano_rng = RandomStreams(rng.randint(2 ** 30)) # initialize storage fot the persistent chain (state = hidden layer of chain) persistent_chain = theano.shared(numpy.zeros((batch_size, 500))) # construct the RBM class self.rbm = RBM(input=x, n_visible=28 * 28, n_hidden=500, numpy_rng=rng, theano_rng=theano_rng) # get the cost and the gradient corresponding to one step of CD self.init_series()
def __init__(self, state): self.state = state if TEST_CONFIG: self.mnist = MNIST.first_1k() print "Test config, so loaded MNIST first 1000" else: self.mnist = MNIST.full()#first_10k() print "Loaded MNIST full" self.cp = ConvolutionParams( \ num_filters=state.num_filters, num_input_planes=1, height_filters=state.filter_size, width_filters=state.filter_size) self.image_size = (28,28) self.minibatch_size = state.minibatch_size self.lr = state.learning_rate self.sparsity_lambda = state.sparsity_lambda # about 1/num_filters, so only one filter active at a time # 40 * 0.05 = ~2 filters active for any given pixel self.sparsity_p = state.sparsity_p self.crbm = CRBM( \ minibatch_size=self.minibatch_size, image_size=self.image_size, conv_params=self.cp, learning_rate=self.lr, sparsity_lambda=self.sparsity_lambda, sparsity_p=self.sparsity_p) self.num_epochs = state.num_epochs self.init_series()