<s> from __future__ import absolute_import , print_function , division <EOL> import unittest <EOL> import numpy <EOL> import numpy . random <EOL> import theano <EOL> from theano . tests import unittest_tools as utt <EOL> '''<STR_LIT>''' <EOL> class T_scipy ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> utt . seed_rng ( ) <EOL> self . orig_floatX = theano . config . floatX <EOL> def tearDown ( self ) : <EOL> theano . config . floatX = self . orig_floatX <EOL> def test_scipy_paper_example1 ( self ) : <EOL> a = theano . tensor . vector ( '<STR_LIT:a>' ) <EOL> b = a + a ** <NUM_LIT:10> <EOL> f = theano . function ( [ a ] , b ) <EOL> assert numpy . all ( f ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] ) == numpy . array ( [ <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT> ] ) ) <EOL> def test_scipy_paper_example2 ( self ) : <EOL> '''<STR_LIT>''' <EOL> T = theano . tensor <EOL> shared = theano . shared <EOL> function = theano . function <EOL> rng = numpy . random <EOL> theano . config . floatX = '<STR_LIT>' <EOL> x = T . matrix ( ) <EOL> y = T . vector ( ) <EOL> w = shared ( rng . randn ( <NUM_LIT:100> ) ) <EOL> b = shared ( numpy . zeros ( ( ) ) ) <EOL> p_1 = <NUM_LIT:1> / ( <NUM_LIT:1> + T . exp ( - T . dot ( x , w ) - b ) ) <EOL> xent = - y * T . log ( p_1 ) - ( <NUM_LIT:1> - y ) * T . log ( <NUM_LIT:1> - p_1 ) <EOL> prediction = p_1 > <NUM_LIT:0.5> <EOL> cost = xent . mean ( ) + <NUM_LIT> * ( w ** <NUM_LIT:2> ) . sum ( ) <EOL> gw , gb = T . grad ( cost , [ w , b ] ) <EOL> train = function ( <EOL> inputs = [ x , y ] , <EOL> outputs = [ prediction , xent ] , <EOL> updates = [ ( w , w - <NUM_LIT:0.1> * gw ) , ( b , b - <NUM_LIT:0.1> * gb ) ] ) <EOL> function ( inputs = [ x ] , outputs = prediction ) <EOL> N = <NUM_LIT:4> <EOL> feats = <NUM_LIT:100> <EOL> D = ( rng . randn ( N , feats ) , rng . randint ( size = <NUM_LIT:4> , low = <NUM_LIT:0> , high = <NUM_LIT:2> ) ) <EOL> training_steps = <NUM_LIT:10> <EOL> for i in range ( training_steps ) : <EOL> pred , err = train ( D [ <NUM_LIT:0> ] , D [ <NUM_LIT:1> ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
