Bat Algorithm
Example:
from bejoor.swarm_based import BatAlgorithm
def func(sol):
return abs((sol[0]**sol[3] + sol[1]**sol[3] - sol[2]**sol[3]))
solution_vector = [{"type": "integer", "lower_bound": 1, "upper_bound": 500}] * 3 + \
[{"type": "integer", "lower_bound": 2, "upper_bound": 100}] + \
[{"type": "float", "lower_bound": 0, "upper_bound": 1}] * 3
# without target objective value
ba= BatAlgorithm(objective_function=func, solution_vector_size=7,
solution_vector=solution_vector, optimization_side="min",
loudness=0.3, pulse_rate=0.5, min_frequency=0.0, max_frequency=2.0,
population_size=30, epochs=50)
ba.run()
print(ba.best_solution)
print(ba.best_objective_value)
Parameters:
-
objective_function
: Objective function needs to be optimized.
-
solution_vector_size
: Vector size of the candidate solutions.
-
solution_vector
: A vector which determines the types of each variable in solution vectors.
-
optimization_side
: Determines maximize or minimize the objective function.
-
target_objective_value
: Target Objective value.
-
target_objective_lower_bound
: Target Objective lower bound.
-
target_objective_upper_bound
: Target Objective upper bound.
-
population_size
: Number of individuals in the population.
-
epochs
: Number of generations to run the algorithm.
-
loudness
: The loudness parameter, controlling local search exploitation.
-
pulse_rate
: The pulse rate, controlling the probability of a bat performing a local search.
-
min_frequency
: Minimum frequency for controlling bat velocities.
-
max_frequency
: Maximum frequency for controlling bat velocities.