<s> from __future__ import absolute_import , print_function , division <EOL> import numpy as N <EOL> import sys <EOL> import time <EOL> from six . moves import xrange <EOL> neg , nout , nhid , niter = [ int ( a ) for a in sys . argv [ <NUM_LIT:1> : ] ] <EOL> lr = <NUM_LIT> <EOL> rng = N . random . RandomState ( <NUM_LIT> ) <EOL> w = rng . rand ( nout , nhid ) <EOL> a = rng . randn ( nhid ) * <NUM_LIT:0.0> <EOL> b = rng . randn ( nout ) * <NUM_LIT:0.0> <EOL> x = ( rng . rand ( neg , nout ) - <NUM_LIT:0.5> ) * <NUM_LIT> <EOL> dot_time = <NUM_LIT:0.0> <EOL> t = time . time ( ) <EOL> for i in xrange ( niter ) : <EOL> tt = time . time ( ) <EOL> d = N . dot ( x , w ) <EOL> dot_time += time . time ( ) - tt <EOL> hid = N . tanh ( d + a ) <EOL> tt = time . time ( ) <EOL> d = N . dot ( hid , w . T ) <EOL> dot_time += time . time ( ) - tt <EOL> out = N . tanh ( d + b ) <EOL> g_out = out - x <EOL> err = <NUM_LIT:0.5> * N . sum ( g_out ** <NUM_LIT:2> ) <EOL> g_hidwt = g_out * ( <NUM_LIT:1.0> - out ** <NUM_LIT:2> ) <EOL> b -= lr * N . sum ( g_hidwt , axis = <NUM_LIT:0> ) <EOL> tt = time . time ( ) <EOL> g_hid = N . dot ( g_hidwt , w ) <EOL> dot_time += time . time ( ) - tt <EOL> g_hidin = g_hid * ( <NUM_LIT:1.0> - hid ** <NUM_LIT:2> ) <EOL> tt = time . time ( ) <EOL> d = N . dot ( g_hidwt . T , hid ) <EOL> dd = N . dot ( x . T , g_hidin ) <EOL> dot_time += time . time ( ) - tt <EOL> gw = ( d + dd ) <EOL> w -= lr * gw <EOL> a -= lr * N . sum ( g_hidin , axis = <NUM_LIT:0> ) <EOL> total_time = time . time ( ) - t <EOL> print ( '<STR_LIT>' , total_time , '<STR_LIT>' , err ) <EOL> print ( '<STR_LIT>' , dot_time , '<STR_LIT>' , dot_time / total_time ) </s>
