<s> """<STR_LIT>""" <EOL> import george <EOL> import unittest <EOL> import numpy as np <EOL> from scipy . optimize import check_grad <EOL> from robo . models . gaussian_process import GaussianProcess <EOL> from robo . initial_design . init_random_uniform import init_random_uniform <EOL> from robo . priors import default_priors <EOL> from robo . acquisition . information_gain import InformationGain <EOL> from robo . task . synthetic_functions . sin_func import SinFunction <EOL> from robo . util import epmgp <EOL> class InformationGainTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . task = SinFunction ( ) <EOL> kernel = george . kernels . Matern52Kernel ( np . ones ( [ self . task . n_dims ] ) * <NUM_LIT> , <EOL> ndim = self . task . n_dims ) <EOL> noise_kernel = george . kernels . WhiteKernel ( <NUM_LIT> , ndim = self . task . n_dims ) <EOL> kernel = <NUM_LIT> * ( kernel + noise_kernel ) <EOL> prior = default_priors . TophatPrior ( - <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> model = GaussianProcess ( kernel , prior = prior ) <EOL> X = init_random_uniform ( self . task . X_lower , <EOL> self . task . X_upper , <EOL> <NUM_LIT:3> ) <EOL> Y = self . task . evaluate ( X ) <EOL> model . train ( X , Y , do_optimize = False ) <EOL> self . acquisition_func = InformationGain ( model , <EOL> X_upper = self . task . X_upper , <EOL> X_lower = self . task . X_lower ) <EOL> self . acquisition_func . update ( model ) <EOL> def test_sampling_representer_points ( self ) : <EOL> assert np . any ( self . acquisition_func . zb >= self . acquisition_func . X_lower ) <EOL> assert np . any ( self . acquisition_func . zb <= self . acquisition_func . X_upper ) <EOL> def test_compute_pmin ( self ) : <EOL> m = np . ones ( [ self . acquisition_func . Nb , <NUM_LIT:1> ] ) <EOL> v = np . eye ( self . acquisition_func . Nb ) <EOL> pmin = epmgp . joint_min ( m , v ) <EOL> pmin = np . exp ( pmin ) <EOL> uprob = <NUM_LIT:1.> / self . acquisition_func . Nb <EOL> assert pmin . shape [ <NUM_LIT:0> ] == self . acquisition_func . Nb <EOL> assert np . any ( pmin < ( uprob + <NUM_LIT> ) ) and np . any ( pmin > uprob - <NUM_LIT> ) <EOL> m = np . ones ( [ self . acquisition_func . Nb , <NUM_LIT:1> ] ) * <NUM_LIT:1000> <EOL> m [ <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> v = np . eye ( self . acquisition_func . Nb ) <EOL> pmin = epmgp . joint_min ( m , v ) <EOL> pmin = np . exp ( pmin ) <EOL> uprob = <NUM_LIT:1.> / self . acquisition_func . Nb <EOL> assert pmin [ <NUM_LIT:0> ] == <NUM_LIT:1.0> <EOL> assert np . any ( pmin [ : <NUM_LIT:1> ] > <NUM_LIT> ) <EOL> def test_innovations ( self ) : <EOL> rep = np . array ( [ [ <NUM_LIT:1.0> ] ] ) <EOL> x = np . array ( [ [ <NUM_LIT:0.0> ] ] ) <EOL> dm , dv = self . acquisition_func . innovations ( x , rep ) <EOL> assert np . any ( np . abs ( dm ) < <NUM_LIT> ) <EOL> assert np . any ( np . abs ( dv ) < <NUM_LIT> ) <EOL> rep = np . array ( [ [ <NUM_LIT:1.0> ] ] ) <EOL> x = np . array ( [ [ <NUM_LIT> ] ] ) <EOL> dm , dv = self . acquisition_func . innovations ( x , rep ) <EOL> assert np . any ( np . abs ( dm ) > <NUM_LIT> ) <EOL> assert np . any ( np . abs ( dv ) > <NUM_LIT> ) <EOL> def test_general_interface ( self ) : <EOL> X_test = init_random_uniform ( self . task . X_lower , self . task . X_upper , <NUM_LIT:1> ) <EOL> a = self . acquisition_func ( X_test , False ) <EOL> assert len ( a . shape ) == <NUM_LIT:2> <EOL> assert a . shape [ <NUM_LIT:0> ] == X_test . shape [ <NUM_LIT:0> ] <EOL> assert a . shape [ <NUM_LIT:1> ] == <NUM_LIT:1> <EOL> def test_check_grads ( self ) : <EOL> x_ = np . array ( [ [ <NUM_LIT:0.1> ] ] ) <EOL> assert check_grad ( self . acquisition_func , <EOL> lambda x : - self . acquisition_func ( x , True ) [ <NUM_LIT:1> ] , x_ ) < <NUM_LIT> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
