| Total Complexity | 1 |
| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import numpy as np |
||
| 2 | from gradient_free_optimizers import HillClimbingOptimizer |
||
| 3 | |||
| 4 | |||
| 5 | n_iter = 10 |
||
| 6 | |||
| 7 | |||
| 8 | def get_score(pos_new): |
||
| 9 | x1 = pos_new[0] |
||
| 10 | |||
| 11 | return -x1 * x1 |
||
| 12 | |||
| 13 | |||
| 14 | space_dim = np.array([100]) |
||
| 15 | init_positions = [np.array([10])] |
||
| 16 | |||
| 17 | |||
| 18 | opt = HillClimbingOptimizer(init_positions, space_dim, opt_para={}) |
||
| 19 | |||
| 20 | for nth_init in range(len(init_positions)): |
||
| 21 | pos_new = opt.init_pos(nth_init) |
||
| 22 | score_new = get_score(pos_new) |
||
| 23 | opt.evaluate(score_new) |
||
| 24 | |||
| 25 | |||
| 26 | for nth_iter in range(len(init_positions), n_iter): |
||
| 27 | pos_new = opt.iterate(nth_iter) |
||
| 28 | score_new = get_score(pos_new) |
||
| 29 | opt.evaluate(score_new) |
||
| 30 |