如何处理adaptive_parzen_normal中的Hyperopt AssertionError?

时间:2019-01-30 15:00:24

标签: python neural-network hyperparameters hyperopt

我正在使用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])
}

我不确定如何处理该错误?理想情况下,我只想忽略导致问题的超参数的任何组合,然后继续尝试下一个组合。但是,此刻错误只是终止了程序。

0 个答案:

没有答案