Skip to content

Commit

Permalink
Merge pull request #126 from takeno1995/main
Browse files Browse the repository at this point in the history
add PIMS
  • Loading branch information
HideakiImamura authored Aug 12, 2024
2 parents 78980b3 + 3578ecc commit e833beb
Show file tree
Hide file tree
Showing 6 changed files with 692 additions and 0 deletions.
21 changes: 21 additions & 0 deletions package/samplers/gp_pims/LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Shion TAKENO

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.
71 changes: 71 additions & 0 deletions package/samplers/gp_pims/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
author: Shion TAKENO
title: Gaussian-Process Probability of Improvement from Maximum of Sample Path Sampler
description: This sampler searches for each trial based on Probability of Improvement from Maximum of Sample Path using Gaussian process.
tags: [sampler, Gaussian process]
optuna_versions: [3.6.1]
license: MIT License
---

<!--
This is an example of the frontmatters.
All columns must be string.
You can omit quotes when value types are not ambiguous.
For tags, a package placed in
- package/samplers/ must include the tag "sampler"
- package/visualilzation/ must include the tag "visualization"
- package/pruners/ must include the tag "pruner"
respectively.
---
author: Optuna team
title: My Sampler
description: A description for My Sampler.
tags: [sampler, 2nd tag for My Sampler, 3rd tag for My Sampler]
optuna_versions: [3.6.1]
license: "MIT License"
---
-->

## Class or Function Names

- PIMSSampler

## Installation

```shell
$ pip install -r requirements.txt
```

## Example

Please see example.py.

## Others

### Reference

Shion Takeno, Yu Inatsu, Masayuki Karasuyama, Ichiro Takeuchi,
Posterior Sampling-Based Bayesian Optimization with Tighter Bayesian Regret Bounds,
Proceedings of the 41st International Conference on Machine Learning, PMLR 235:47510-47534, 2024.

### Bibtex

```
@InProceedings{pmlr-v235-takeno24a,
title = {Posterior Sampling-Based {B}ayesian Optimization with Tighter {B}ayesian Regret Bounds},
author = {Takeno, Shion and Inatsu, Yu and Karasuyama, Masayuki and Takeuchi, Ichiro},
booktitle = {Proceedings of the 41st International Conference on Machine Learning},
pages = {47510--47534},
year = {2024},
editor = {Salakhutdinov, Ruslan and Kolter, Zico and Heller, Katherine and Weller, Adrian and Oliver, Nuria and Scarlett, Jonathan and Berkenkamp, Felix},
volume = {235},
series = {Proceedings of Machine Learning Research},
month = {21--27 Jul},
publisher = {PMLR},
pdf = {https://raw.githubusercontent.com/mlresearch/v235/main/assets/takeno24a/takeno24a.pdf},
url = {https://proceedings.mlr.press/v235/takeno24a.html}
}
```
4 changes: 4 additions & 0 deletions package/samplers/gp_pims/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .sampler import PIMSSampler


__all__ = ["PIMSSampler"]
37 changes: 37 additions & 0 deletions package/samplers/gp_pims/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

import numpy as np
import optuna
import optunahub


def f(x: np.ndarray) -> float:
return -np.sin(3 * np.sum(x**2)) - np.sum(x**2) ** 2 + 0.7 * np.sum(x**2)


if __name__ == "__main__":
mod = optunahub.load_module(
package="samplers/gp_pims",
)

PIMSSampler = mod.PIMSSampler

def objective(trial: optuna.Trial) -> float:
x = trial.suggest_float("x", 0, 1)
y = trial.suggest_float("y", 0, 1)
return f(np.asarray([x, y]))

search_space = {
"x": optuna.distributions.FloatDistribution(0, 1),
"y": optuna.distributions.FloatDistribution(0, 1),
}

kernel_bounds = np.array([[1e-3, 1e-3], [1e3, 1e3]])
sampler = PIMSSampler(search_space=search_space, kernel_bounds=kernel_bounds)
study = optuna.create_study(sampler=sampler, direction="maximize")
# study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=20)
# optuna.visualization.plot_optimization_history(study)

fig = optuna.visualization.plot_optimization_history(study)
fig.write_image("optuna_history.png")
18 changes: 18 additions & 0 deletions package/samplers/gp_pims/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
contourpy==1.1.0
cycler==0.11.0
Cython==3.0.0
decorator==5.1.1
fonttools==4.42.0
GPy==1.13.1
importlib-resources==6.0.1
kiwisolver==1.4.4
matplotlib==3.7.2
numpy==1.26.3
packaging==23.1
paramz==0.9.6
Pillow==10.0.0
pyparsing==3.0.9
python-dateutil==2.8.2
scipy==1.11.1
six==1.16.0
zipp==3.16.2
Loading

0 comments on commit e833beb

Please sign in to comment.