<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from numpy import atleast_2d as array2d <EOL> from scipy import linalg <EOL> from scipy . optimize import minimize <EOL> from scipy . spatial . distance import squareform <EOL> from openmdao . surrogate_models . surrogate_model import MultiFiSurrogateModel <EOL> import logging <EOL> _logger = logging . getLogger ( ) <EOL> MACHINE_EPSILON = np . finfo ( np . double ) . eps <EOL> NUGGET = <NUM_LIT> * MACHINE_EPSILON <EOL> INITIAL_RANGE_DEFAULT = <NUM_LIT> <EOL> TOLERANCE_DEFAULT = <NUM_LIT> <EOL> THETA0_DEFAULT = <NUM_LIT:0.5> <EOL> THETAL_DEFAULT = <NUM_LIT> <EOL> THETAU_DEFAULT = <NUM_LIT:50> <EOL> if hasattr ( linalg , '<STR_LIT>' ) : <EOL> solve_triangular = linalg . solve_triangular <EOL> else : <EOL> def solve_triangular ( x , y , lower = True ) : <EOL> return linalg . solve ( x , y ) <EOL> def constant_regression ( x ) : <EOL> """<STR_LIT>""" <EOL> x = np . asarray ( x , dtype = np . float ) <EOL> n_eval = x . shape [ <NUM_LIT:0> ] <EOL> f = np . ones ( [ n_eval , <NUM_LIT:1> ] ) <EOL> return f <EOL> def linear_regression ( x ) : <EOL> """<STR_LIT>""" <EOL> x = np . asarray ( x , dtype = np . float ) <EOL> n_eval = x . shape [ <NUM_LIT:0> ] <EOL> f = np . hstack ( [ np . ones ( [ n_eval , <NUM_LIT:1> ] ) , x ] ) <EOL> return f <EOL> def squared_exponential_correlation ( theta , d ) : <EOL> """<STR_LIT>""" <EOL> theta = np . asarray ( theta , dtype = np . float ) <EOL> d = np . asarray ( d , dtype = np . float ) <EOL> if d . ndim > <NUM_LIT:1> : <EOL> n_features = d . shape [ <NUM_LIT:1> ] <EOL> else : <EOL> n_features = <NUM_LIT:1> <EOL> if theta . size == <NUM_LIT:1> : <EOL> return np . exp ( - theta [ <NUM_LIT:0> ] * np . sum ( d ** <NUM_LIT:2> , axis = <NUM_LIT:1> ) ) <EOL> elif theta . size != n_features : <EOL> raise ValueError ( "<STR_LIT>" % n_features ) <EOL> else : <EOL> return np . exp ( - np . sum ( theta . reshape ( <NUM_LIT:1> , n_features ) * d ** <NUM_LIT:2> , axis = <NUM_LIT:1> ) ) <EOL> def l1_cross_distances ( X , Y = None ) : <EOL> """<STR_LIT>""" <EOL> if Y is None : <EOL> X = array2d ( X ) <EOL> n_samples , n_features = X . shape <EOL> n_nonzero_cross_dist = n_samples * ( n_samples - <NUM_LIT:1> ) // <NUM_LIT:2> <EOL> D = np . zeros ( ( n_nonzero_cross_dist , n_features ) ) <EOL> ll_1 = <NUM_LIT:0> <EOL> for k in range ( n_samples - <NUM_LIT:1> ) : <EOL> ll_0 = ll_1 <EOL> ll_1 = ll_0 + n_samples - k - <NUM_LIT:1> <EOL> D [ ll_0 : ll_1 ] = np . abs ( X [ k ] - X [ ( k + <NUM_LIT:1> ) : ] ) <EOL> return D <EOL> else : <EOL> X = array2d ( X ) <EOL> Y = array2d ( Y ) <EOL> n_samples_X , n_features_X = X . shape <EOL> n_samples_Y , n_features_Y = Y . shape <EOL> if n_features_X != n_features_Y : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> n_features = n_features_X <EOL> n_nonzero_cross_dist = n_samples_X * n_samples_Y <EOL> D = np . zeros ( ( n_nonzero_cross_dist , n_features ) ) <EOL> ll_1 = <NUM_LIT:0> <EOL> for k in range ( n_samples_X ) : <EOL> ll_0 = ll_1 <EOL> ll_1 = ll_0 + n_samples_Y <EOL> D [ ll_0 : ll_1 ] = np . abs ( X [ k ] - Y ) <EOL> return D <EOL> class MultiFiCoKriging ( object ) : <EOL> """<STR_LIT>""" <EOL> _regression_types = { <EOL> '<STR_LIT>' : constant_regression , <EOL> '<STR_LIT>' : linear_regression } <EOL> def __init__ ( self , regr = '<STR_LIT>' , rho_regr = '<STR_LIT>' , <EOL> theta = None , theta0 = None , thetaL = None , thetaU = None ) : <EOL> self . corr = squared_exponential_correlation <EOL> self . regr = regr <EOL> self . rho_regr = rho_regr <EOL> self . theta = theta <EOL> self . theta0 = theta0 <EOL> self . thetaL = thetaL <EOL> self . thetaU = thetaU <EOL> self . _nfev = <NUM_LIT:0> <EOL> def _build_R ( self , lvl , theta ) : <EOL> """<STR_LIT>""" <EOL> D = self . D [ lvl ] <EOL> n_samples = self . n_samples [ lvl ] <EOL> R = np . eye ( n_samples ) * ( <NUM_LIT:1.> + NUGGET ) <EOL> corr = squareform ( self . corr ( theta , D ) ) <EOL> R = R + corr <EOL> return R <EOL> def fit ( self , X , y , <EOL> initial_range = INITIAL_RANGE_DEFAULT , tol = TOLERANCE_DEFAULT ) : <EOL> """<STR_LIT>""" <EOL> self . _check_list_structure ( X , y ) <EOL> self . _check_params ( ) <EOL> X = self . X <EOL> y = self . y <EOL> nlevel = self . nlevel <EOL> n_samples = self . n_samples <EOL> self . beta = nlevel * [ <NUM_LIT:0> ] <EOL> self . beta_rho = nlevel * [ None ] <EOL> self . beta_regr = nlevel * [ None ] <EOL> self . C = nlevel * [ <NUM_LIT:0> ] <EOL> self . D = nlevel * [ <NUM_LIT:0> ] <EOL> self . F = nlevel * [ <NUM_LIT:0> ] <EOL> self . p = nlevel * [ <NUM_LIT:0> ] <EOL> self . q = nlevel * [ <NUM_LIT:0> ] <EOL> self . G = nlevel * [ <NUM_LIT:0> ] <EOL> self . sigma2 = nlevel * [ <NUM_LIT:0> ] <EOL> self . _R_adj = nlevel * [ None ] <EOL> y_best = y [ nlevel - <NUM_LIT:1> ] <EOL> for i in range ( nlevel - <NUM_LIT:1> ) [ : : - <NUM_LIT:1> ] : <EOL> y_best = np . concatenate ( ( y [ i ] [ : - n_samples [ i + <NUM_LIT:1> ] ] , y_best ) ) <EOL> self . y_best = y_best <EOL> self . y_mean = np . zeros ( <NUM_LIT:1> ) <EOL> self . y_std = np . ones ( <NUM_LIT:1> ) <EOL> self . X_mean = np . zeros ( <NUM_LIT:1> ) <EOL> self . X_std = np . ones ( <NUM_LIT:1> ) <EOL> for lvl in range ( nlevel ) : <EOL> self . D [ lvl ] = l1_cross_distances ( X [ lvl ] ) <EOL> if ( np . min ( np . sum ( self . D [ lvl ] , axis = <NUM_LIT:1> ) ) == <NUM_LIT:0.> ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . F [ lvl ] = self . regr ( X [ lvl ] ) <EOL> self . p [ lvl ] = self . F [ lvl ] . shape [ <NUM_LIT:1> ] <EOL> if lvl > <NUM_LIT:0> : <EOL> F_rho = self . rho_regr ( X [ lvl ] ) <EOL> self . q [ lvl ] = F_rho . shape [ <NUM_LIT:1> ] <EOL> self . F [ lvl ] = np . hstack ( ( F_rho * np . dot ( ( self . y [ lvl - <NUM_LIT:1> ] ) [ - n_samples [ lvl ] : ] , <EOL> np . ones ( ( <NUM_LIT:1> , self . q [ lvl ] ) ) ) , self . F [ lvl ] ) ) <EOL> else : <EOL> self . q [ lvl ] = <NUM_LIT:0> <EOL> n_samples_F_i = self . F [ lvl ] . shape [ <NUM_LIT:0> ] <EOL> if n_samples_F_i != n_samples [ lvl ] : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if int ( self . p [ lvl ] + self . q [ lvl ] ) >= n_samples_F_i : <EOL> raise Exception ( ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> % ( n_samples [ i ] , self . p [ lvl ] + self . q [ lvl ] ) ) <EOL> self . X = X <EOL> self . y = y <EOL> self . rlf_value = np . zeros ( nlevel ) <EOL> for lvl in range ( nlevel ) : <EOL> if self . theta [ lvl ] is None : <EOL> sol = self . _max_rlf ( lvl = lvl , initial_range = initial_range , tol = tol ) <EOL> self . theta [ lvl ] = sol [ '<STR_LIT>' ] <EOL> self . rlf_value [ lvl ] = sol [ '<STR_LIT>' ] <EOL> if np . isinf ( self . rlf_value [ lvl ] ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . rlf_value [ lvl ] = self . rlf ( lvl = lvl ) <EOL> if np . isinf ( self . rlf_value [ lvl ] ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return <EOL> def rlf ( self , lvl , theta = None ) : <EOL> """<STR_LIT>""" <EOL> if theta is None : <EOL> theta = self . theta [ lvl ] <EOL> rlf_value = <NUM_LIT> <EOL> n_samples = self . n_samples [ lvl ] <EOL> y = self . y [ lvl ] <EOL> F = self . F [ lvl ] <EOL> p = self . p [ lvl ] <EOL> q = self . q [ lvl ] <EOL> R = self . _build_R ( lvl , theta ) <EOL> try : <EOL> C = linalg . cholesky ( R , lower = True ) <EOL> except linalg . LinAlgError : <EOL> _logger . warning ( ( '<STR_LIT>' % lvl ) + <EOL> '<STR_LIT>' + str ( theta ) ) <EOL> return rlf_value <EOL> Ft = solve_triangular ( C , F , lower = True ) <EOL> Yt = solve_triangular ( C , y , lower = True ) <EOL> try : <EOL> Q , G = linalg . qr ( Ft , econ = True ) <EOL> except : <EOL> Q , G = linalg . qr ( Ft , mode = '<STR_LIT>' ) <EOL> pass <EOL> beta = solve_triangular ( G , np . dot ( Q . T , Yt ) ) <EOL> err = Yt - np . dot ( Ft , beta ) <EOL> err2 = np . dot ( err . T , err ) [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> self . _err = err <EOL> sigma2 = err2 / ( n_samples - p - q ) <EOL> detR = ( ( np . diag ( C ) ) ** ( <NUM_LIT> / n_samples ) ) . prod ( ) <EOL> rlf_value = ( n_samples - p - q ) * np . log10 ( sigma2 ) + n_samples * np . log10 ( detR ) <EOL> self . beta_rho [ lvl ] = beta [ : q ] <EOL> self . beta_regr [ lvl ] = beta [ q : ] <EOL> self . beta [ lvl ] = beta <EOL> self . sigma2 [ lvl ] = sigma2 <EOL> self . C [ lvl ] = C <EOL> self . G [ lvl ] = G <EOL> return rlf_value <EOL> def _max_rlf ( self , lvl , initial_range , tol ) : <EOL> """<STR_LIT>""" <EOL> thetaL = self . thetaL [ lvl ] <EOL> thetaU = self . thetaU [ lvl ] <EOL> def rlf_transform ( x ) : <EOL> return self . rlf ( theta = <NUM_LIT> ** x , lvl = lvl ) <EOL> theta0 = self . theta0 [ lvl ] <EOL> x0 = np . log10 ( theta0 [ <NUM_LIT:0> ] ) <EOL> constraints = [ ] <EOL> for i in range ( theta0 . size ) : <EOL> constraints . append ( { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : lambda log10t , i = i : <EOL> log10t [ i ] - np . log10 ( thetaL [ <NUM_LIT:0> ] [ i ] ) } ) <EOL> constraints . append ( { '<STR_LIT:type>' : '<STR_LIT>' , '<STR_LIT>' : lambda log10t , i = i : <EOL> np . log10 ( thetaU [ <NUM_LIT:0> ] [ i ] ) - log10t [ i ] } ) <EOL> constraints = tuple ( constraints ) <EOL> sol = minimize ( rlf_transform , x0 , method = '<STR_LIT>' , <EOL> constraints = constraints , <EOL> options = { '<STR_LIT>' : initial_range , <EOL> '<STR_LIT>' : tol , '<STR_LIT>' : <NUM_LIT:0> } ) <EOL> log10_optimal_x = sol [ '<STR_LIT:x>' ] <EOL> optimal_rlf_value = sol [ '<STR_LIT>' ] <EOL> self . _nfev += sol [ '<STR_LIT>' ] <EOL> optimal_theta = <NUM_LIT> ** log10_optimal_x <EOL> res = { } <EOL> res [ '<STR_LIT>' ] = optimal_theta <EOL> res [ '<STR_LIT>' ] = optimal_rlf_value <EOL> return res <EOL> def predict ( self , X , eval_MSE = True ) : <EOL> """<STR_LIT>""" <EOL> X = array2d ( X ) <EOL> nlevel = self . nlevel <EOL> n_eval , n_features_X = X . shape <EOL> mu = np . zeros ( ( n_eval , nlevel ) ) <EOL> f = self . regr ( X ) <EOL> f0 = self . regr ( X ) <EOL> dx = l1_cross_distances ( X , Y = self . X [ <NUM_LIT:0> ] ) <EOL> F = self . F [ <NUM_LIT:0> ] <EOL> C = self . C [ <NUM_LIT:0> ] <EOL> beta = self . beta [ <NUM_LIT:0> ] <EOL> Ft = solve_triangular ( C , F , lower = True ) <EOL> yt = solve_triangular ( C , self . y [ <NUM_LIT:0> ] , lower = True ) <EOL> r_ = self . corr ( self . theta [ <NUM_LIT:0> ] , dx ) . reshape ( n_eval , self . n_samples [ <NUM_LIT:0> ] ) <EOL> gamma = solve_triangular ( C . T , yt - np . dot ( Ft , beta ) , lower = False ) <EOL> mu [ : , <NUM_LIT:0> ] = ( np . dot ( f , beta ) + np . dot ( r_ , gamma ) ) . ravel ( ) <EOL> if eval_MSE : <EOL> self . sigma2_rho = nlevel * [ None ] <EOL> MSE = np . zeros ( ( n_eval , nlevel ) ) <EOL> r_t = solve_triangular ( C , r_ . T , lower = True ) <EOL> G = self . G [ <NUM_LIT:0> ] <EOL> u_ = solve_triangular ( G . T , f . T - np . dot ( Ft . T , r_t ) , lower = True ) <EOL> MSE [ : , <NUM_LIT:0> ] = self . sigma2 [ <NUM_LIT:0> ] * ( <NUM_LIT:1> - ( r_t ** <NUM_LIT:2> ) . sum ( axis = <NUM_LIT:0> ) + ( u_ ** <NUM_LIT:2> ) . sum ( axis = <NUM_LIT:0> ) ) <EOL> for i in range ( <NUM_LIT:1> , nlevel ) : <EOL> C = self . C [ i ] <EOL> F = self . F [ i ] <EOL> g = self . rho_regr ( X ) <EOL> dx = l1_cross_distances ( X , Y = self . X [ i ] ) <EOL> r_ = self . corr ( self . theta [ i ] , dx ) . reshape ( n_eval , self . n_samples [ i ] ) <EOL> f = np . vstack ( ( g . T * mu [ : , i - <NUM_LIT:1> ] , f0 . T ) ) <EOL> Ft = solve_triangular ( C , F , lower = True ) <EOL> yt = solve_triangular ( C , self . y [ i ] , lower = True ) <EOL> r_t = solve_triangular ( C , r_ . T , lower = True ) <EOL> G = self . G [ i ] <EOL> beta = self . beta [ i ] <EOL> mu [ : , i ] = ( np . dot ( f . T , beta ) + np . dot ( r_t . T , yt - np . dot ( Ft , beta ) ) ) . ravel ( ) <EOL> if eval_MSE : <EOL> Q_ = ( np . dot ( ( yt - np . dot ( Ft , beta ) ) . T , yt - np . dot ( Ft , beta ) ) ) [ <NUM_LIT:0> , <NUM_LIT:0> ] <EOL> u_ = solve_triangular ( G . T , f - np . dot ( Ft . T , r_t ) , lower = True ) <EOL> sigma2_rho = np . dot ( g , self . sigma2 [ i ] * linalg . inv ( np . dot ( G . T , G ) ) [ : self . q [ i ] , : self . q [ i ] ] + np . dot ( beta [ : self . q [ i ] ] , beta [ : self . q [ i ] ] . T ) ) <EOL> sigma2_rho = ( sigma2_rho * g ) . sum ( axis = <NUM_LIT:1> ) <EOL> MSE [ : , i ] = sigma2_rho * MSE [ : , i - <NUM_LIT:1> ] + Q_ / ( <NUM_LIT:2> * ( self . n_samples [ i ] - self . p [ i ] - self . q [ i ] ) ) * ( <NUM_LIT:1> - ( r_t ** <NUM_LIT:2> ) . sum ( axis = <NUM_LIT:0> ) ) + self . sigma2 [ i ] * ( u_ ** <NUM_LIT:2> ) . sum ( axis = <NUM_LIT:0> ) <EOL> for i in range ( nlevel ) : <EOL> mu [ : , i ] = self . y_mean + self . y_std * mu [ : , i ] <EOL> if eval_MSE : <EOL> MSE [ : , i ] = self . y_std ** <NUM_LIT:2> * MSE [ : , i ] <EOL> if eval_MSE : <EOL> return mu [ : , - <NUM_LIT:1> ] . reshape ( ( n_eval , <NUM_LIT:1> ) ) , MSE [ : , - <NUM_LIT:1> ] . reshape ( ( n_eval , <NUM_LIT:1> ) ) <EOL> else : <EOL> return mu [ : , - <NUM_LIT:1> ] . reshape ( ( n_eval , <NUM_LIT:1> ) ) <EOL> def _check_list_structure ( self , X , y ) : <EOL> if type ( X ) is not list : <EOL> nlevel = <NUM_LIT:1> <EOL> X = [ X ] <EOL> else : <EOL> nlevel = len ( X ) <EOL> if type ( y ) is not list : <EOL> y = [ y ] <EOL> if len ( X ) != len ( y ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> n_samples = np . zeros ( nlevel , dtype = int ) <EOL> n_features = np . zeros ( nlevel , dtype = int ) <EOL> n_samples_y = np . zeros ( nlevel , dtype = int ) <EOL> for i in range ( nlevel ) : <EOL> n_samples [ i ] , n_features [ i ] = X [ i ] . shape <EOL> if i > <NUM_LIT:1> and n_features [ i ] != n_features [ i - <NUM_LIT:1> ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> y [ i ] = np . asarray ( y [ i ] ) . ravel ( ) [ : , np . newaxis ] <EOL> n_samples_y [ i ] = y [ i ] . shape [ <NUM_LIT:0> ] <EOL> if n_samples [ i ] != n_samples_y [ i ] : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . n_features = n_features [ <NUM_LIT:0> ] <EOL> if type ( self . theta ) is not list : <EOL> self . theta = nlevel * [ self . theta ] <EOL> elif len ( self . theta ) != nlevel : <EOL> raise ValueError ( "<STR_LIT>" % nlevel ) <EOL> if type ( self . theta0 ) is not list : <EOL> self . theta0 = nlevel * [ self . theta0 ] <EOL> elif len ( self . theta0 ) != nlevel : <EOL> raise ValueError ( "<STR_LIT>" % nlevel ) <EOL> if type ( self . thetaL ) is not list : <EOL> self . thetaL = nlevel * [ self . thetaL ] <EOL> elif len ( self . thetaL ) != nlevel : <EOL> raise ValueError ( "<STR_LIT>" % nlevel ) <EOL> if type ( self . thetaU ) is not list : <EOL> self . thetaU = nlevel * [ self . thetaU ] <EOL> elif len ( self . thetaU ) != nlevel : <EOL> raise ValueError ( "<STR_LIT>" % nlevel ) <EOL> self . nlevel = nlevel <EOL> self . X = X [ : ] <EOL> self . y = y [ : ] <EOL> self . n_samples = n_samples <EOL> return <EOL> def _check_params ( self ) : <EOL> if not callable ( self . regr ) : <EOL> if self . regr in self . _regression_types : <EOL> self . regr = self . _regression_types [ self . regr ] <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( self . _regression_types . keys ( ) , self . regr ) ) <EOL> if not callable ( self . rho_regr ) : <EOL> if self . rho_regr in self . _regression_types : <EOL> self . rho_regr = self . _regression_types [ self . rho_regr ] <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( self . _regression_types . keys ( ) , self . rho_regr ) ) <EOL> for i in range ( self . nlevel ) : <EOL> if self . theta [ i ] is not None : <EOL> self . theta [ i ] = array2d ( self . theta [ i ] ) <EOL> if np . any ( self . theta [ i ] <= <NUM_LIT:0> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if self . theta0 [ i ] is not None : <EOL> self . theta0 [ i ] = array2d ( self . theta0 [ i ] ) <EOL> if np . any ( self . theta0 [ i ] <= <NUM_LIT:0> ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> self . theta0 [ i ] = array2d ( self . n_features * [ THETA0_DEFAULT ] ) <EOL> lth = self . theta0 [ i ] . size <EOL> if self . thetaL [ i ] is not None : <EOL> self . thetaL [ i ] = array2d ( self . thetaL [ i ] ) <EOL> if self . thetaL [ i ] . size != lth : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . thetaL [ i ] = array2d ( self . n_features * [ THETAL_DEFAULT ] ) <EOL> if self . thetaU [ i ] is not None : <EOL> self . thetaU [ i ] = array2d ( self . thetaU [ i ] ) <EOL> if self . thetaU [ i ] . size != lth : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . thetaU [ i ] = array2d ( self . n_features * [ THETAU_DEFAULT ] ) <EOL> if np . any ( self . thetaL [ i ] <= <NUM_LIT:0> ) or np . any ( self . thetaU [ i ] < self . thetaL [ i ] ) : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return <EOL> class MultiFiCoKrigingSurrogate ( MultiFiSurrogateModel ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , regr = '<STR_LIT>' , rho_regr = '<STR_LIT>' , <EOL> theta = None , theta0 = None , thetaL = None , thetaU = None , <EOL> tolerance = TOLERANCE_DEFAULT , initial_range = INITIAL_RANGE_DEFAULT ) : <EOL> super ( MultiFiCoKrigingSurrogate , self ) . __init__ ( ) <EOL> self . tolerance = tolerance <EOL> self . initial_range = initial_range <EOL> self . model = MultiFiCoKriging ( regr = regr , rho_regr = rho_regr , theta = theta , <EOL> theta0 = theta0 , thetaL = thetaL , thetaU = thetaU ) <EOL> def predict ( self , new_x ) : <EOL> """<STR_LIT>""" <EOL> Y_pred , MSE = self . model . predict ( [ new_x ] ) <EOL> return Y_pred , np . sqrt ( np . abs ( MSE ) ) <EOL> def train_multifi ( self , X , Y ) : <EOL> """<STR_LIT>""" <EOL> X , Y = self . _fit_adapter ( X , Y ) <EOL> self . model . fit ( X , Y , tol = self . tolerance , initial_range = self . initial_range ) <EOL> def _fit_adapter ( self , X , Y ) : <EOL> if len ( np . shape ( np . array ( X [ <NUM_LIT:0> ] ) ) ) == <NUM_LIT:1> : <EOL> X = [ X ] <EOL> Y = [ Y ] <EOL> X = [ np . array ( x ) for x in reversed ( X ) ] <EOL> Y = [ np . array ( y ) for y in reversed ( Y ) ] <EOL> return ( X , Y ) <EOL> class FloatMultiFiCoKrigingSurrogate ( MultiFiCoKrigingSurrogate ) : <EOL> """<STR_LIT>""" <EOL> def predict ( self , new_x ) : <EOL> dist = super ( FloatMultiFiCoKrigingSurrogate , self ) . predict ( new_x ) <EOL> return dist . mu <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import doctest <EOL> doctest . testmod ( ) </s>
