view pylearn/algorithms/tests/test_regressor.py @ 1506:2f69c9932d9a

Fix test in float32.
author Frederic Bastien <nouiz@nouiz.org>
date Mon, 12 Sep 2011 10:56:38 -0400
parents f7957524f76e
children
line wrap: on
line source


import pylearn.algorithms.regressor as models
import theano
import numpy
import time


def test_train(mode = theano.Mode('c|py', 'fast_run')):

    reg = models.BinRegressor(regularize = False)

    model = reg.make(lr = 0.01,
                     input_size = 100,
                     mode = mode,
                     seed = 10)

#     data = [[0, 1, 0, 0, 1, 1, 1, 0, 1, 0]*10]*10
#     targets = [[1]]*10
    #data = numpy.random.rand(10, 100)

    R = numpy.random.RandomState(100)
    t1 = time.time()
    for i in xrange(1001):
        data = R.random_integers(0, 1, size = (10, 100)).astype(theano.config.floatX)
        targets = data[:, 6].reshape((10, 1))
        cost = model.update(data, targets)
        if i % 100 == 0:
            print i, '\t', cost, '\t', 1*(targets.T == model.classify(data).T)
    t2 = time.time()
    return t2 - t1

if __name__ == '__main__':
    print 'optimized:'
    t1 = test_train(theano.Mode('c|py', 'fast_run'))
    print 'time:',t1
    print

    print 'not optimized:'
    t2 = test_train(theano.Mode('c|py', 'fast_compile'))
    print 'time:',t2