プリンキピア

第19章ハイパーパラメータ最適化

19.2.1. Searcher19.2.1 サーチャー

Below we define a base class for searchers, which provides a new candidate configuration through the sample_configuration function. A simple way to implement this function would be to sample configurations uniformly at random, as we did for random search in Section 19.1. More sophisticated algorithms, such as Bayesian optimization, will make these decisions based on the performance of previous trials. As a result, these algorithms are able to sample more promising candidates over time. We add the update function in order to update the history of previous trials, which can then be exploited to improve our sampling distribution.
英語のヒント
以下では、サーチャーの基底クラスを定義する。これは、sample_configuration関数を通じて新しい候補の設定を与える。この関数を実装する簡単な方法は、19.1節でランダム探索についてしたように、設定を一様にランダムに抜き出すことだろう。ベイズ最適化のような、もっと凝ったアルゴリズムは、過去の試行の性能にもとづいてこれらの決定を下す。その結果、これらのアルゴリズムは時間とともにもっと有望な候補を抜き出せる。過去の試行の履歴を更新するためにupdate関数を加える。この履歴は、サンプリング分布を改善するのに利用できる。
class HPOSearcher(d2l.HyperParameters):  #@save
    def sample_configuration() -> dict:
        raise NotImplementedError

    def update(self, config: dict, error: float, additional_info=None):
        pass
The following code shows how to implement our random search optimizer from the previous section in this API. As a slight extension, we allow the user to prescribe the first configuration to be evaluated via initial_config, while subsequent ones are drawn at random.
英語のヒント
次のコードは、前の節のランダム探索の最適化手法をこのAPIでどう実装するかを示す。少し拡張して、利用者が最初に評価する設定をinitial_configで指定できるようにし、その後の設定はランダムに抜き出す。
class RandomSearcher(HPOSearcher):  #@save
    def __init__(self, config_space: dict, initial_config=None):
        self.save_hyperparameters()

    def sample_configuration(self) -> dict:
        if self.initial_config is not None:
            result = self.initial_config
            self.initial_config = None
        else:
            result = {
                name: domain.rvs()
                for name, domain in self.config_space.items()
            }
        return result