niapy
¶
niapy.runner
¶
Implementation of Runner utility class.
- class niapy.runner.Runner(dimension=10, max_evals=1000000, runs=1, algorithms='ArtificialBeeColonyAlgorithm', problems='Ackley')[source]¶
Bases:
object
Runner utility feature.
Feature which enables running multiple algorithms with multiple problems. It also support exporting results in various formats (e.g. Pandas DataFrame, JSON, Excel)
- Variables
Initialize Runner.
- Parameters
- __init__(dimension=10, max_evals=1000000, runs=1, algorithms='ArtificialBeeColonyAlgorithm', problems='Ackley')[source]¶
Initialize Runner.
niapy.task
¶
The implementation of tasks.
- class niapy.task.OptimizationType(value)[source]¶
Bases:
enum.Enum
Enum representing type of optimization.
- Variables
- MAXIMIZATION = -1.0¶
- MINIMIZATION = 1.0¶
- class niapy.task.Task(problem=None, dimension=None, lower=None, upper=None, optimization_type=OptimizationType.MINIMIZATION, repair_function=<function limit>, max_evals=inf, max_iters=inf, cutoff_value=None, enable_logging=False)[source]¶
Bases:
object
Class representing an optimization task.
- Date:
2019
- Author:
Klemen Berkovič and others
- Variables
problem (Problem) – Optimization problem.
dimension (int) – Dimension of the problem.
lower (numpy.ndarray) – Lower bounds of the problem.
upper (numpy.ndarray) – Upper bounds of the problem.
range (numpy.ndarray) – Search range between upper and lower limits.
optimization_type (OptimizationType) – Optimization type to use.
iters (int) – Number of algorithm iterations/generations.
evals (int) – Number of function evaluations.
max_iters (int) – Maximum number of algorithm iterations/generations.
max_evals (int) – Maximum number of function evaluations.
cutoff_value (float) – Reference function/fitness values to reach in optimization.
x (numpy.ndarray) – Best found individual.
x_f (float) – Best found individual function/fitness value.
Initialize task class for optimization.
- Parameters
dimension (Optional[int]) – Dimension of the problem. Will be ignored if problem is instance of the Problem class.
lower (Optional[Union[float, Iterable[float]]]) – Lower bounds of the problem. Will be ignored if problem is instance of the Problem class.
upper (Optional[Union[float, Iterable[float]]]) – Upper bounds of the problem. Will be ignored if problem is instance of the Problem class.
optimization_type (Optional[OptimizationType]) – Set the type of optimization. Default is minimization.
repair_function (Optional[Callable[[numpy.ndarray, numpy.ndarray, numpy.ndarray, Dict[str, Any]], numpy.ndarray]]) – Function for repairing individuals components to desired limits.
max_evals (Optional[int]) – Number of function evaluations.
max_iters (Optional[int]) – Number of generations or iterations.
cutoff_value (Optional[float]) – Reference value of function/fitness function.
enable_logging (Optional[bool]) – Enable/disable logging of improvements.
- __init__(problem=None, dimension=None, lower=None, upper=None, optimization_type=OptimizationType.MINIMIZATION, repair_function=<function limit>, max_evals=inf, max_iters=inf, cutoff_value=None, enable_logging=False)[source]¶
Initialize task class for optimization.
- Parameters
dimension (Optional[int]) – Dimension of the problem. Will be ignored if problem is instance of the Problem class.
lower (Optional[Union[float, Iterable[float]]]) – Lower bounds of the problem. Will be ignored if problem is instance of the Problem class.
upper (Optional[Union[float, Iterable[float]]]) – Upper bounds of the problem. Will be ignored if problem is instance of the Problem class.
optimization_type (Optional[OptimizationType]) – Set the type of optimization. Default is minimization.
repair_function (Optional[Callable[[numpy.ndarray, numpy.ndarray, numpy.ndarray, Dict[str, Any]], numpy.ndarray]]) – Function for repairing individuals components to desired limits.
max_evals (Optional[int]) – Number of function evaluations.
max_iters (Optional[int]) – Number of generations or iterations.
cutoff_value (Optional[float]) – Reference value of function/fitness function.
enable_logging (Optional[bool]) – Enable/disable logging of improvements.
- eval(x)[source]¶
Evaluate the solution A.
- Parameters
x (numpy.ndarray) – Solution to evaluate.
- Returns
Fitness/function values of solution.
- Return type
- is_feasible(x)[source]¶
Check if the solution is feasible.
- Parameters
x (Union[numpy.ndarray, Individual]) – Solution to check for feasibility.
- Returns
True if solution is in feasible space else False.
- Return type
- repair(x, rng=None)[source]¶
Repair solution and put the solution in the random position inside of the bounds of problem.
- Parameters
x (numpy.ndarray) – Solution to check and repair if needed.
rng (Optional[numpy.random.Generator]) – Random number generator.
- Returns
Fixed solution.
- Return type
numpy.ndarray