Conditions | 1 |
Total Lines | 64 |
Code Lines | 50 |
Lines | 64 |
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 |
||
93 | View Code Duplication | def test_start_temp_1(): |
|
94 | n_initialize = 1 |
||
95 | |||
96 | start_temp_0 = 0 |
||
97 | start_temp_1 = 0.1 |
||
98 | start_temp_10 = 1 |
||
99 | start_temp_100 = 100 |
||
100 | start_temp_inf = np.inf |
||
101 | |||
102 | epsilon = 0.03 |
||
103 | |||
104 | opt = SimulatedAnnealingOptimizer( |
||
105 | search_space, |
||
106 | start_temp=start_temp_0, |
||
107 | epsilon=epsilon, |
||
108 | initialize={"random": n_initialize}, |
||
109 | ) |
||
110 | opt.search(objective_function, n_iter=n_iter) |
||
111 | n_transitions_0 = opt.n_transitions |
||
112 | |||
113 | opt = SimulatedAnnealingOptimizer( |
||
114 | search_space, |
||
115 | start_temp=start_temp_1, |
||
116 | epsilon=epsilon, |
||
117 | initialize={"random": n_initialize}, |
||
118 | ) |
||
119 | opt.search(objective_function, n_iter=n_iter) |
||
120 | n_transitions_1 = opt.n_transitions |
||
121 | |||
122 | opt = SimulatedAnnealingOptimizer( |
||
123 | search_space, |
||
124 | start_temp=start_temp_10, |
||
125 | epsilon=epsilon, |
||
126 | initialize={"random": n_initialize}, |
||
127 | ) |
||
128 | opt.search(objective_function, n_iter=n_iter) |
||
129 | n_transitions_10 = opt.n_transitions |
||
130 | |||
131 | opt = SimulatedAnnealingOptimizer( |
||
132 | search_space, |
||
133 | start_temp=start_temp_100, |
||
134 | epsilon=epsilon, |
||
135 | initialize={"random": n_initialize}, |
||
136 | ) |
||
137 | opt.search(objective_function, n_iter=n_iter) |
||
138 | n_transitions_100 = opt.n_transitions |
||
139 | |||
140 | opt = SimulatedAnnealingOptimizer( |
||
141 | search_space, |
||
142 | start_temp=start_temp_inf, |
||
143 | epsilon=epsilon, |
||
144 | initialize={"random": n_initialize}, |
||
145 | ) |
||
146 | opt.search(objective_function, n_iter=n_iter) |
||
147 | n_transitions_inf = opt.n_transitions |
||
148 | |||
149 | print("\n n_transitions_0", n_transitions_0) |
||
150 | print("\n n_transitions_1", n_transitions_1) |
||
151 | print("\n n_transitions_10", n_transitions_10) |
||
152 | print("\n n_transitions_100", n_transitions_100) |
||
153 | print("\n n_transitions_inf", n_transitions_inf) |
||
154 | |||
155 | assert n_transitions_0 == start_temp_0 |
||
156 | assert n_transitions_1 < n_transitions_10 < n_transitions_100 < n_transitions_inf |
||
157 | |||
212 |