Created
May 12, 2023 01:26
-
-
Save c-bata/fa8efc075e86a1f7e6dd6d83b85c1017 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import time | |
import optuna | |
import numpy as np | |
def objective(trial: optuna.Trial, n_params: int) -> float: | |
return sum([ | |
math.sin(trial.suggest_float('param-{}'.format(i), 0, math.pi * 2)) | |
for i in range(n_params) | |
]) | |
def main(): | |
storage_url = "mysql+pymysql://optuna:[email protected]:3306/optuna" | |
sampler = optuna.samplers.TPESampler(seed=1) | |
optuna.logging.set_verbosity(optuna.logging.ERROR) | |
for n_params in [5, 30]: | |
elapsed = [] | |
for i in range(5): | |
study = optuna.create_study(storage=storage_url, sampler=sampler) | |
start = time.time() | |
study.optimize(lambda t: objective(t, n_params=n_params), n_trials=100) | |
elapsed.append(time.time() - start) | |
optuna.delete_study(study_name=study.study_name, storage=storage_url) | |
print(f"Elapsed {n_params=}: {np.mean(elapsed):.4f} (+/- {np.std(elapsed):.4f})s", elapsed) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PR 4672
master
ee15fcc95
n_params=5
(Average Time ± Std Deviation) (s)n_params=30
(Average Time ± Std Deviation) (s)ee15fcc95