<s> import logging <EOL> from scipy . stats import norm <EOL> import numpy as np <EOL> from robo . acquisition . base import AcquisitionFunction <EOL> from robo . incumbent . best_observation import BestObservation <EOL> logger = logging . getLogger ( __name__ ) <EOL> class LogEI ( AcquisitionFunction ) : <EOL> def __init__ ( self , model , X_lower , X_upper , par = <NUM_LIT> , ** kwargs ) : <EOL> r"""<STR_LIT>""" <EOL> super ( LogEI , self ) . __init__ ( model , X_lower , X_upper ) <EOL> self . par = par <EOL> self . rec = BestObservation ( self . model , self . X_lower , self . X_upper ) <EOL> def update ( self , model ) : <EOL> """<STR_LIT>""" <EOL> super ( LogEI , self ) . update ( model ) <EOL> self . rec = BestObservation ( self . model , self . X_lower , self . X_upper ) <EOL> def compute ( self , X , derivative = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if derivative : <EOL> logger . error ( "<STR_LIT>" ) <EOL> return <EOL> if np . any ( X < self . X_lower ) or np . any ( X > self . X_upper ) : <EOL> return np . array ( [ [ - np . finfo ( np . float ) . max ] ] ) <EOL> m , v = self . model . predict ( X ) <EOL> _ , eta = self . rec . estimate_incumbent ( None ) <EOL> f_min = eta - self . par <EOL> s = np . sqrt ( v ) <EOL> z = ( f_min - m ) / s <EOL> log_ei = np . zeros ( ( m . size , <NUM_LIT:1> ) ) <EOL> for i in range ( <NUM_LIT:0> , m . size ) : <EOL> mu , sigma = m [ i ] , s [ i ] <EOL> if np . any ( abs ( f_min - mu ) ) == <NUM_LIT:0> : <EOL> if sigma > <NUM_LIT:0> : <EOL> log_ei [ i ] = np . log ( sigma ) + norm . logpdf ( z [ i ] ) <EOL> else : <EOL> log_ei [ i ] = - np . Infinity <EOL> elif sigma == <NUM_LIT:0> : <EOL> if mu < np . any ( f_min ) : <EOL> log_ei [ i ] = np . log ( f_min - mu ) <EOL> else : <EOL> log_ei [ i ] = - np . Infinity <EOL> else : <EOL> b = np . log ( sigma ) + norm . logpdf ( z [ i ] ) <EOL> if np . any ( f_min > mu ) : <EOL> a = np . log ( f_min - mu ) + norm . logcdf ( z [ i ] ) <EOL> log_ei [ i ] = max ( a , b ) + np . log ( <NUM_LIT:1> + np . exp ( - abs ( b - a ) ) ) <EOL> else : <EOL> a = np . log ( mu - f_min ) + norm . logcdf ( z [ i ] ) <EOL> if a >= b : <EOL> log_ei [ i ] = - np . Infinity <EOL> else : <EOL> log_ei [ i ] = b + np . log ( <NUM_LIT:1> - np . exp ( a - b ) ) <EOL> return log_ei </s>
