| Conditions | 4 |
| Total Lines | 55 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 21 | def plot_performance(self, runs=3, path=None, optimizers="all"): |
||
| 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 | eval_times = [] |
||
| 38 | total_times = [] |
||
| 39 | for run in range(runs): |
||
| 40 | |||
| 41 | eval_time = [] |
||
| 42 | total_time = [] |
||
| 43 | for optimizer in optimizers: |
||
| 44 | opt = Hyperactive(self.X, self.y, memory=False) |
||
| 45 | opt.search(self.search_config, n_iter=3, optimizer=optimizer) |
||
| 46 | |||
| 47 | eval_time.append(opt.eval_time) |
||
| 48 | total_time.append(opt.total_time) |
||
| 49 | |||
| 50 | eval_time = np.array(eval_time) |
||
| 51 | total_time = np.array(total_time) |
||
| 52 | |||
| 53 | eval_times.append(eval_time) |
||
| 54 | total_times.append(total_time) |
||
| 55 | |||
| 56 | eval_times = np.array(eval_times) |
||
| 57 | total_times = np.array(total_times) |
||
| 58 | opt_times = np.subtract(total_times, eval_times) |
||
| 59 | |||
| 60 | opt_time_mean = opt_times.mean(axis=0) |
||
| 61 | eval_time_mean = eval_times.mean(axis=0) |
||
| 62 | total_time_mean = total_times.mean(axis=0) |
||
| 63 | |||
| 64 | opt_time_std = opt_times.std(axis=0) |
||
| 65 | eval_time_std = eval_times.std(axis=0) |
||
| 66 | |||
| 67 | eval_time = eval_time_mean/total_time_mean |
||
| 68 | opt_time = opt_time_mean/total_time_mean |
||
| 69 | |||
| 70 | fig = go.Figure(data=[ |
||
| 71 | go.Bar(name='Eval time', x=optimizers, y=eval_time), |
||
| 72 | go.Bar(name='Opt time', x=optimizers, y=opt_time) |
||
| 73 | ]) |
||
| 74 | fig.update_layout(barmode='stack') |
||
| 75 | py.offline.plot(fig, filename="sampleplot.html") |
||
| 76 | |||
| 118 | py.offline.plot(fig, filename="search_path" + optimizer + ".html") |