<s> import numpy as np <EOL> from scipy import stats , special <EOL> import scipy as sp <EOL> from . import link_functions <EOL> from . likelihood import Likelihood <EOL> class Exponential ( Likelihood ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , gp_link = None ) : <EOL> if gp_link is None : <EOL> gp_link = link_functions . Log ( ) <EOL> super ( Exponential , self ) . __init__ ( gp_link , '<STR_LIT>' ) <EOL> def pdf_link ( self , link_f , y , Y_metadata = None ) : <EOL> """<STR_LIT>""" <EOL> assert np . atleast_1d ( link_f ) . shape == np . atleast_1d ( y ) . shape <EOL> log_objective = link_f * np . exp ( - y * link_f ) <EOL> return np . exp ( np . sum ( np . log ( log_objective ) ) ) <EOL> def logpdf_link ( self , link_f , y , Y_metadata = None ) : <EOL> """<STR_LIT>""" <EOL> log_objective = np . log ( link_f ) - y * link_f <EOL> return log_objective <EOL> def dlogpdf_dlink ( self , link_f , y , Y_metadata = None ) : <EOL> """<STR_LIT>""" <EOL> grad = <NUM_LIT:1.> / link_f - y <EOL> return grad <EOL> def d2logpdf_dlink2 ( self , link_f , y , Y_metadata = None ) : <EOL> """<STR_LIT>""" <EOL> hess = - <NUM_LIT:1.> / ( link_f ** <NUM_LIT:2> ) <EOL> return hess <EOL> def d3logpdf_dlink3 ( self , link_f , y , Y_metadata = None ) : <EOL> """<STR_LIT>""" <EOL> d3lik_dlink3 = <NUM_LIT> / ( link_f ** <NUM_LIT:3> ) <EOL> return d3lik_dlink3 <EOL> def samples ( self , gp , Y_metadata = None ) : <EOL> """<STR_LIT>""" <EOL> orig_shape = gp . shape <EOL> gp = gp . flatten ( ) <EOL> Ysim = np . random . exponential ( <NUM_LIT:1.0> / self . gp_link . transf ( gp ) ) <EOL> return Ysim . reshape ( orig_shape ) </s>
