<s> """<STR_LIT>""" <EOL> import GPy <EOL> default_seed = <NUM_LIT> <EOL> def oil ( num_inducing = <NUM_LIT:50> , max_iters = <NUM_LIT:100> , kernel = None , optimize = True , plot = True ) : <EOL> """<STR_LIT>""" <EOL> try : import pods <EOL> except ImportError : raise ImportWarning ( '<STR_LIT>' ) <EOL> data = pods . datasets . oil ( ) <EOL> X = data [ '<STR_LIT:X>' ] <EOL> Xtest = data [ '<STR_LIT>' ] <EOL> Y = data [ '<STR_LIT:Y>' ] [ : , <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> Ytest = data [ '<STR_LIT>' ] [ : , <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> Y [ Y . flatten ( ) == - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> Ytest [ Ytest . flatten ( ) == - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> m = GPy . models . SparseGPClassification ( X , Y , kernel = kernel , num_inducing = num_inducing ) <EOL> m . Ytest = Ytest <EOL> m [ '<STR_LIT>' ] = <NUM_LIT> <EOL> if optimize : <EOL> m . optimize ( messages = <NUM_LIT:1> ) <EOL> print ( m ) <EOL> probs = m . predict ( Xtest ) [ <NUM_LIT:0> ] <EOL> GPy . util . classification . conf_matrix ( probs , Ytest ) <EOL> return m <EOL> def toy_linear_1d_classification ( seed = default_seed , optimize = True , plot = True ) : <EOL> """<STR_LIT>""" <EOL> try : import pods <EOL> except ImportError : raise ImportWarning ( '<STR_LIT>' ) <EOL> data = pods . datasets . toy_linear_1d_classification ( seed = seed ) <EOL> Y = data [ '<STR_LIT:Y>' ] [ : , <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> Y [ Y . flatten ( ) == - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> m = GPy . models . GPClassification ( data [ '<STR_LIT:X>' ] , Y ) <EOL> if optimize : <EOL> m . optimize ( ) <EOL> if plot : <EOL> from matplotlib import pyplot as plt <EOL> fig , axes = plt . subplots ( <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> m . plot_f ( ax = axes [ <NUM_LIT:0> ] ) <EOL> m . plot ( ax = axes [ <NUM_LIT:1> ] ) <EOL> print ( m ) <EOL> return m <EOL> def toy_linear_1d_classification_laplace ( seed = default_seed , optimize = True , plot = True ) : <EOL> """<STR_LIT>""" <EOL> try : import pods <EOL> except ImportError : print ( '<STR_LIT>' ) <EOL> data = pods . datasets . toy_linear_1d_classification ( seed = seed ) <EOL> Y = data [ '<STR_LIT:Y>' ] [ : , <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> Y [ Y . flatten ( ) == - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> likelihood = GPy . likelihoods . Bernoulli ( ) <EOL> laplace_inf = GPy . inference . latent_function_inference . Laplace ( ) <EOL> kernel = GPy . kern . RBF ( <NUM_LIT:1> ) <EOL> m = GPy . core . GP ( data [ '<STR_LIT:X>' ] , Y , kernel = kernel , likelihood = likelihood , inference_method = laplace_inf ) <EOL> if optimize : <EOL> try : <EOL> m . optimize ( '<STR_LIT>' , messages = <NUM_LIT:1> ) <EOL> except Exception as e : <EOL> return m <EOL> if plot : <EOL> from matplotlib import pyplot as plt <EOL> fig , axes = plt . subplots ( <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> m . plot_f ( ax = axes [ <NUM_LIT:0> ] ) <EOL> m . plot ( ax = axes [ <NUM_LIT:1> ] ) <EOL> print ( m ) <EOL> return m <EOL> def sparse_toy_linear_1d_classification ( num_inducing = <NUM_LIT:10> , seed = default_seed , optimize = True , plot = True ) : <EOL> """<STR_LIT>""" <EOL> try : import pods <EOL> except ImportError : print ( '<STR_LIT>' ) <EOL> data = pods . datasets . toy_linear_1d_classification ( seed = seed ) <EOL> Y = data [ '<STR_LIT:Y>' ] [ : , <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> Y [ Y . flatten ( ) == - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> m = GPy . models . SparseGPClassification ( data [ '<STR_LIT:X>' ] , Y , num_inducing = num_inducing ) <EOL> m [ '<STR_LIT>' ] = <NUM_LIT> <EOL> if optimize : <EOL> m . optimize ( ) <EOL> if plot : <EOL> from matplotlib import pyplot as plt <EOL> fig , axes = plt . subplots ( <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> m . plot_f ( ax = axes [ <NUM_LIT:0> ] ) <EOL> m . plot ( ax = axes [ <NUM_LIT:1> ] ) <EOL> print ( m ) <EOL> return m <EOL> def sparse_toy_linear_1d_classification_uncertain_input ( num_inducing = <NUM_LIT:10> , seed = default_seed , optimize = True , plot = True ) : <EOL> """<STR_LIT>""" <EOL> try : import pods <EOL> except ImportError : print ( '<STR_LIT>' ) <EOL> import numpy as np <EOL> data = pods . datasets . toy_linear_1d_classification ( seed = seed ) <EOL> Y = data [ '<STR_LIT:Y>' ] [ : , <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> Y [ Y . flatten ( ) == - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> X = data [ '<STR_LIT:X>' ] <EOL> X_var = np . random . uniform ( <NUM_LIT> , <NUM_LIT:0.5> , X . shape ) <EOL> m = GPy . models . SparseGPClassificationUncertainInput ( X , X_var , Y , num_inducing = num_inducing ) <EOL> m [ '<STR_LIT>' ] = <NUM_LIT> <EOL> if optimize : <EOL> m . optimize ( ) <EOL> if plot : <EOL> from matplotlib import pyplot as plt <EOL> fig , axes = plt . subplots ( <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> m . plot_f ( ax = axes [ <NUM_LIT:0> ] ) <EOL> m . plot ( ax = axes [ <NUM_LIT:1> ] ) <EOL> print ( m ) <EOL> return m <EOL> def toy_heaviside ( seed = default_seed , max_iters = <NUM_LIT:100> , optimize = True , plot = True ) : <EOL> """<STR_LIT>""" <EOL> try : import pods <EOL> except ImportError : print ( '<STR_LIT>' ) <EOL> data = pods . datasets . toy_linear_1d_classification ( seed = seed ) <EOL> Y = data [ '<STR_LIT:Y>' ] [ : , <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> Y [ Y . flatten ( ) == - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> kernel = GPy . kern . RBF ( <NUM_LIT:1> ) <EOL> likelihood = GPy . likelihoods . Bernoulli ( gp_link = GPy . likelihoods . link_functions . Heaviside ( ) ) <EOL> ep = GPy . inference . latent_function_inference . expectation_propagation . EP ( ) <EOL> m = GPy . core . GP ( X = data [ '<STR_LIT:X>' ] , Y = Y , kernel = kernel , likelihood = likelihood , inference_method = ep , name = '<STR_LIT>' ) <EOL> if optimize : <EOL> for _ in range ( <NUM_LIT:5> ) : <EOL> m . optimize ( max_iters = int ( max_iters / <NUM_LIT:5> ) ) <EOL> print ( m ) <EOL> if plot : <EOL> from matplotlib import pyplot as plt <EOL> fig , axes = plt . subplots ( <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> m . plot_f ( ax = axes [ <NUM_LIT:0> ] ) <EOL> m . plot ( ax = axes [ <NUM_LIT:1> ] ) <EOL> print ( m ) <EOL> return m <EOL> def crescent_data ( model_type = '<STR_LIT>' , num_inducing = <NUM_LIT:10> , seed = default_seed , kernel = None , optimize = True , plot = True ) : <EOL> """<STR_LIT>""" <EOL> try : import pods <EOL> except ImportError : print ( '<STR_LIT>' ) <EOL> data = pods . datasets . crescent_data ( seed = seed ) <EOL> Y = data [ '<STR_LIT:Y>' ] <EOL> Y [ Y . flatten ( ) == - <NUM_LIT:1> ] = <NUM_LIT:0> <EOL> if model_type == '<STR_LIT>' : <EOL> m = GPy . models . GPClassification ( data [ '<STR_LIT:X>' ] , Y , kernel = kernel ) <EOL> elif model_type == '<STR_LIT>' : <EOL> m = GPy . models . SparseGPClassification ( data [ '<STR_LIT:X>' ] , Y , kernel = kernel , num_inducing = num_inducing ) <EOL> m [ '<STR_LIT>' ] = <NUM_LIT> <EOL> elif model_type == '<STR_LIT>' : <EOL> m = GPy . models . FITCClassification ( data [ '<STR_LIT:X>' ] , Y , kernel = kernel , num_inducing = num_inducing ) <EOL> m [ '<STR_LIT>' ] = <NUM_LIT> <EOL> if optimize : <EOL> m . optimize ( messages = <NUM_LIT:1> ) <EOL> if plot : <EOL> m . plot ( ) <EOL> print ( m ) <EOL> return m </s>
