第19章ハイパーパラメータ最適化
19.2.8. Exercises19.2.8 練習問題
- The goal of this exercise is to implement the objective function for a slightly more challenging HPO problem, and to run more realistic experiments. We will use the two hidden layer MLP
DropoutMLPimplemented in Section 5.6.英語のヒント
この練習問題の目標は、少し難しいHPOの問題の目的関数を実装し、もっと現実的な実験を実行することである。5.6節で実装した、隠れ層が二つのMLPDropoutMLPを使う。- Code up the objective function, which should depend on all hyperparameters of the model and
batch_size. Usemax_epochs=50. GPUs do not help here, sonum_gpus=0. Hint: Modifyhpo_objective_lenet.英語のヒント
モデルのすべてのハイパーパラメータとbatch_sizeに依存する目的関数を書け。max_epochs=50を使え。ここではGPUは役に立たないので、num_gpus=0とする。ヒント:hpo_objective_lenetを変更せよ。 - Choose a sensible search space, where
num_hiddens_1,num_hiddens_2are integers in , and dropout values lie in , whilebatch_sizelies in . Provide code forconfig_space, using sensible distributions fromscipy.stats.英語のヒント
num_hiddens_1とnum_hiddens_2はの整数、ドロップアウトの値はの中、batch_sizeはの中にある、妥当な探索空間を選べ。scipy.statsの妥当な分布を使って、config_spaceのコードを書け。 - Run random search on this example with
number_of_trials=20and plot the results. Make sure to first evaluate the default configuration of Section 5.6, which isinitial_config = {'num_hiddens_1': 256, 'num_hiddens_2': 256, 'dropout_1': 0.5, 'dropout_2': 0.5, 'lr': 0.1, 'batch_size': 256}.英語のヒント
この例で、number_of_trials=20としてランダム探索を実行し、結果をプロットせよ。まず5.6節の既定の設定、つまりinitial_config = {'num_hiddens_1': 256, 'num_hiddens_2': 256, 'dropout_1': 0.5, 'dropout_2': 0.5, 'lr': 0.1, 'batch_size': 256}を評価するようにせよ。
- In this exercise, you will implement a new searcher (subclass of
HPOSearcher) which makes decisions based on past data. It depends on parametersprobab_local,num_init_random. Itssample_configurationmethod works as follows. For the firstnum_init_randomcalls, do the same asRandomSearcher.sample_configuration. Otherwise, with probability1 - probab_local, do the same asRandomSearcher.sample_configuration. Otherwise, pick the configuration which attained the smallest validation error so far, select one of its hyperparameters at random, and sample its value randomly like inRandomSearcher.sample_configuration, but leave all other values the same. Return this configuration, which is identical to the best configuration so far, except in this one hyperparameter.英語のヒント
この練習問題では、過去のデータにもとづいて決定を下す新しいサーチャー(HPOSearcherのサブクラス)を実装する。これはパラメータprobab_localとnum_init_randomに依存する。そのsample_configurationメソッドは次のように働く。最初のnum_init_random回の呼び出しでは、RandomSearcher.sample_configurationと同じことをする。そうでなければ、確率1 - probab_localでRandomSearcher.sample_configurationと同じことをする。そうでもなければ、これまでで最も小さい検証誤差を達成した設定を選び、そのハイパーパラメータの一つをランダムに選んで、RandomSearcher.sample_configurationと同じようにその値をランダムに抜き出すが、ほかの値はすべてそのままにする。この一つのハイパーパラメータを除けばこれまでの最良の設定と同一であるこの設定を返す。- Code up this new
LocalSearcher. Hint: Your searcher requiresconfig_spaceas argument at construction. Feel free to use a member of typeRandomSearcher. You will also have to implement theupdatemethod.英語のヒント
この新しいLocalSearcherを書け。ヒント:このサーチャーは、作るときに引数としてconfig_spaceを必要とする。RandomSearcher型のメンバーを自由に使ってよい。updateメソッドも実装しなければならない。 - Re-run the experiment from the previous exercise, but using your new searcher instead of
RandomSearcher. Experiment with different values forprobab_local,num_init_random. However, note that a proper comparison between different HPO methods requires repeating experiments several times, and ideally considering a number of benchmark tasks.英語のヒント
前の練習問題の実験を、RandomSearcherの代わりに新しいサーチャーを使って実行し直せ。probab_localとnum_init_randomの値をいろいろ変えて実験せよ。しかし、異なるHPOの方法を適切に比較するには、実験を何度も繰り返し、理想的にはいくつものベンチマークのタスクを考える必要があることに注意しよう。