# Copyright (c) 2015, Javier Gonzalez
# Copyright (c) 2015, the GPy Authors (see GPy AUTHORS.txt)
# Licensed under the BSD 3-clause license (see LICENSE.txt)


"""
This is a simple demo to demonstrate the use of Bayesian optimization with GPyOpt with some simple options. Run the example by writing:

import GPyOpt
autoML_demo = GPyOpt.demos.autoMLtuner()

As a result you should see:

- A plot with the model and the current acquisition function
- A plot with the diagnostic plots of the optimization.
- An object call BO_demo_auto that contains the results of the optimization process (see reference manual for details). Among the available results you have access to the GP model via

>> BO_demo_2d.model

and to the location of the best found location writing.

BO_demo_auto.x_opt

"""

def autoML_tuner():

    import GPyOpt
    from numpy.random import seed
    import numpy as np
    import matplotlib.pyplot as plt
    
    # --- Regression problem
    n = 100
    b0 = 1 
    b1 = 2.5 
    X = np.random.uniform(1,10,n).reshape(n,1)
    Y = b0+b1*X +np.random.normal(0,1.5,n).reshape(n,1)

    # Objective function
    class objective:
        def __init__(self,X,Y):
            self.X = X
            self.Y = Y             
        def f(self,beta):
            return  sum((beta[:,0]+beta[:,1]*self.X-self.Y)**2).reshape(beta.shape[0],1)

                                   
    # --- Problem definition and optimization
    myobj = objective(X,Y)
    bounds = [(0,10),(0,10)]  
    
    # --- Tuning the parameters
    tuner = GPyOpt.methods.autoTune(myobj.f, bounds)   
    beta_tuner = tuner.x_opt             

    # --- OLS solution
    X1 = np.c_[np.ones(n),X ]
    beta_ols   = np.dot(np.dot(np.linalg.inv(np.dot(X1.T,X1)),X1.T),Y)
    
    # --- Plot
    plt.plot(X,Y,'.')
    plt.plot([0,10],[beta_tuner[0],beta_tuner[0]+beta_tuner[1]*10],'k.-',label='GPyOpt')
    plt.plot([0,10],[beta_ols[0],beta_ols[0]+beta_ols[1]*10],label='OLS')
    plt.legend()
@@ -392,114 +392,121 @@
 lot 
-with the model and the current acquisition function%0A- A plot with the diagnostic plots of the optimization
+comparing an OLS estimator for a simple regression problem with the obtained parameters using the automatic tuner
 .%0A- 
@@ -523,21 +523,21 @@
 call
- BO_demo_auto
+ed autoML_dem
  tha
@@ -692,28 +692,8 @@
 ia%0A%0A
-%3E%3E BO_demo_2d.model%0A
 %0Aand
@@ -750,19 +750,18 @@
 g.%0A%0A
-BO_demo_aut
+autoML_dem
 o.x_
@@ -1952,8 +1952,9 @@
 legend()
+%0A

Update autoML_tuner.py