pyrimidine.misc subpackage¶
pyrimidine.misc.aco module¶
Ant Colony Optimization
Ref Blum, Christian. “Ant colony optimization: Introduction and recent trends.” Physics of Life reviews 2.4 (2005): 353-373.
- class pyrimidine.misc.aco.BaseAnt¶
Bases:
FitnessMixin- get_length(distances=None)¶
- init()¶
- move(colony=None, n_steps=1)¶
To move an ant
- Parameters:
colony (None, optional) – the population of ants
n_steps (int, optional) – the number of steps in each move
- Returns:
bool
- params = {'greedy_degree': 1, 'initial_position': None, 'move_flag': True, 'n_steps': 1, 'path': None}¶
- release_pheromone(colony)¶
- reset()¶
- class pyrimidine.misc.aco.BaseAntColony(*args, **kwargs)¶
Bases:
PopulationMixin- alias = {'ants': 'elements', 'get_worst_ants': 'get_worst_elements', 'worst_ant': 'worst_element'}¶
- apply(f, *args, **kwargs)¶
- property elements¶
- classmethod from_distances(n_ants=10, distances=None)¶
- classmethod from_positions(n_ants=10, positions=None)¶
- init()¶
- isa(cls)¶
- move(*args, **kwargs)¶
- property move_proba¶
- property n_elements¶
- params = {'alpha': 1, 'beta': 5, 'local_max_iter': 3, 'max_iter': 100, 'move_rate': 0.5, 'n_steps': 1, 'reset_rate': 0.3, 'sedimentation': 100, 'volatilization': 0.75}¶
- regester(name, key, force=True)¶
- regester_map(name, key=None, force=True)¶
- transition(*args, **kwargs)¶
The core method of the object.
This method transitions one state of the object to another state based on certain rules, such as crossing and mutating for individuals in GA, or the moving method in Simulated Annealing.
- update_pheromone()¶
- pyrimidine.misc.aco.random() x in the interval [0, 1).¶
pyrimidine.misc.ba module¶
The Bat Algorithm is a nature-inspired optimization algorithm developed by Xin-She Yang in 2010. It is based on the echolocation behavior of bats. Bats emit ultrasonic pulses and listen to the echoes to determine the distance to obstacles and the location of prey. This behavior forms the basis of the algorithm where solutions are represented as virtual bats, and their positions in the search space are adjusted iteratively to find the optimal solution.
References Gagnon, Iannick et al. “A critical analysis of the bat algorithm.” Engineering Reports 2 (2020): n. pag. Yang, Xin-She. “A New Metaheuristic Bat-Inspired Algorithm.” Nature Inspired Cooperative Strategies for Optimization (2010). Yang, Xin-She and Amir Hossein Gandomi. “Bat algorithm: a novel approach for global engineering optimization.” Engineering Computations 29 (2012): 464-483.
- class pyrimidine.misc.ba.Bat(*args, **kwargs)¶
Bases:
BaseParticlea bat is regarded as a particle
see BaseParticle
- alias = {'chromosomes': 'elements', 'n_chromosomes': 'n_elements'}¶
- apply(f, *args, **kwargs)¶
- property elements¶
- isa(cls)¶
- move()¶
- property n_elements¶
- params = {'frequency': 0.5, 'loudness': 0, 'max_iter': 100, 'pulse_rate': 0, 'scale': 0.1}¶
- property position¶
- regester(name, key, force=True)¶
- regester_map(name, key=None, force=True)¶
- property velocity¶
- class pyrimidine.misc.ba.Bats(*args, **kwargs)¶
Bases:
BasePopulation- alias = {'bats': 'elements', 'best_individual': 'best_element', 'best_individuals': 'best_elements', 'get_best_individual': 'get_best_element', 'get_best_individuals': 'get_best_elements', 'individuals': 'elements', 'n_bats': 'n_elements', 'n_individuals': 'n_elements', 'worst_individual': 'worst_element'}¶
- apply(f, *args, **kwargs)¶
- property elements¶
- init()¶
- isa(cls)¶
- property n_elements¶
- params = {'alpha': 0.95, 'gamma': 0.5, 'mate_prob': 0.75, 'max_iter': 100, 'mutate_prob': 0.2, 'pulse_rate': 0.9, 'scaling': 0.2, 'tourn_size': 5}¶
- regester(name, key, force=True)¶
- regester_map(name, key=None, force=True)¶
- transition(k)¶
Transition of the states of population. The core method of the class
It is considered to be the standard flow of the Genetic Algorithm
- pyrimidine.misc.ba.random() x in the interval [0, 1).¶
pyrimidine.misc.fa module¶
Firefly Algorithm
References Yang, X. S. (2010). “Firefly Algorithm: A New Approach for Optimization”. In Stochastic Algorithms: Foundations and Applications (pp. 169-178). Springer Berlin Heidelberg. Yang, X. S. (2013). “Nature-Inspired Metaheuristic Algorithms”. Luniver Press.
- class pyrimidine.misc.fa.BaseFirefly(*args, **kwargs)¶
Bases:
BaseParticle- alias = {'chromosomes': 'elements', 'n_chromosomes': 'n_elements'}¶
- apply(f, *args, **kwargs)¶
- property elements¶
- isa(cls)¶
- property n_elements¶
- params = {'alpha': 1, 'gamma': 1, 'max_iter': 100}¶
- random_move()¶
- regester(name, key, force=True)¶
- regester_map(name, key=None, force=True)¶
- update_vilocity(fame=None, *args, **kwargs)¶
- class pyrimidine.misc.fa.StandardFireflies¶
Bases:
PopulationMixinStarndard Firefly Algorithm
- element_class¶
alias of
BaseFirefly
- params = {'alpha': 0.2, 'beta': 1, 'gamma': 1}¶
- transition(*args, **kwargs)¶
The core method of the object.
This method transitions one state of the object to another state based on certain rules, such as crossing and mutating for individuals in GA, or the moving method in Simulated Annealing.
- pyrimidine.misc.fa.attractiveness(distance, gamma=1.0)¶
pyrimidine.misc.gsa module¶
The Gravity Searching Algorithm (GSA) is a metaheuristic optimization method that simulates the law of gravity in physics. It was introduced as a nature-inspired algorithm for solving optimization problems, particularly in continuous domains.
References 1. Rashedi, E., Nezamabadi-Pour, H., & Saryazdi, S. (2009). “GSA: A Gravitational Search Algorithm”. Information Sciences, 179(13), 2232-2248. 2. Rashedi, E., Nezamabadi-Pour, H., & Saryazdi, S. (2011). “A New Method for Solving Optimization Problems Using Gravitational Search Algorithm”. International Journal of Computer Applications, 22(8), 1-6. 3. Niazi, M., Mirjalili, S., Mirjalili, S. M., & Yang, X. S. (2016). “Enhanced Gravity Search Algorithm”. Swarm and Evolutionary Computation, 6(1), 10-21.
- class pyrimidine.misc.gsa.GravitySearch¶
Bases:
PopulationMixinStandard GSA
- Extends:
PopulationMixin
- alias = {'n_particles': 'n_elements', 'particles': 'elements'}¶
- compute_accelerate()¶
- compute_mass()¶
- default_size = 20¶
- move()¶
- params = {'attenuation_coefficient': 10, 'gravity_coefficient': 100}¶
- transition(k)¶
Transitation of the states of particles
- class pyrimidine.misc.gsa.Particle(*args, **kwargs)¶
Bases:
BaseParticleA particle in GSA
- Extends:
PolyIndividual
- Variables:
default_size {number} – one individual represented by 2 chromosomes: position and velocity phantom {Particle} – the current state of the particle moving in the solution space.
- alias = {'chromosomes': 'elements', 'n_chromosomes': 'n_elements'}¶
- apply(f, *args, **kwargs)¶
- default_size = 2¶
- element_class¶
alias of
FloatChromosome
- property elements¶
- isa(cls)¶
- move(*args, **kwargs)¶
- property n_elements¶
- params = {'accelerate': 0, 'max_iter': 100}¶
- property position¶
- regester(name, key, force=True)¶
- regester_map(name, key=None, force=True)¶
- property velocity¶
- pyrimidine.misc.gsa.random() x in the interval [0, 1).¶
pyrimidine.misc.sma module¶
Slime Mould Algorithm
- class pyrimidine.misc.sma.SlimeMould(*args, **kwargs)¶
Bases:
HOFPopulationSlime Mould Algorithm
- alias = {'best_individuals': 'best_elements', 'get_best_individual': 'get_best_element', 'get_best_individuals': 'get_best_elements', 'hof': 'hall_of_fame', 'individuals': 'elements', 'n_individuals': 'n_elements', 'worst_individual': 'worst_element'}¶
- apply(f, *args, **kwargs)¶
- approach_food(t)¶
- element_class¶
alias of
SlimyMaterial
- property elements¶
- get_ranks()¶
- isa(cls)¶
- property n_elements¶
- params = {'hof_size': 2, 'mate_prob': 0.75, 'max_iter': 100, 'mutate_prob': 0.2, 'tourn_size': 5}¶
- regester(name, key, force=True)¶
- regester_map(name, key=None, force=True)¶
- transition(t)¶
Update the hall_of_fame after each step of evolution
- class pyrimidine.misc.sma.SlimyMaterial(*args, **kwargs)¶
Bases:
BaseIndividual- alias = {'chromosomes': 'elements', 'n_chromosomes': 'n_elements'}¶
- apply(f, *args, **kwargs)¶
- approach_food(fame, direction, p, vb, vc)¶
- backup(check=True)¶
Backup the fitness and other information
- Parameters:
check (bool, optional) – check whether the fitness increases.
- copy(*args, **kwargs)¶
copy the object
- Parameters:
type – the type of new object
element_class (None, optional) – the new element_class
- Returns:
a new object copy the data but with new type
- property elements¶
- property fitness¶
- init()¶
- isa(cls)¶
- property memory¶
- property n_elements¶
- params = {'max_iter': 100}¶
- random_move()¶
- regester(name, key, force=True)¶
- regester_map(name, key=None, force=True)¶
- set_memory(**d)¶
- property solution¶
get the attribute from memory, where the best solution is stored
- pyrimidine.misc.sma.random() x in the interval [0, 1).¶
pyrimidine.misc.ssa module¶
Sparrow Search Algorithm
The framework of the SSA
Input: G: the maximum iterations PD: the number of producers SD: the number of sparrows who perceive the danger R2 : the alarm value n: the number of sparrows Initialize a population of n sparrows and define its relevant parameters. Output: Xbest, fg. while (t < G)
Rank the fitness values and find the current best individual and the current worst individual. R2 = rand(1) for i = 1 : PD
update the sparrow’s location;
- for i = (PD + 1)n
update the sparrow’s location;
- for l = 1SD
update the sparrow’s location;
Get the current new location; If the new location is better than before, update it; t = t + 1
return Xbest, fg.
References Jiankai Xuea, and Bo Shena, A novel swarm intelligence optimization approach: sparrow search algorithm.
- class pyrimidine.misc.ssa.BaseSparrow(*args, **kwargs)¶
Bases:
FloatChromosome- alias = {'chromosomes': 'elements', 'n_chromosomes': 'n_elements'}¶
- backup(check=True)¶
Backup the fitness and other information
- Parameters:
check (bool, optional) – check whether the fitness increases.
- copy(*args, **kwargs)¶
copy the object
- Parameters:
type – the type of new object
element_class (None, optional) – the new element_class
- Returns:
a new object copy the data but with new type
- property fitness¶
- init()¶
- property memory¶
- move(ST, i)¶
- params = {'max_iter': 100}¶
- set_memory(**d)¶
- property solution¶
get the attribute from memory, where the best solution is stored
- class pyrimidine.misc.ssa.Producer(*args, **kwargs)¶
Bases:
BaseSparrow- alias = {'chromosomes': 'elements', 'n_chromosomes': 'n_elements'}¶
- params = {'max_iter': 100}¶
- class pyrimidine.misc.ssa.Scrounger(*args, **kwargs)¶
Bases:
BaseSparrow- alias = {'chromosomes': 'elements', 'n_chromosomes': 'n_elements'}¶
- move(worst, producer, i)¶
- params = {'max_iter': 100}¶
- class pyrimidine.misc.ssa.StandardSparrowSearch¶
Bases:
PopulationMixinStarndard Sparrow Search Algorithm
- element_class¶
alias of
BaseSparrow
- init()¶
- params = {'PD': 0.2, 'SD': 0.2, 'ST': 0.7, 'rho': 0.001}¶
- transition(*args, **kwargs)¶
The core method of the object.
This method transitions one state of the object to another state based on certain rules, such as crossing and mutating for individuals in GA, or the moving method in Simulated Annealing.
- pyrimidine.misc.ssa.random() x in the interval [0, 1).¶