| Conditions | 2 |
| Total Lines | 62 |
| Code Lines | 46 |
| 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 | import os |
||
| 49 | def plot_search_path(optimizer_key): |
||
| 50 | opt_class, n_inits = optimizer_dict[optimizer_key] |
||
| 51 | opt = opt_class(search_space) |
||
| 52 | |||
| 53 | opt.search( |
||
| 54 | objective_function, |
||
| 55 | n_iter=50, |
||
| 56 | random_state=0, |
||
| 57 | memory=False, |
||
| 58 | verbosity={"progress_bar": True, "print_results": False}, |
||
| 59 | initialize={"vertices": n_inits}, |
||
| 60 | ) |
||
| 61 | |||
| 62 | optimizers = opt.optimizers |
||
| 63 | |||
| 64 | print(optimizers, "\n") |
||
| 65 | |||
| 66 | plt.figure(figsize=(5.5, 4.7)) |
||
| 67 | plt.set_cmap("jet") |
||
| 68 | |||
| 69 | for n, opt_ in enumerate(optimizers): |
||
| 70 | pos_list = np.array(opt_.pos_new_list) |
||
| 71 | score_list = np.array(opt_.score_new_list) |
||
| 72 | |||
| 73 | # print("\npos_list\n", pos_list, "\n", len(pos_list)) |
||
| 74 | # print("score_list\n", score_list, "\n", len(score_list)) |
||
| 75 | |||
| 76 | plt.plot( |
||
| 77 | pos_list[:, 0], |
||
| 78 | pos_list[:, 1], |
||
| 79 | linestyle="--", |
||
| 80 | marker=",", |
||
| 81 | color="black", |
||
| 82 | alpha=0.33, |
||
| 83 | label=n, |
||
| 84 | ) |
||
| 85 | plt.scatter( |
||
| 86 | pos_list[:, 0], |
||
| 87 | pos_list[:, 1], |
||
| 88 | c=score_list, |
||
| 89 | marker="H", |
||
| 90 | s=5, |
||
| 91 | vmin=-1000, |
||
| 92 | vmax=0, |
||
| 93 | label=n, |
||
| 94 | ) |
||
| 95 | |||
| 96 | plt.xlabel("X") |
||
| 97 | plt.ylabel("Y") |
||
| 98 | |||
| 99 | plt.xlim((0, 200)) |
||
| 100 | plt.ylim((0, 200)) |
||
| 101 | plt.colorbar() |
||
| 102 | # plt.legend(loc="upper left") |
||
| 103 | |||
| 104 | plt.tight_layout() |
||
| 105 | plt.savefig( |
||
| 106 | os.path.abspath(os.path.dirname(__file__)) |
||
| 107 | + "/plots/temp/" |
||
| 108 | + optimizer_key |
||
| 109 | + "_path.png", |
||
| 110 | dpi=400, |
||
| 111 | ) |
||
| 117 |