2

我正在使用 hyperopt 搜索空间以帮助调整神经网络的超参数。我正在搜索的空间是:

space = {
    'latent_dim1': hp.qloguniform('latent_dim1', np.log(30), np.log(70), 1),

    'batch_size': hp.choice('batch_size', [32, 64, 128]),

    'epochs': hp.choice('epochs', [150, 200, 250, 300]),

    'optimiser': hp.choice('optimizer', ['adam', 'rmsprop', COCOB()]),
    'learning_rates': hp.loguniform('learning_rates', np.log(0.1), np.log(0.001)),

    'loss': hp.choice('loss', ['mean_absolute_error', diff_smape]),

    'window': hp.choice('window', [True, False]),
    'window_size': hp.quniform('window_size', 13, 104, 1),

    'teacher_forcing': hp.choice('teacher_forcing', [True, False])
}

在这个空间上搜索时,经过十到二十次空间迭代,我得到以下错误:

Traceback (most recent call last):
  File "hyperparam_gru.py", line 159, in <module>
    best = fmin(seq2seq_model_gru, space, algo=tpe.suggest, max_evals=100, trials=trials)
  File "/lib/python3.6/site-packages/hyperopt/fmin.py", line 367, in fmin
    return_argmin=return_argmin,
  File "/lib/python3.6/site-packages/hyperopt/base.py", line 635, in fmin
    return_argmin=return_argmin)
  File "/lib/python3.6/site-packages/hyperopt/fmin.py", line 385, in fmin
    rval.exhaust()
  File "/lib/python3.6/site-packages/hyperopt/fmin.py", line 244, in exhaust
    self.run(self.max_evals - n_done, block_until_done=self.asynchronous)
  File "/lib/python3.6/site-packages/hyperopt/fmin.py", line 202, in run
    self.rstate.randint(2 ** 31 - 1))
  File "/lib/python3.6/site-packages/hyperopt/tpe.py", line 901, in suggest
    print_node_on_error=False)
  File "/lib/python3.6/site-packages/hyperopt/pyll/base.py", line 913, in rec_eval
    rval = scope._impls[node.name](*args, **kwargs)
  File "/lib/python3.6/site-packages/hyperopt/tpe.py", line 466, in adaptive_parzen_normal
    assert prior_sigma > 0
AssertionError

我能够搜索不太具有表现力的空间(以及其他空间):

space= {
    'latent_dim1': hp.choice('latent_dim1', [30, 50, 70, 90]),

    'batch_size': hp.choice('batch_size', [16, 32, 64, 128, 256, 512]),

    'epochs': hp.choice('epochs', [100, 150, 200, 250]),

    'optimiser': hp.choice('optimizer', ['adadelta', 'adam', 'rmsprop', COCOB()]),
    'learning_rates': hp.choice('learning_rates', [0.1, 0.01, 0.001]),

    'loss': hp.choice('loss', ['mean_absolute_error', diff_smape]),

    'window': hp.choice('window', [True, False]),
    'window_size': hp.choice('window_size', [13, 26, 39, 52, 78, 104]),

    'teacher_forcing': hp.choice('teacher_forcing', [True, False])
}

我不确定如何处理错误?理想情况下,我希望它只是省略导致问题的任何超参数组合,然后继续尝试下一个组合。然而,目前错误只是终止了程序。

4

0 回答 0