Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use MerCBO for a custom dataset? #1

Open
fipeop opened this issue Oct 8, 2021 · 3 comments
Open

How to use MerCBO for a custom dataset? #1

fipeop opened this issue Oct 8, 2021 · 3 comments

Comments

@fipeop
Copy link

fipeop commented Oct 8, 2021

Thanks for the great work with MerCBO.

I want to use it for a custom dataset, in which I would like to have:

  1. Initialize the model with custom X and Y values and specific discrete space.
  2. An external function, so I need to run an iteration of BO at a time, evaluate an external function (a physical experiment) and then update the model.
    Thanks
@aryandeshwal
Copy link
Owner

aryandeshwal commented Oct 8, 2021

Thank you for your interest!

main.py file contains the main interface to the code and it invokes objective functions based on a format similar to the files inMerCBO/MerCBO/experiments directory. I think labs.py is the easiest example to look at.

In order to use a custom dataset, please follow steps given below:

  • Create a file in the MerCBO/MerCBO/experiments (let say custom_dataset.py) with a class (let say class Custom_Dataset)

    • The class needs to have an evaluate method that takes an input (torch tensor) and returns the output (torch tensor). You can call your custom external function here.
    • In the __init__ method of the class:
      • self.n_vertices is a list of size equal to the input dimension. For example, since the input dimension in LABS is 40, self.n_vertices is set to np.array([[2] * 40]) (2 just signifies that each variable has 2 choices).
      • self.suggested_init is where the initial X for the model are sampled randomly. It is called in line 61 of main.py to initialize the model. You can define your custom values for x in self.suggested_init.
      • Just copy the rest from labs.py __init__ from line 20 to line 31 in the __init__ of your new class.
  • In the main.py file

    • import your new class from MerCBO.experiments.test_functions.custom_dataset import Custom_Dataset.
    • pass an object of your class to kwag_['objective'] similar to line 170 before calling MerCBO method in line 173.

I think everything else should run fine once you make these changes. Please let me know if it doesn't and I will try to provide more pointers.

@fipeop
Copy link
Author

fipeop commented Oct 11, 2021

Thank you, I will give it a try later this week and let you know.

Is batch optimization possible or this is legacy code from COMBO? i.e. suggesting more than 1 sample by iteration?

@aryandeshwal
Copy link
Owner

Batch optimization is also possible with parallel thompson sampling. I can provide a batch version if you need. Please let me know. Thanks!

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

No branches or pull requests

2 participants