<s> from __future__ import absolute_import , print_function , division <EOL> import numpy <EOL> import theano <EOL> import theano . tensor as tt <EOL> from theano import sandbox , Out <EOL> theano . config . floatX = '<STR_LIT>' <EOL> rng = numpy . random <EOL> N = <NUM_LIT> <EOL> feats = <NUM_LIT> <EOL> D = ( rng . randn ( N , feats ) . astype ( theano . config . floatX ) , <EOL> rng . randint ( size = N , low = <NUM_LIT:0> , high = <NUM_LIT:2> ) . astype ( theano . config . floatX ) ) <EOL> training_steps = <NUM_LIT> <EOL> x = theano . shared ( D [ <NUM_LIT:0> ] , name = "<STR_LIT:x>" ) <EOL> y = theano . shared ( D [ <NUM_LIT:1> ] , name = "<STR_LIT:y>" ) <EOL> w = theano . shared ( rng . randn ( feats ) . astype ( theano . config . floatX ) , name = "<STR_LIT:w>" ) <EOL> b = theano . shared ( numpy . asarray ( <NUM_LIT:0.> , dtype = theano . config . floatX ) , name = "<STR_LIT:b>" ) <EOL> x . tag . test_value = D [ <NUM_LIT:0> ] <EOL> y . tag . test_value = D [ <NUM_LIT:1> ] <EOL> p_1 = <NUM_LIT:1> / ( <NUM_LIT:1> + tt . exp ( - tt . dot ( x , w ) - b ) ) <EOL> prediction = p_1 > <NUM_LIT:0.5> <EOL> xent = - y * tt . log ( p_1 ) - ( <NUM_LIT:1> - y ) * tt . log ( <NUM_LIT:1> - p_1 ) <EOL> cost = tt . cast ( xent . mean ( ) , '<STR_LIT>' ) + <NUM_LIT> * ( w ** <NUM_LIT:2> ) . sum ( ) <EOL> gw , gb = tt . grad ( cost , [ w , b ] ) <EOL> """<STR_LIT>""" <EOL> train = theano . function ( <EOL> inputs = [ ] , <EOL> outputs = [ prediction , xent ] , <EOL> updates = { w : w - <NUM_LIT> * gw , b : b - <NUM_LIT> * gb } , <EOL> name = "<STR_LIT:train>" ) <EOL> predict = theano . function ( inputs = [ ] , outputs = prediction , <EOL> name = "<STR_LIT>" ) <EOL> if any ( [ x . op . __class__ . __name__ in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] for x in <EOL> train . maker . fgraph . toposort ( ) ] ) : <EOL> print ( '<STR_LIT>' ) <EOL> elif any ( [ x . op . __class__ . __name__ in [ '<STR_LIT>' , '<STR_LIT>' ] for x in <EOL> train . maker . fgraph . toposort ( ) ] ) : <EOL> print ( '<STR_LIT>' ) <EOL> else : <EOL> print ( '<STR_LIT>' ) <EOL> print ( train . maker . fgraph . toposort ( ) ) <EOL> for i in range ( training_steps ) : <EOL> pred , err = train ( ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( D [ <NUM_LIT:1> ] ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( predict ( ) ) <EOL> """<STR_LIT>""" </s>
