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

Add PLMBOSampler #83

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions package/samplers/plmbo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Ryota Ozaki

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
84 changes: 84 additions & 0 deletions package/samplers/plmbo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
author: "Ryota Ozaki"
title: "PLMBO (Preference Learning Multi-Objective Bayesian Optimization)"
description: "Interatctive multi-objective Bayesian optimization based on user preference"
tags: ["sampler", "interactive optimization", "Bayesian optimization", "multi-objective optimization", "preference learning", "active learning"]
optuna_versions: ["3.6.1"]
license: "MIT License"
---

## Class or Function Names
- PLMBOSampler

## Installation
```sh
pip install -r https://raw.githubusercontent.com/optuna/optunahub-registry/main/package/samplers/plmbo/requirements.txt
```

## Example
```python
from __future__ import annotations

import matplotlib.pyplot as plt
import optuna
import optunahub
from optuna.distributions import FloatDistribution
import numpy as np


PLMBOSampler = optunahub.load_module( # type: ignore
"samplers/plmbo",
).PLMBOSampler

if __name__ == "__main__":
f_sigma = 0.01

def obj_func1(x):
return np.sin(x[0]) + x[1]

def obj_func2(x):
return -np.sin(x[0]) - x[1] + 0.1

def obs_obj_func(x):
return np.array(
[
obj_func1(x) + np.random.normal(0, f_sigma),
obj_func2(x) + np.random.normal(0, f_sigma),
]
)

def objective(trial: optuna.Trial):
x1 = trial.suggest_float("x1", 0, 1)
x2 = trial.suggest_float("x2", 0, 1)
values = obs_obj_func(np.array([x1, x2]))
return float(values[0]), float(values[1])

sampler = PLMBOSampler(
{
"x1": FloatDistribution(0, 1),
"x2": FloatDistribution(0, 1),
}
)
study = optuna.create_study(sampler=sampler, directions=["minimize", "minimize"])
study.optimize(objective, n_trials=20)

optuna.visualization.matplotlib.plot_pareto_front(study)
plt.show()
```

## Others
### Reference
R Ozaki, K Ishikawa, Y Kanzaki, S Takeno, I Takeuchi, and M Karasuyama. (2024). Multi-Objective Bayesian Optimization with Active Preference Learning. Proceedings of the AAAI Conference on Artificial Intelligence.

### Bibtex
```
@inproceedings{ozaki2024multi,
title={Multi-Objective Bayesian Optimization with Active Preference Learning},
author={Ozaki, Ryota and Ishikawa, Kazuki and Kanzaki, Youhei and Takeno, Shion and Takeuchi, Ichiro and Karasuyama, Masayuki},
booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
volume={38},
number={13},
pages={14490--14498},
year={2024}
}
```
4 changes: 4 additions & 0 deletions package/samplers/plmbo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .plmbo import PLMBOSampler


__all__ = ["PLMBOSampler"]
48 changes: 48 additions & 0 deletions package/samplers/plmbo/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# mypy: ignore-errors
from __future__ import annotations

import matplotlib.pyplot as plt
import numpy as np
import optuna
from optuna.distributions import FloatDistribution
import optunahub


PLMBOSampler = optunahub.load_module( # type: ignore
"samplers/plmbo",
).PLMBOSampler

if __name__ == "__main__":
f_sigma = 0.01

def obj_func1(x):
return np.sin(x[0]) + x[1]

def obj_func2(x):
return -np.sin(x[0]) - x[1] + 0.1

def obs_obj_func(x):
return np.array(
[
obj_func1(x) + np.random.normal(0, f_sigma),
obj_func2(x) + np.random.normal(0, f_sigma),
]
)

def objective(trial: optuna.Trial):
x1 = trial.suggest_float("x1", 0, 1)
x2 = trial.suggest_float("x2", 0, 1)
values = obs_obj_func(np.array([x1, x2]))
return float(values[0]), float(values[1])

sampler = PLMBOSampler(
{
"x1": FloatDistribution(0, 1),
"x2": FloatDistribution(0, 1),
}
)
study = optuna.create_study(sampler=sampler, directions=["minimize", "minimize"])
study.optimize(objective, n_trials=20)

optuna.visualization.matplotlib.plot_pareto_front(study)
plt.show()
Loading