<s> '''<STR_LIT>''' <EOL> import george <EOL> import cma <EOL> import numpy as np <EOL> from robo . task . synthetic_functions . branin import Branin <EOL> from robo . priors . base_prior import BasePrior <EOL> from robo . models . gaussian_process_mcmc import GaussianProcessMCMC <EOL> from robo . priors import default_priors <EOL> from robo . acquisition . ei import EI <EOL> from robo . acquisition . integrated_acquisition import IntegratedAcquisition <EOL> from robo . maximizers . direct import Direct <EOL> from robo . solver . bayesian_optimization import BayesianOptimization <EOL> class MyPrior ( BasePrior ) : <EOL> def __init__ ( self , n_dims ) : <EOL> super ( MyPrior , self ) . __init__ ( ) <EOL> self . n_dims = n_dims <EOL> self . tophat = default_priors . TophatPrior ( - <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> self . ln_prior = default_priors . LognormalPrior ( mean = <NUM_LIT:0.0> , sigma = <NUM_LIT:1.0> ) <EOL> self . horseshoe = default_priors . HorseshoePrior ( scale = <NUM_LIT:0.1> ) <EOL> def lnprob ( self , theta ) : <EOL> lp = <NUM_LIT:0> <EOL> lp += self . ln_prior . lnprob ( theta [ <NUM_LIT:0> ] ) <EOL> lp += self . tophat . lnprob ( theta [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) <EOL> lp += self . horseshoe . lnprob ( theta [ - <NUM_LIT:1> ] ) <EOL> return lp <EOL> def sample_from_prior ( self , n_samples ) : <EOL> p0 = np . zeros ( [ n_samples , self . n_dims ] ) <EOL> p0 [ : , <NUM_LIT:0> ] = self . ln_prior . sample_from_prior ( n_samples ) [ : , <NUM_LIT:0> ] <EOL> ls_sample = np . array ( [ self . tophat . sample_from_prior ( n_samples ) [ : , <NUM_LIT:0> ] <EOL> for _ in range ( <NUM_LIT:1> , ( self . n_dims - <NUM_LIT:1> ) ) ] ) . T <EOL> p0 [ : , <NUM_LIT:1> : ( self . n_dims - <NUM_LIT:1> ) ] = ls_sample <EOL> p0 [ : , - <NUM_LIT:1> ] = self . horseshoe . sample_from_prior ( n_samples ) [ : , <NUM_LIT:0> ] <EOL> return p0 <EOL> burnin = <NUM_LIT:100> <EOL> chain_length = <NUM_LIT:200> <EOL> n_hypers = <NUM_LIT:20> <EOL> task = Branin ( ) <EOL> cov_amp = <NUM_LIT:1.0> <EOL> config_kernel = george . kernels . Matern52Kernel ( np . ones ( [ task . n_dims ] ) , <EOL> ndim = task . n_dims ) <EOL> noise_kernel = george . kernels . WhiteKernel ( <NUM_LIT> , ndim = task . n_dims ) <EOL> kernel = cov_amp * ( config_kernel + noise_kernel ) <EOL> prior = MyPrior ( len ( kernel ) ) <EOL> model = GaussianProcessMCMC ( kernel , prior = prior , burnin = burnin , <EOL> chain_length = chain_length , n_hypers = n_hypers ) <EOL> ei = EI ( model , X_upper = task . X_upper , X_lower = task . X_lower , ) <EOL> acquisition_func = IntegratedAcquisition ( model , ei , <EOL> task . X_lower , task . X_upper ) <EOL> maximizer = Direct ( acquisition_func , task . X_lower , task . X_upper ) <EOL> bo = BayesianOptimization ( acquisition_func = acquisition_func , <EOL> model = model , <EOL> maximize_func = maximizer , <EOL> task = task ) <EOL> bo . run ( <NUM_LIT:20> ) </s>
