view algorithms/_test_logistic_regression.py @ 519:b267a8000f92

Added theano.Member to Member variables which were passed in during initialization.
author Joseph Turian <turian@iro.umontreal.ca>
date Fri, 14 Nov 2008 02:07:20 -0500
parents c7ce66b4e8f4
children
line wrap: on
line source

from logistic_regression import *
import sys, time

if __name__ == '__main__':
    pprint.assign(nnet.crossentropy_softmax_1hot_with_bias_dx, printing.FunctionPrinter('xsoftmaxdx'))
    pprint.assign(nnet.crossentropy_softmax_argmax_1hot_with_bias, printing.FunctionPrinter('nll', 'softmax', 'argmax'))
    if 1:
        lrc = Module_Nclass()

        print '================'
        print lrc.update.pretty()
        print '================'
        print lrc.update.pretty(mode = theano.Mode('py', 'fast_run'))
        print '================'
#         print lrc.update.pretty(mode = compile.FAST_RUN.excluding('inplace'))
#         print '================'

#        sys.exit(0)

        lr = lrc.make(10, 2, mode=theano.Mode('c|py', 'fast_run'))
        #lr = lrc.make(10, 2, mode=compile.FAST_RUN.excluding('fast_run'))
        #lr = lrc.make(10, 2, mode=theano.Mode('py', 'merge')) #'FAST_RUN')

        data_x = N.random.randn(5, 10)
        data_y = (N.random.randn(5) > 0)

        t = time.time()
        for i in xrange(10000):
            lr.lr = 0.02
            xe = lr.update(data_x, data_y) 
            #if i % 100 == 0:
            #    print i, xe

        print 'training time:', time.time() - t
        print 'final error', xe

        #print
        #print 'TRAINED MODEL:'
        #print lr

    if 0:
        lrc = Module()

        lr = lrc.make(10, mode=theano.Mode('c|py', 'merge')) #'FAST_RUN')

        data_x = N.random.randn(5, 10)
        data_y = (N.random.randn(5, 1) > 0)

        for i in xrange(10000):
            xe = lr.update(data_x, data_y)
            if i % 100 == 0:
                print i, xe

        print
        print 'TRAINED MODEL:'
        print lr