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
Implement partial fixed sampler. #1117
Comments
|
I think we can already perform this kind of setting by using For example, import optuna
n_trials = 10
def objective(trial):
x = trial.suggest_uniform('x', 0, 10)
y = trial.suggest_uniform('y', 0, 10)
return x ** 2 + y ** 2
study = optuna.create_study()
for _ in range(n_trials):
study.enqueue_trial({'x': 5})
study.optimize(objective, n_trials=n_trials)
for t in study.trials:
t.params['x'] == 5 |
[FYI] Let me share a prototype of the partial fixed sampler: I think it follows @keisuke-umezawa's design, but this feature can be implemented using |
This is still an open issue. I think both approaches (i.e., So, it may be better to discuss the approaches based on the concrete implementation in the PR. Maybe you can utilize my prototypical implementation if you'd like to implement class PartialFixedSampler:
def __init__(self, fixed_params, base_sampler):
self._fixed_params = fixed_params
self._base_sampler = base_sampler
def reseed_rng(self) -> None:
self._base_sampler.reseed_rng()
def infer_relative_search_space(self, study, trial):
# type: (Study, FrozenTrial) -> Dict[str, BaseDistribution]
search_space = self._base_sampler.infer_relative_search_space(study, trial)
# Remove fixed params from relative search space to return fixed values.
for name in self._fixed_params:
if name in search_space:
del search_space[name]
return search_space
def sample_independent(self, study, trial, param_name, param_distribution):
# type: (Study, FrozenTrial, str, BaseDistribution) -> float
# Fixed params will be sampled here.
if param_name in self._fixed_params:
return self._fixed_params[param_name]
return self._base_sampler.sample_independent(study, trial, param_name, param_distribution)
def sample_relative(self, study, trial, search_space):
# type: (Study, FrozenTrial, Dict[str, BaseDistribution]) -> Dict[str, float]
# Fixed params are never sampled here.
return self._base_sampler.sample_relative(study, trial, search_space) |
Related PR and issues:
|
[WIP] I'll add docstrings. Big thanks for @toshihikoyanase - san ! |
Hi @keisuke-umezawa |
@toshihikoyanase |
@norihitoishida Thank you for letting me know. I'll close this issue. @keisuke-umezawa Please feel free to re-open it if you have further comments. |
Motivation
Sometimes, when we try an experiment again, we want to override some parameters by fixed values.
e.g.
Description
I would like to propose
partial fixed sampler
to override some parameters by fixed values , because it is easy to run experiments with small code changes.I want to discuss two points here:
partial fixed sampler
is needed or not.The text was updated successfully, but these errors were encountered: