Comments (2)
Could you explain how to group the params?
from optuna.
您能解释一下如何对参数进行分组吗?
I found I can do this with a callback func and a wrapper by using user_attrs.
import optuna
from typing import Any, Dict, Callable
def create_best_param_dict(study: optuna.Study, trial: optuna.Trial) -> None:
if study.best_trial:
best_params = study.best_trial.params
groups: Dict[str, Any] = study.best_trial.user_attrs.get("groups", {})
best_param_dict = {}
for group_name, param_names in groups.items():
best_param_dict[group_name] = {
param_name: best_params[param_name] for param_name in param_names
}
study.set_user_attr("best_param_dict", best_param_dict)
def trial_suggest_wrapper(
group_name: str, suggest_func: Callable, name: str, **kwargs: Any
) -> Any:
trial:optuna.Trial = suggest_func.__self__
if "groups" not in trial.user_attrs:
trial.set_user_attr("groups", {})
groups = trial.user_attrs["groups"]
if group_name not in groups:
groups[group_name] = []
groups[group_name].append(name)
trial.set_user_attr("groups", groups)
return suggest_func(name=name, **kwargs)
def objective(trial: optuna.Trial) -> float:
x = trial_suggest_wrapper(
group_name="group1", suggest_func=trial.suggest_float, name="x", low=0, high=10
)
y = trial_suggest_wrapper(
group_name="group2", suggest_func=trial.suggest_float, name="y", low=0, high=10
)
return (x - 2) ** 2 + (y - 2) ** 2
study = optuna.create_study(direction="minimize")
study.optimize(objective, n_trials=100, callbacks=[create_best_param_dict])
best_param_dict: Dict[str, Any] = study.user_attrs.get("best_param_dict", {})
print(best_param_dict)
from optuna.
Related Issues (20)
- Custom Executor Support HOT 1
- trial.suggest_float doesn't work properly. HOT 1
- while opptimizing hyperparameter with optuna I get stuck in first trial and the trial 0 is not terminated
- Optuna restrict to only to the first trial and display it as the best one HOT 1
- Cannot build the document on Mac HOT 1
- With very short heartbeat, not only trials may fail but also the whole process crushes
- TypeError if both storage and WilcoxonPruner are given to create_study HOT 4
- Why is optuna stressing my CPU instead of GPU when device is set to "cuda"?
- ModuleNotFoundError: No module named 'MySQLdb'
- Speed up `TPESampler` using approximation in standard normal related computation
- Unable to use Redis: AttributeError: 'JournalRedisStorage' object has no attribute 'create_new_study' HOT 2
- Conda package not updated HOT 3
- Specify the removing version on `convert_positional_args`
- GridSampler: Duplicates HOT 5
- Wrong testing in tests with minimum versions
- Any bugs when using NumPy v2.0.0 HOT 2
- Expand the type of `callbacks` in `optimize` to `Iterable` HOT 2
- Fix http links underscore HOT 2
- Why does ` CmaEsSampler` expect at least 2D continuous space?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from optuna.