Skip to content

Instantly share code, notes, and snippets.

@hppRC
Last active February 27, 2022 09:47
Show Gist options
  • Save hppRC/f67e8fc0f4905a7c6f03e092535dee59 to your computer and use it in GitHub Desktop.
Save hppRC/f67e8fc0f4905a7c6f03e092535dee59 to your computer and use it in GitHub Desktop.
N_TRIALS=10
STORAGE=sqlite:///example.db
STUDY_NAME=`optuna create-study --storage $STORAGE`
DISTRIBUTIONS=`cat distributions.json`
for _ in `seq 1 $N_TRIALS`; do
trial=`optuna ask \
--storage $STORAGE \
--study-name $STUDY_NAME \
--search-space "$DISTRIBUTIONS" \
--direction minimize`
x=`echo $trial | jq .params.x`
y=`echo "($x - 2) ^ 2" | bc`
number=`echo $trial | jq .number`
optuna tell \
--storage $STORAGE \
--study-name $STUDY_NAME \
--trial-number $number \
--value $y
done
optuna trials --study-name $STUDY_NAME --storage $STORAGE
optuna best-trials --study-name $STUDY_NAME --storage $STORAGE
optuna best-trial --study-name $STUDY_NAME --storage $STORAGE
@hppRC
Copy link
Author

hppRC commented Feb 27, 2022

distributions.json

{
    "x": {
        "name": "UniformDistribution",
        "attributes": {
            "low": -10.0,
            "high": 10.0
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment