coin-or / rbfopt

RBFOpt library for black-box optimization
Other
188 stars 33 forks source link

Is there a way to exstract the rbf surrogate model? #29

Closed TheoChristiaanse closed 4 years ago

TheoChristiaanse commented 4 years ago

I found that we can save the state of the optimization. We there all the points are stored. Is it possible to extract the surrogate model from the stored optimization?

I think we could fit the used rbf function using the data from the stored data and rbf shape. Is there some code that we can easily use already available in the rbfopt library? Would be great to see what are the sub-optimal solutions we missed, and explore these using the surrogate model.

gnannicini commented 4 years ago

Here is an old related example. You would have to modify it to load the RbfoptAlgorihtm from file first; I didn't double check if it works, but should be very easy to adjust to your needs.

import rbfopt
import rbfopt.rbfopt_utils as ru

# I assume alg is the rbfopt.RbfoptAlgorithm object after optimization, i.e., after calling alg.optimize()
settings = rbfopt.RbfoptSettings(rbf=alg.best_global_rbf[0], rbf_shape_parameter=alg.best_global_rbf[1])
# The line above is to get the RBF type automatically selected by the algorithm; alternatively, you can select your own basis function
n = alg.n
k = len(alg.node_pos)
matrix = ru.get_rbf_matrix(settings, n, k, alg.node_pos)
rbf_l, rbf_h = ru.get_rbf_coefficients(settings, n, k, Amat, alg.node_val)
# Now rbf_l, rbf_h contain the parameters of the RBF model. You can evaluate it at a new point with:
new_value = ru.evaluate_rbf(settings, point_at_which_to_evaluate, n, k, alg.node_pos, rbf_l, rbf_h)
# If you want to evaluate it at many points, you can use this faster version:
new_values = ru.bulk_evaluate_rbf(settings, points_at_which_to_evaluate, n, k, alg.node_pos, rbf_l, rbf_h)