<s> """<STR_LIT>""" <EOL> import numpy as N <EOL> import copy <EOL> from theano import config <EOL> import theano . tensor as T <EOL> from pylearn2 . utils . rng import make_np_rng <EOL> class CosDataset ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , min_x = - <NUM_LIT> , max_x = <NUM_LIT> , std = <NUM_LIT> , rng = None ) : <EOL> """<STR_LIT>""" <EOL> self . min_x , self . max_x , self . std = min_x , max_x , std <EOL> rng = make_np_rng ( rng , [ <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ] , which_method = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . default_rng = copy . copy ( rng ) <EOL> self . rng = rng <EOL> def energy ( self , mat ) : <EOL> """<STR_LIT>""" <EOL> x = mat [ : , <NUM_LIT:0> ] <EOL> y = mat [ : , <NUM_LIT:1> ] <EOL> rval = ( y - N . cos ( x ) ) ** <NUM_LIT> / ( <NUM_LIT> * ( self . std ** <NUM_LIT> ) ) <EOL> return rval <EOL> def pdf_func ( self , mat ) : <EOL> """<STR_LIT>""" <EOL> x = mat [ : , <NUM_LIT:0> ] <EOL> y = mat [ : , <NUM_LIT:1> ] <EOL> rval = N . exp ( - ( y - N . cos ( x ) ) ** <NUM_LIT> / ( <NUM_LIT> * ( self . std ** <NUM_LIT> ) ) ) <EOL> rval /= N . sqrt ( <NUM_LIT> * N . pi * ( self . std ** <NUM_LIT> ) ) <EOL> rval /= ( self . max_x - self . min_x ) <EOL> rval *= x < self . max_x <EOL> rval *= x > self . min_x <EOL> return rval <EOL> def free_energy ( self , X ) : <EOL> """<STR_LIT>""" <EOL> x = X [ : , <NUM_LIT:0> ] <EOL> y = X [ : , <NUM_LIT:1> ] <EOL> rval = T . sqr ( y - T . cos ( x ) ) / ( <NUM_LIT> * ( self . std ** <NUM_LIT> ) ) <EOL> mask = x < self . max_x <EOL> mask = mask * ( x > self . min_x ) <EOL> rval = mask * rval + ( <NUM_LIT:1> - mask ) * <NUM_LIT> <EOL> return rval <EOL> def pdf ( self , X ) : <EOL> """<STR_LIT>""" <EOL> x = X [ : , <NUM_LIT:0> ] <EOL> y = X [ : , <NUM_LIT:1> ] <EOL> rval = T . exp ( - T . sqr ( y - T . cos ( x ) ) / ( <NUM_LIT> * ( self . std ** <NUM_LIT> ) ) ) <EOL> rval /= N . sqrt ( <NUM_LIT> * N . pi * ( self . std ** <NUM_LIT> ) ) <EOL> rval /= ( self . max_x - self . min_x ) <EOL> rval *= x < self . max_x <EOL> rval *= x > self . min_x <EOL> return rval <EOL> def get_stream_position ( self ) : <EOL> """<STR_LIT>""" <EOL> return copy . copy ( self . rng ) <EOL> def set_stream_position ( self , s ) : <EOL> """<STR_LIT>""" <EOL> self . rng = copy . copy ( s ) <EOL> def restart_stream ( self ) : <EOL> """<STR_LIT>""" <EOL> self . reset_RNG ( ) <EOL> def reset_RNG ( self ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in dir ( self ) : <EOL> self . default_rng = N . random . RandomState ( [ <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ] ) <EOL> self . rng = copy . copy ( self . default_rng ) <EOL> def apply_preprocessor ( self , preprocessor , can_fit = False ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) <EOL> def get_batch_design ( self , batch_size ) : <EOL> """<STR_LIT>""" <EOL> x = N . cast [ config . floatX ] ( self . rng . uniform ( self . min_x , self . max_x , <EOL> ( batch_size , <NUM_LIT:1> ) ) ) <EOL> y = N . cos ( x ) + ( N . cast [ config . floatX ] ( self . rng . randn ( * x . shape ) ) * <EOL> self . std ) <EOL> rval = N . hstack ( ( x , y ) ) <EOL> return rval </s>
