@@ 13-99 (lines=87) @@ | ||
10 | ||
11 | __all__ = ['HybridSelfAdaptiveBatAlgorithm'] |
|
12 | ||
13 | class HybridSelfAdaptiveBatAlgorithm(SelfAdaptiveBatAlgorithm): |
|
14 | r"""Implementation of Hybrid self adaptive bat algorithm. |
|
15 | ||
16 | Algorithm: |
|
17 | Hybrid self adaptive bat algorithm |
|
18 | ||
19 | Date: |
|
20 | April 2019 |
|
21 | ||
22 | Author: |
|
23 | Klemen Berkovič |
|
24 | ||
25 | License: |
|
26 | MIT |
|
27 | ||
28 | Reference paper: |
|
29 | Fister, Iztok, Simon Fong, and Janez Brest. "A novel hybrid self-adaptive bat algorithm." The Scientific World Journal 2014 (2014). |
|
30 | ||
31 | Reference URL: |
|
32 | https://www.hindawi.com/journals/tswj/2014/709738/cta/ |
|
33 | ||
34 | Attributes: |
|
35 | Name (List[str]): List of strings representing algorithm name. |
|
36 | F (float): Scaling factor for local search. |
|
37 | CR (float): Probability of crossover for local search. |
|
38 | CrossMutt (Callable[[numpy.ndarray, int, numpy.ndarray, float, float, mtrand.RandomState, Dict[str, Any]): Local search method based of Differential evolution strategy. |
|
39 | ||
40 | See Also: |
|
41 | * :class:`NiaPy.algorithms.basic.BatAlgorithm` |
|
42 | """ |
|
43 | Name = ['HybridSelfAdaptiveBatAlgorithm', 'HSABA'] |
|
44 | ||
45 | @staticmethod |
|
46 | def algorithmInfo(): |
|
47 | r"""Get basic information about the algorithm. |
|
48 | ||
49 | Returns: |
|
50 | str: Basic information. |
|
51 | """ |
|
52 | return r"""Fister, Iztok, Simon Fong, and Janez Brest. "A novel hybrid self-adaptive bat algorithm." The Scientific World Journal 2014 (2014).""" |
|
53 | ||
54 | @staticmethod |
|
55 | def typeParameters(): |
|
56 | r"""Get dictionary with functions for checking values of parameters. |
|
57 | ||
58 | Returns: |
|
59 | Dict[str, Callable]: Additional arguments. |
|
60 | ||
61 | See Also: |
|
62 | * :func:`NiaPy.algorithms.basic.BatAlgorithm.typeParameters` |
|
63 | """ |
|
64 | d = SelfAdaptiveBatAlgorithm.typeParameters() |
|
65 | d.update({ |
|
66 | 'F': lambda x: isinstance(x, (int, float)) and x > 0, |
|
67 | 'CR': lambda x: isinstance(x, float) and 0 <= x <= 1 |
|
68 | }) |
|
69 | return d |
|
70 | ||
71 | def setParameters(self, F=3, CR=0.5, CrossMutt=CrossBest1, **ukwargs): |
|
72 | r"""Set core parameters of HybridBatAlgorithm algorithm. |
|
73 | ||
74 | Arguments: |
|
75 | F (Optional[float]): Scaling factor for local search. |
|
76 | CR (Optional[float]): Probability of crossover for local search. |
|
77 | CrossMutt (Optional[Callable[[numpy.ndarray, int, numpy.ndarray, float, float, mtrand.RandomState, Dict[str, Any], numpy.ndarray]]): Local search method based of Differential evolution strategy. |
|
78 | ukwargs (Dict[str, Any]): Additional arguments. |
|
79 | ||
80 | See Also: |
|
81 | * :func:`NiaPy.algorithms.basic.BatAlgorithm.setParameters` |
|
82 | """ |
|
83 | SelfAdaptiveBatAlgorithm.setParameters(self, **ukwargs) |
|
84 | self.F, self.CR, self.CrossMutt = F, CR, CrossMutt |
|
85 | ||
86 | def localSearch(self, best, A, i, Sol, task, **kwargs): |
|
87 | r"""Improve the best solution. |
|
88 | ||
89 | Args: |
|
90 | best (numpy.ndarray): Global best individual. |
|
91 | task (Task): Optimization task. |
|
92 | i (int): Index of current individual. |
|
93 | Sol (numpy.ndarray): Current best population. |
|
94 | **kwargs (Dict[str, Any]): |
|
95 | ||
96 | Returns: |
|
97 | numpy.ndarray: New solution based on global best individual. |
|
98 | """ |
|
99 | return task.repair(self.CrossMutt(Sol, i, best, self.F, self.CR, rnd=self.Rand), rnd=self.Rand) |
|
100 | ||
101 | # vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3 |
|
102 |
@@ 13-95 (lines=83) @@ | ||
10 | ||
11 | __all__ = ['HybridBatAlgorithm'] |
|
12 | ||
13 | class HybridBatAlgorithm(BatAlgorithm): |
|
14 | r"""Implementation of Hybrid bat algorithm. |
|
15 | ||
16 | Algorithm: |
|
17 | Hybrid bat algorithm |
|
18 | ||
19 | Date: |
|
20 | 2018 |
|
21 | ||
22 | Author: |
|
23 | Grega Vrbancic and Klemen Berkovič |
|
24 | ||
25 | License: |
|
26 | MIT |
|
27 | ||
28 | Reference paper: |
|
29 | Fister Jr., Iztok and Fister, Dusan and Yang, Xin-She. "A Hybrid Bat Algorithm". Elektrotehniski vestnik, 2013. 1-7. |
|
30 | ||
31 | Attributes: |
|
32 | Name (List[str]): List of strings representing algorithm name. |
|
33 | F (float): Scaling factor. |
|
34 | CR (float): Crossover. |
|
35 | ||
36 | See Also: |
|
37 | * :class:`NiaPy.algorithms.basic.BatAlgorithm` |
|
38 | """ |
|
39 | Name = ['HybridBatAlgorithm', 'HBA'] |
|
40 | ||
41 | @staticmethod |
|
42 | def algorithmInfo(): |
|
43 | r"""Get basic information about the algorithm. |
|
44 | ||
45 | Returns: |
|
46 | str: Basic information. |
|
47 | """ |
|
48 | return r"""Fister Jr., Iztok and Fister, Dusan and Yang, Xin-She. "A Hybrid Bat Algorithm". Elektrotehniski vestnik, 2013. 1-7.""" |
|
49 | ||
50 | @staticmethod |
|
51 | def typeParameters(): |
|
52 | r"""Get dictionary with functions for checking values of parameters. |
|
53 | ||
54 | Returns: |
|
55 | Dict[str, Callable]: |
|
56 | * F (Callable[[Union[int, float]], bool]): Scaling factor. |
|
57 | * CR (Callable[[float], bool]): Crossover probability. |
|
58 | ||
59 | See Also: |
|
60 | * :func:`NiaPy.algorithms.basic.BatAlgorithm.typeParameters` |
|
61 | """ |
|
62 | d = BatAlgorithm.typeParameters() |
|
63 | d.update({ |
|
64 | 'F': lambda x: isinstance(x, (int, float)) and x > 0, |
|
65 | 'CR': lambda x: isinstance(x, float) and 0 <= x <= 1 |
|
66 | }) |
|
67 | return d |
|
68 | ||
69 | def setParameters(self, F=0.50, CR=0.90, CrossMutt=CrossBest1, **ukwargs): |
|
70 | r"""Set core parameters of HybridBatAlgorithm algorithm. |
|
71 | ||
72 | Arguments: |
|
73 | F (Optional[float]): Scaling factor. |
|
74 | CR (Optional[float]): Crossover. |
|
75 | ||
76 | See Also: |
|
77 | * :func:`NiaPy.algorithms.basic.BatAlgorithm.setParameters` |
|
78 | """ |
|
79 | BatAlgorithm.setParameters(self, **ukwargs) |
|
80 | self.F, self.CR, self.CrossMutt = F, CR, CrossMutt |
|
81 | ||
82 | def localSearch(self, best, task, i, Sol, **kwargs): |
|
83 | r"""Improve the best solution. |
|
84 | ||
85 | Args: |
|
86 | best (numpy.ndarray): Global best individual. |
|
87 | task (Task): Optimization task. |
|
88 | i (int): Index of current individual. |
|
89 | Sol (numpy.ndarray): Current best population. |
|
90 | **kwargs (Dict[str, Any]): |
|
91 | ||
92 | Returns: |
|
93 | numpy.ndarray: New solution based on global best individual. |
|
94 | """ |
|
95 | return task.repair(self.CrossMutt(Sol, i, best, self.F, self.CR, rnd=self.Rand), rnd=self.Rand) |
|
96 | ||
97 | # vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3 |
|
98 |