<s> from expsuite import PyExperimentSuite <EOL> from numpy import * <EOL> import hashlib <EOL> import os <EOL> class MySuite ( PyExperimentSuite ) : <EOL> def __init__ ( self ) : <EOL> PyExperimentSuite . __init__ ( self ) <EOL> self . dataset = None <EOL> def crossvalidation ( self , dataset , params , rep , shuffle = True ) : <EOL> """<STR_LIT>""" <EOL> if params [ '<STR_LIT>' ] < <NUM_LIT:2> : <EOL> raise SystemExit ( '<STR_LIT>' % params [ '<STR_LIT>' ] ) <EOL> key = int ( hashlib . sha1 ( dataset ) . hexdigest ( ) [ : <NUM_LIT:7> ] , <NUM_LIT:16> ) <EOL> indices = range ( dataset . shape [ <NUM_LIT:0> ] ) <EOL> if shuffle : <EOL> random . seed ( key ) <EOL> indices = random . permutation ( indices ) <EOL> batchsize = dataset . shape [ <NUM_LIT:0> ] // ( params [ '<STR_LIT>' ] ) <EOL> if batchsize == <NUM_LIT:0> : <EOL> raise SystemExit ( '<STR_LIT>' % dataset . shape [ <NUM_LIT:0> ] ) <EOL> batch = [ ] <EOL> for i in range ( params [ '<STR_LIT>' ] ) : <EOL> batch . append ( dataset [ indices [ batchsize * i : batchsize * ( i + <NUM_LIT:1> ) ] ] ) <EOL> trainset = zeros ( ( <NUM_LIT:0> , batch [ <NUM_LIT:0> ] . shape [ <NUM_LIT:1> ] ) , dtype = dataset . dtype ) <EOL> for i , b in enumerate ( batch ) : <EOL> if i == rep : <EOL> testset = b <EOL> else : <EOL> trainset = r_ [ trainset , b ] <EOL> return trainset , testset <EOL> def reset ( self , params , rep ) : <EOL> """<STR_LIT>""" <EOL> data = load ( os . path . join ( params [ '<STR_LIT>' ] ) ) <EOL> self . train , self . test = self . crossvalidation ( data , params , rep , shuffle = True ) <EOL> print <EOL> print <EOL> print '<STR_LIT>' % rep <EOL> print '<STR_LIT>' , self . train . flatten ( ) <EOL> print '<STR_LIT>' , self . test . flatten ( ) <EOL> print '<STR_LIT>' , <EOL> def iterate ( self , params , rep , n ) : <EOL> """<STR_LIT>""" <EOL> print '<STR_LIT:.>' , <EOL> ret = { '<STR_LIT>' : rep , '<STR_LIT>' : n } <EOL> return ret <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> mysuite = MySuite ( ) <EOL> mysuite . start ( ) </s>
