Skip to content

Commit

Permalink
Merge pull request #49 from optuna/cmaes-sampler
Browse files Browse the repository at this point in the history
Add built-in `CmaEsSampler`
  • Loading branch information
y0z authored May 24, 2024
2 parents c2b943d + f42f4fd commit 1c5049a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
21 changes: 21 additions & 0 deletions package/samplers/cmaes/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Preferred Networks, Inc.

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.
37 changes: 37 additions & 0 deletions package/samplers/cmaes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
author: 'Optuna team'
title: 'CMA-ES Sampler'
description: 'A sampler using cmaes as the backend.'
tags: ['sampler', 'built-in']
optuna_versions: ['3.6.1']
license: 'MIT License'
---

## Class or Function Names
- CmaEsSampler

## Installation
```bash
pip install cmaes
```

## Example
```python
import optuna
import optunahub


def objective(trial):
x = trial.suggest_float("x", -1, 1)
y = trial.suggest_int("y", -1, 1)
return x**2 + y


mod = optunahub.load_module("samplers/cmaes")
sampler = mod.CmaEsSampler()
study = optuna.create_study(sampler=sampler)
study.optimize(objective, n_trials=20)
```

## Others
See the [documentation](https://optuna.readthedocs.io/en/stable/reference/samplers/generated/optuna.samplers.CmaEsSampler.html) for more details.
4 changes: 4 additions & 0 deletions package/samplers/cmaes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from optuna.samplers import CmaEsSampler


__all__ = ["CmaEsSampler"]
1 change: 1 addition & 0 deletions package/samplers/cmaes/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmaes

0 comments on commit 1c5049a

Please sign in to comment.