Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Using physical data not a "known" function #287

Closed
will-colea opened this issue Jan 6, 2020 · 8 comments
Closed

Using physical data not a "known" function #287

will-colea opened this issue Jan 6, 2020 · 8 comments

Comments

@will-colea
Copy link

Hello, I'm new to python and gaussian processes, so I need a little help/insight. I am trying to use GPyOpt with physical x, y data and not a "known" function. The examples all use a known function. I am reading in a .csv file and I want to use bayesian optimization with the test data to let me know what experiment to run next (obtain next x,y data set). Please any advice and help is appreciated. Thank you.

@will-colea
Copy link
Author

This is what I am working with now, but I'd like to use x,y collected data instead of the f(x) as some function. Thanks!

--- Load GPyOpt

from GPyOpt.methods import BayesianOptimization
import numpy as np

--- Define your problem

def f(x): return (6x-2)**2sin(x)
domain = [{'name': 'var_1', 'type': 'continuous', 'domain': (0,10)}]

--- Solve your problem

myBopt = BayesianOptimization(f=f, domain=domain)
myBopt.run_optimization(max_iter=10)
myBopt.plot_acquisition()

@apaleyes
Copy link
Collaborator

apaleyes commented Jan 7, 2020

have a look at external function evaluation example, sounds exactly like what you are doing: https://nbviewer.jupyter.org/github/SheffieldML/GPyOpt/blob/master/manual/GPyOpt_external_objective_evaluation.ipynb

@will-colea
Copy link
Author

Thank you for the recommendation.
I've taken a look at it. It seems that I need the x input to be an n by 1 array and the externally evaluated function needs to output some n by 1 array. I am still a bit confused how to implement this with xy data from say a .csv file. In this example it still seems like you need a known function. For instance in this 1D objective function, theres a known function defined as...
fval = 0.25*np.sin(12*X-4)
How can I implement this without having a known fval? Any thoughts or words of advice?
Thank you for your help and work on this library!

@apaleyes
Copy link
Collaborator

apaleyes commented Jan 8, 2020

You don't need to have a known function. On each of the iterations you just need to have a new pair of x,y ready. It could be produced by a function, an experiment, or read of a file. In your case you could ignore what BO recommends in terms of a next x location, and just read next line from the csv. not sure how effective that is, but that's as close as it gets.

on the other hand, since you already have all the data available in the csv, there isn't any benefit in using BO at all. just fit a GP to all this data and find min/max of the final mean function

@will-colea
Copy link
Author

Thank you for responding so quickly again. Your help is much appreciated.

Okay, I can definitely make a called function that provides the corresponding y from the data without actually having it plug x into a known function. I will try that.

Although, this leads me into another question about this for my implementation. To clarify I have a set of about 5 experiments that I used a latin square to choose my initial x points. Each new experiment takes me about a month to complete, which is why I am trying to implement this technique on my data. I want a recommendation on where to sample next in order to find a global max or min for y. In your opinion, do you believe this GPyOpt is viable to accomplish this?

Thank you for your time again!

@apaleyes
Copy link
Collaborator

apaleyes commented Jan 9, 2020

Yes, it does make sense to use bayesian optimization, with gpyopt or not, for your use case. but now i am confused about the csv file. where does it come from?

@will-colea
Copy link
Author

Thank you again for your response and your time/expertise.

Yes, so I used a latin square (common in design of experiments) that basically gave me a set of initial sets of experiments to run. I have completed those initial experiments and have this data, but I need to run probably a few more to know if I've reached an optimum. I was hoping to use the results of these initial experiments with bayesian optimization + acquisition function to determine my next experiment to run.

@will-colea
Copy link
Author

I got this to work. Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants