hp.process函数定义
时间: 2023-10-07 22:05:11 浏览: 171
php-process
`hp.process()` 函数是 Hyperopt 库中的一个函数,用于执行一个优化过程。它的定义如下:
```python
def process(fn, space, algo, max_evals, trials, rstate, verbose=0,
catch_eval_exceptions=False, return_argmin=True,
pass_expr_memo_ctrl=None):
"""
Minimize a function over a hyperparameter space.
Parameters
----------
fn : callable
A Python callable that is the objective function. This function should
return a real-valued loss that hyperopt will seek to minimize. It should
have signature ``fn(params) -> loss`` where ``params`` is a dictionary
containing the hyperparameters to be optimized and ``loss`` is a float
value representing the objective function's value at those hyperparameters.
space : hyperopt.pyll.Apply node
A Pyll expression representing a tree of (potentially conditional)
hyperparameters to optimize.
algo : search algorithm
A search algorithm. An algorithm is an object that defines the search
strategy. It should have a ``suggest`` method that takes a number of
trials and returns a set of hyperparameters to evaluate next.
max_evals : int
The maximum number of evaluations of ``fn``.
trials : ``Trials`` object
A container for storing the details of each trial. This object defines
the interface for communicating back to hyperopt.
rstate : numpy.random.RandomState instance
A numpy RandomState instance used for random sampling.
verbose : int
Controls verbosity of output:
* 0: no output
* 1: print only status updates
* 2: print status and results
catch_eval_exceptions : bool
If True, catch exceptions thrown by the objective function and store the
traceback in the corresponding trial document.
return_argmin : bool
If True, return the hyperparameters that gave the best observed value.
Otherwise, return the full dictionary of hyperparameters and their
values for each evaluated point.
Returns
-------
results : either the best point found (if return_argmin=True) or the full
dictionary of evaluated points (if return_argmin=False).
"""
```
该函数的主要作用是最小化一个给定的目标函数 `fn`,其参数由 `space` 指定,使用一个指定的优化算法 `algo` 进行搜索,并在给定的最大评估次数 `max_evals` 之后返回结果。它还接受一个 `Trials` 对象来存储每个评估的详细信息,以及一个随机数生成器 `rstate` 来执行随机采样。函数的输出结果可以是最优点的超参数(如果 `return_argmin` 为 `True`),或者每个评估点的超参数和对应的值(如果 `return_argmin` 为 `False`)。函数还支持捕获评估函数 `fn` 抛出的异常,并将其存储在相应的评估记录中。
阅读全文