| Conditions | 1 |
| Total Lines | 15 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | """Hyperparameter optimization functionality for backends""" |
||
| 29 | def optimize(self, n_trials): |
||
| 30 | """Find the optimal hyperparameters by testing up to the given number of |
||
| 31 | hyperparameter combinations""" |
||
| 32 | |||
| 33 | self._prepare() |
||
| 34 | space = self.get_hp_space() |
||
| 35 | trials = hyperopt.Trials() |
||
| 36 | best = hyperopt.fmin( |
||
| 37 | show_progressbar=False, |
||
| 38 | fn=self._test, |
||
| 39 | space=space, |
||
| 40 | algo=hyperopt.tpe.suggest, |
||
| 41 | max_evals=n_trials, |
||
| 42 | trials=trials) |
||
| 43 | return (best, 1 - trials.best_trial['result']['loss']) |
||
| 44 | |||
| 56 |