| Conditions | 4 |
| Total Lines | 55 |
| Code Lines | 44 |
| Lines | 55 |
| Ratio | 100 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # Author: Simon Blanke |
||
| 22 | if optimizers == "all": |
||
| 23 | optimizers = [ |
||
| 24 | "HillClimbing", |
||
| 25 | "StochasticHillClimbing", |
||
| 26 | "TabuSearch", |
||
| 27 | "RandomSearch", |
||
| 28 | "RandomRestartHillClimbing", |
||
| 29 | "RandomAnnealing", |
||
| 30 | "SimulatedAnnealing", |
||
| 31 | "StochasticTunneling", |
||
| 32 | "ParallelTempering", |
||
| 33 | "ParticleSwarm", |
||
| 34 | "EvolutionStrategy", |
||
| 35 | "Bayesian", |
||
| 36 | ] |
||
| 37 | |||
| 38 | eval_times = [] |
||
| 39 | total_times = [] |
||
| 40 | for run in range(runs): |
||
| 41 | |||
| 42 | eval_time = [] |
||
| 43 | total_time = [] |
||
| 44 | for optimizer in optimizers: |
||
| 45 | opt = Hyperactive(self.X, self.y, memory=False) |
||
| 46 | opt.search(self.search_config, n_iter=3, optimizer=optimizer) |
||
| 47 | |||
| 48 | eval_time.append(opt.eval_time) |
||
| 49 | total_time.append(opt.total_time) |
||
| 50 | |||
| 51 | eval_time = np.array(eval_time) |
||
| 52 | total_time = np.array(total_time) |
||
| 53 | |||
| 54 | eval_times.append(eval_time) |
||
| 55 | total_times.append(total_time) |
||
| 56 | |||
| 57 | eval_times = np.array(eval_times) |
||
| 58 | total_times = np.array(total_times) |
||
| 59 | opt_times = np.subtract(total_times, eval_times) |
||
| 60 | |||
| 61 | opt_time_mean = opt_times.mean(axis=0) |
||
| 62 | eval_time_mean = eval_times.mean(axis=0) |
||
| 63 | total_time_mean = total_times.mean(axis=0) |
||
| 64 | |||
| 65 | # opt_time_std = opt_times.std(axis=0) |
||
| 66 | # eval_time_std = eval_times.std(axis=0) |
||
| 67 | |||
| 68 | eval_time = eval_time_mean / total_time_mean |
||
| 69 | opt_time = opt_time_mean / total_time_mean |
||
| 70 | |||
| 71 | fig = go.Figure( |
||
| 72 | data=[ |
||
| 73 | go.Bar(name="Eval time", x=optimizers, y=eval_time), |
||
| 74 | go.Bar(name="Opt time", x=optimizers, y=opt_time), |
||
| 75 | ] |
||
| 76 | ) |
||
| 77 | fig.update_layout(barmode="stack") |
||
| 119 |