<s> """<STR_LIT>""" <EOL> __authors__ = "<STR_LIT>" <EOL> __copyright__ = "<STR_LIT>" <EOL> __credits__ = [ "<STR_LIT>" ] <EOL> __license__ = "<STR_LIT>" <EOL> __maintainer__ = "<STR_LIT>" <EOL> __email__ = "<STR_LIT>" <EOL> import numpy <EOL> import theano <EOL> import theano . tensor as T <EOL> from pylearn2 . compat import OrderedDict <EOL> from pylearn2 . models import Model <EOL> from pylearn2 . utils . rng import make_theano_rng <EOL> from pylearn2 . utils import sharedX , wraps <EOL> pi = sharedX ( numpy . pi ) <EOL> class Prior ( Model ) : <EOL> """<STR_LIT>""" <EOL> def get_vae ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> return self . vae <EOL> else : <EOL> return None <EOL> def set_vae ( self , vae ) : <EOL> """<STR_LIT>""" <EOL> if self . get_vae ( ) is not None : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . vae = vae <EOL> self . rng = self . vae . rng <EOL> self . theano_rng = make_theano_rng ( int ( self . rng . randint ( <NUM_LIT:2> ** <NUM_LIT:30> ) ) , <EOL> which_method = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . batch_size = vae . batch_size <EOL> def initialize_parameters ( self , nhid ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( str ( self . __class__ ) + "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def monitoring_channels_from_prior_params ( self ) : <EOL> """<STR_LIT>""" <EOL> return OrderedDict ( ) <EOL> def sample_from_p_z ( self , num_samples , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( str ( self . __class__ ) + "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def log_p_z ( self , z ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( str ( self . __class__ ) + "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class DiagonalGaussianPrior ( Prior ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( Prior . initialize_parameters ) <EOL> def initialize_parameters ( self , nhid ) : <EOL> self . nhid = nhid <EOL> self . prior_mu = sharedX ( numpy . zeros ( self . nhid ) , name = "<STR_LIT>" ) <EOL> self . log_prior_sigma = sharedX ( numpy . zeros ( self . nhid ) , <EOL> name = "<STR_LIT>" ) <EOL> self . _params = [ self . prior_mu , self . log_prior_sigma ] <EOL> @ wraps ( Prior . sample_from_p_z ) <EOL> def sample_from_p_z ( self , num_samples ) : <EOL> return self . theano_rng . normal ( size = ( num_samples , self . nhid ) , <EOL> avg = self . prior_mu , <EOL> std = T . exp ( self . log_prior_sigma ) , <EOL> dtype = theano . config . floatX ) <EOL> @ wraps ( Prior . log_p_z ) <EOL> def log_p_z ( self , z ) : <EOL> return - <NUM_LIT:0.5> * ( <EOL> T . log ( <NUM_LIT:2> * pi * T . exp ( <NUM_LIT:2> * self . log_prior_sigma ) ) + <EOL> ( ( z - self . prior_mu ) / T . exp ( self . log_prior_sigma ) ) ** <NUM_LIT:2> <EOL> ) . sum ( axis = <NUM_LIT:2> ) </s>
