moptipy.algorithms.so.fitnesses package

Fitness assignment processes.

Fitness assignment processes are modules of the fully-configurable Evolutionary Algorithm GeneralEA. The transform objective values to scalar fitness values that are then used by Selection algorithms.

Submodules

moptipy.algorithms.so.fitnesses.direct module

Direct fitness assignment uses the objective values directly as fitness.

Together with fitness proportionate selection (FitnessProportionateSUS), it turns an EA (GeneralEA) to a minimization variant of the traditional Genetic Algorithms.

  1. John Henry Holland. Adaptation in Natural and Artificial Systems: An Introductory Analysis with Applications to Biology, Control, and Artificial Intelligence. Ann Arbor, MI, USA: University of Michigan Press. 1975. ISBN: 0-472-08460-7

  2. David Edward Goldberg. Genetic Algorithms in Search, Optimization, and Machine Learning. Boston, MA, USA: Addison-Wesley Longman Publishing Co., Inc. 1989. ISBN: 0-201-15767-5

class moptipy.algorithms.so.fitnesses.direct.Direct[source]

Bases: Fitness

Objective values are used as fitness directly.

This is the most primitive and basic fitness assignment strategy. It does not give preference to new solutions over old solutions if both have the same objective value. In this, it is different from RankAndIteration, which is the default fitness assignment strategy. It is therefore also not compatible to our basic (mu+lambda) Evolutionary Algorithm implementation (EA).

assign_fitness(p, random)[source]

Assign the objective value as fitness.

Parameters:
Return type:

None

moptipy.algorithms.so.fitnesses.rank module

A fitness representing the rank of a solution based on its quality.

First, all solutions are sorted based on their objective values. Then, they receive their rank, i.e., index+1 in the sorted list, as fitness. If two elements have the same objective value, they also receive the same rank. This rank will be the index+1 of the first element.

>>> # The first value in FRecord(x, y) is the solution, which is not matter
>>> # here. The second value is the objective value used for ranking.
>>> l = [FRecord(1, 10), FRecord(2, 3), FRecord(3, 3), FRecord(4, 2)]
>>> from numpy.random import default_rng
>>> Rank().assign_fitness(l, default_rng())
>>> for z in l:
...     print(f"x={z.x}, fitness={z.fitness}")
x=4, fitness=1
x=2, fitness=2
x=3, fitness=2
x=1, fitness=4

Together with fitness proportionate selection (FitnessProportionateSUS), it works very similar to linear ranking selection in an EA (GeneralEA).

  1. L. Darrell Whitley. The GENITOR Algorithm and Selection Pressure: Why Rank-Based Allocation of Reproductive Trials is Best. In J. David Schaffer, ed., Proceedings of the 3rd International Conference on Genetic Algorithms (ICGA’89), June 4-7, 1989, Fairfax, VA, USA, pages 116-121. San Francisco, CA, USA: Morgan Kaufmann Publishers Inc. ISBN: 1-55860-066-3 https://www.researchgate.net/publication/2527551

  2. Tobias Blickle and Lothar Thiele. A Comparison of Selection Schemes used in Genetic Algorithms. Second edition, December 1995. TIK-Report 11 from the Eidgenössische Technische Hochschule (ETH) Zürich, Department of Electrical Engineering, Computer Engineering and Networks Laboratory (TIK), Zürich, Switzerland. ftp://ftp.tik.ee.ethz.ch/pub/publications/TIK-Report11.ps

class moptipy.algorithms.so.fitnesses.rank.Rank[source]

Bases: Fitness

A fitness computing the rank of an individual based on its quality.

assign_fitness(p, random)[source]

Assign the rank as fitness.

Parameters:
Return type:

None

>>> l = [FRecord(0, 10), FRecord(1, 5), FRecord(2, 5), FRecord(3, -1)]
>>> from numpy.random import default_rng
>>> Rank().assign_fitness(l, default_rng())
>>> l[0].x
3
>>> l[0].fitness
1
>>> l[1].x
1
>>> l[1].fitness
2
>>> l[2].x
2
>>> l[2].fitness
2
>>> l[3].x
0
>>> l[3].fitness
4

moptipy.algorithms.so.fitnesses.rank_and_iteration module

A fitness combining the rank of a solution with the iteration of its creation.

This fitness assignment process is compatible with the simple (mu+lambda) Evolutionary Algorithm implemented in EA. It will assign a better fitness to a solution which has a better objective value. Ties will be broken based on the iteration counter it of the solution records Record.

class moptipy.algorithms.so.fitnesses.rank_and_iteration.RankAndIteration[source]

Bases: Fitness

A fitness joining objective rank and creation iteration.

The fitness assignment strategy will use two pieces of information to determine the fitness of a solution:

  1. the rank the solutions by their objective values (f). If two solutions have the same fitness, they get the same rank, but the next-worst solution will then get a rank with is larger by 2.

  2. the iteration index (it) relative to the maximum and minimum iteration index.

It will multiply the rank of the solution with the range of the iteration index in the population and then add the maximum iteration index minus the iteration index of the solution, i.e.,

fitness(x) = rank(f(x)) * (max_it - min_it + 1) + (max_it - it(x))

This way, better solutions receive better fitness and ties are broken such that younger solutions (with higher iteration index) are preferred. In combination with best selection (moptipy.algorithms.modules.selections.best.Best), this replicates the behavior of our simple (mu+lambda) Evolutionary Algorithm (EA).

assign_fitness(p, random)[source]

Assign the rank and iteration fitness.

Parameters:
Return type:

None