<s> import os <EOL> import sys <EOL> import numpy as np <EOL> import pydeep <EOL> import pydeep . neural <EOL> import pylab <EOL> import pydeep . utils <EOL> import pydeep . utils . utils <EOL> mnist_dir = os . path . join ( os . environ [ '<STR_LIT>' ] , '<STR_LIT>' , '<STR_LIT>' ) <EOL> mnist_train_path = os . path . join ( mnist_dir , '<STR_LIT>' ) <EOL> data = np . load ( mnist_train_path ) <EOL> train = data [ <NUM_LIT> : , : ] <EOL> valid = data [ : <NUM_LIT> , : ] <EOL> nHidden = <NUM_LIT:100> <EOL> ViewDimensions = ( <NUM_LIT:10> , <NUM_LIT:10> ) <EOL> arch = [ train . shape [ <NUM_LIT:1> ] , nHidden , train . shape [ <NUM_LIT:1> ] ] <EOL> lts = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> reg = pydeep . neural . NetReg ( ) <EOL> reg . dropout = True <EOL> reg . max_constraint = True <EOL> regs = [ reg ] * <NUM_LIT:2> <EOL> regs [ <NUM_LIT:0> ] . drop_rate = <NUM_LIT> <EOL> regs [ <NUM_LIT:1> ] . drop_rate = <NUM_LIT:0.5> <EOL> net = pydeep . neural . Net ( arch , lts , regs ) <EOL> ntp = pydeep . neural . NetTrainParams ( ) <EOL> ntp . maxepoch = <NUM_LIT> <EOL> ntp . eta = pydeep . scalar_schedule . ExponentialSchedule ( <NUM_LIT:1.0> , <NUM_LIT> ) <EOL> pydeep . neural . train_sgd ( net , train , train , ntp ) <EOL> Wimg = pydeep . utils . utils . tile_raster_images ( net . layers [ <NUM_LIT:0> ] . W . T , ( <NUM_LIT> , <NUM_LIT> ) , ViewDimensions ) <EOL> pylab . figure ( <NUM_LIT:1> ) <EOL> pylab . imshow ( Wimg ) <EOL> pylab . set_cmap ( '<STR_LIT>' ) <EOL> pylab . axis ( '<STR_LIT>' ) <EOL> dimg_src = pydeep . utils . utils . tile_raster_images ( train , ( <NUM_LIT> , <NUM_LIT> ) , ViewDimensions ) <EOL> pylab . figure ( <NUM_LIT:2> ) <EOL> pylab . imshow ( dimg_src ) <EOL> pylab . axis ( '<STR_LIT>' ) <EOL> X = net . predict ( train ) <EOL> dimg_rec = pydeep . utils . utils . tile_raster_images ( X , ( <NUM_LIT> , <NUM_LIT> ) , ViewDimensions ) <EOL> pylab . figure ( <NUM_LIT:3> ) <EOL> pylab . imshow ( dimg_rec ) <EOL> pylab . axis ( '<STR_LIT>' ) <EOL> pylab . show ( ) </s>
