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.
-
run
(export='dataframe', verbose=False)[source]¶ Execute runner.
- Parameters
export (str) – Takes export type (e.g. dataframe, json, xls, xlsx) (default: “dataframe”)
verbose (bool) – Switch for verbose logging (default: {False})
- Returns
Returns dictionary of results
- Return type
dict
- Raises
TypeError – Raises TypeError if export type is not supported
niapy.task
¶
The implementation of tasks.
-
class
niapy.task.
OptimizationType
(value)[source]¶ Bases:
enum.Enum
Enum representing type of optimization.
- Variables
MINIMIZATION (int) – Represents minimization problems and is default optimization type of all algorithms.
MAXIMIZATION (int) – Represents maximization problems.
-
MAXIMIZATION
= -1.0¶
-
MINIMIZATION
= 1.0¶
-
class
niapy.task.
Task
(problem=None, dimension=None, lower=None, upper=None, optimization_type=<OptimizationType.MINIMIZATION: 1.0>, 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_f (float) – Best found individual function/fitness value.
Initialize task class for optimization.
- Parameters
problem (Union[str, Problem]) – Optimization problem.
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: 1.0>, repair_function=<function limit>, max_evals=inf, max_iters=inf, cutoff_value=None, enable_logging=False)[source]¶ Initialize task class for optimization.
- Parameters
problem (Union[str, Problem]) – Optimization problem.
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
float
-
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
bool
-
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
-
return_conv
()[source]¶ Get values of x and y axis for plotting covariance graph.
- Returns
List of ints of function evaluations.
List of ints of function/fitness values.
- Return type
Tuple[List[int], List[float]]