| Total Complexity | 1 |
| Total Lines | 30 |
| Duplicated Lines | 36.67 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | import sys |
||
| 2 | import numpy as np |
||
| 3 | from hyperactive import Hyperactive |
||
| 4 | |||
| 5 | |||
| 6 | View Code Duplication | def ackley_function(para): |
|
|
|
|||
| 7 | x, y = para["x"], para["y"] |
||
| 8 | |||
| 9 | loss = ( |
||
| 10 | -20 * np.exp(-0.2 * np.sqrt(0.5 * (x * x + y * y))) |
||
| 11 | - np.exp(0.5 * (np.cos(2 * np.pi * x) + np.cos(2 * np.pi * y))) |
||
| 12 | + np.exp(1) |
||
| 13 | + 20 |
||
| 14 | ) |
||
| 15 | |||
| 16 | return -loss |
||
| 17 | |||
| 18 | |||
| 19 | search_space = { |
||
| 20 | "x": list(np.arange(-10, 10, 0.01)), |
||
| 21 | "y": list(np.arange(-10, 10, 0.01)), |
||
| 22 | } |
||
| 23 | |||
| 24 | |||
| 25 | hyper = Hyperactive() |
||
| 26 | hyper.add_search(ackley_function, search_space, n_iter=30, memory=True) |
||
| 27 | hyper.run() |
||
| 28 | |||
| 29 | sys.stdout.flush() |
||
| 30 |