def setParameters(self, F=0.9, CR=0.85, CrossMutt=CrossBest1, **ukwargs): r"""Set core parameters of HybridBatAlgorithm algorithm. Arguments: F (Optional[float]): Scaling factor for local search. CR (Optional[float]): Probability of crossover for local search. 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. ukwargs (Dict[str, Any]): Additional arguments. See Also: * :func:`NiaPy.algorithms.basic.BatAlgorithm.setParameters` """ SelfAdaptiveBatAlgorithm.setParameters(self, **ukwargs) self.F, self.CR, self.CrossMutt = F, CR, CrossMutt
def getParameters(self): r"""Get parameters of the algorithm. Returns: Dict[str, Any]: Parameters of the algorithm. See Also: * :func:`NiaPy.algorithms.modified.AdaptiveBatAlgorithm.getParameters` """ d = SelfAdaptiveBatAlgorithm.getParameters(self) d.update({'F': self.F, 'CR': self.CR}) return d
def typeParameters(): r"""Get dictionary with functions for checking values of parameters. Returns: Dict[str, Callable]: Additional arguments. See Also: * :func:`NiaPy.algorithms.basic.BatAlgorithm.typeParameters` """ d = SelfAdaptiveBatAlgorithm.typeParameters() d.update({ 'F': lambda x: isinstance(x, (int, float)) and x > 0, 'CR': lambda x: isinstance(x, float) and 0 <= x <= 1 }) return d
# encoding=utf8 # This is temporary fix to import module from parent folder # It will be removed when package is published on PyPI import sys sys.path.append('../') # End of fix from NiaPy.algorithms.modified import SelfAdaptiveBatAlgorithm from NiaPy.task import StoppingTask from NiaPy.benchmarks import Griewank # we will run Bat Algorithm for 5 independent runs algo = SelfAdaptiveBatAlgorithm() for i in range(5): task = StoppingTask(D=10, nGEN=10000, benchmark=Griewank(Lower=-600, Upper=600)) best = algo.run(task) print('%s -> %s' % (best[0], best[1])) print(algo.getParameters()) # vim: tabstop=3 noexpandtab shiftwidth=3 softtabstop=3