The basic equation of square exponential or RBF kernel is as follows:
Here l is the length scale and sigma is the variance parameter. The length scale controls
There are three primary problems here:
As a partially working example,ignoring the kernel definition to emphasize the optimizer:
import numpy as np
from scipy.optimize import minimize,least_squares
from sklearn.gaussian_process import GaussianProcessRegressor
def trust_region_optimizer(obj_func, initial_theta, bounds):
trust_region_method = least_squares(1/obj_func,initial_theta,bounds,method='trf')
return (trust_region_method.x,trust_region_method.fun)
X=np.random.random((10,4))
y=np.random.random((10,1))
gp = GaussianProcessRegressor(optimizer = trust_region_optimizer, alpha =1.2, n_restarts_optimizer=10)
gp.fit(X, y)
The scipy optimizers return a results object, using the minimization of the rosenbrock test function as an example:
from scipy.optimize import least_squares,rosen
res=least_squares(rosen,np.array([0,0]),method='trf')
As shown above, the optimized values can be accessed using:
res.x
and the resulting value of the function to be minimized:
res.fun
which is what the 'fun' parameter represents. However now that the optimizer is working internally, you will need to access the resulting function value from scikit-learn:
gp.log_marginal_likelihood_value_