| Total Complexity | 1 |
| Total Lines | 35 |
| Duplicated Lines | 31.43 % |
| 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 | """Test module for verbose output functionality.""" |
||
| 2 | |||
| 3 | import sys |
||
| 4 | |||
| 5 | import numpy as np |
||
| 6 | |||
| 7 | from hyperactive import Hyperactive |
||
| 8 | |||
| 9 | |||
| 10 | View Code Duplication | def ackley_function(para): |
|
|
|
|||
| 11 | """Ackley optimization function for testing.""" |
||
| 12 | x, y = para["x"], para["y"] |
||
| 13 | |||
| 14 | loss = ( |
||
| 15 | -20 * np.exp(-0.2 * np.sqrt(0.5 * (x * x + y * y))) |
||
| 16 | - np.exp(0.5 * (np.cos(2 * np.pi * x) + np.cos(2 * np.pi * y))) |
||
| 17 | + np.exp(1) |
||
| 18 | + 20 |
||
| 19 | ) |
||
| 20 | |||
| 21 | return -loss |
||
| 22 | |||
| 23 | |||
| 24 | search_space = { |
||
| 25 | "x": list(np.arange(-10, 10, 0.01)), |
||
| 26 | "y": list(np.arange(-10, 10, 0.01)), |
||
| 27 | } |
||
| 28 | |||
| 29 | |||
| 30 | hyper = Hyperactive() |
||
| 31 | hyper.add_search(ackley_function, search_space, n_iter=30, memory=True) |
||
| 32 | hyper.run() |
||
| 33 | |||
| 34 | sys.stdout.flush() |
||
| 35 |