Skip to content

Explanation of the algorithm

RH12503 edited this page Apr 12, 2021 · 5 revisions

Triangula uses a modified genetic algorithm to triangulate images. The algorithm is very similar to an asexual genetic algorithm, but has an extra step at the end where all beneficial mutations found are combined. The process is relatively simple to understand, and is broken down into a few steps below.

Step 1: Creating a new generation

The algorithm starts off by populating the current generation with new members. At the start of each generation, there needs to be an old generation with its fitnesses calculated.

Firstly, a set number of members from the old generation with the highest fitnesses are added to the current generation with no mutations. The number is the algorithm's cutoff value, and these members are known as the base members. An equal number of spots are reserved at the end of the population for reasons explained later.

Then, the rest of the population is filled with copies of the base members. There is an equal number of copies of each base member. If member x is a copy of base member y, base member y is referred to as the base of member x. These copies are all mutated by randomly changing the coordinates of some points. The algorithm keeps track of all mutations made by adding each mutation to a data structure.

Step 2: Calculating fitnesses

Next, the fitnesses of each member from the newly filled generation are calculated. The algorithm creates a Goroutine for each member that calculates the member’s fitness.

When a fitness is calculated, the algorithm stores the new fitness. If the fitness of the member is higher than the fitness of the base of that member, the member is marked as having beneficial mutations.

Step 3: Combining mutations

Now, for each base member, there should be copies of that base member marked as having beneficial mutations. One more copy of each base member is created and added to the end of the population.

For each new copy of a base member created, the algorithm iterates through members with the same base marked as having beneficial mutations and mutates the new copy with all of the beneficial mutations. The fitnesses of these new copies are evaluated and stored in the algorithm.

Step 4: Updating fitnesses

Lastly, in preparation for the next generation, all of the members of the current generation are sorted by fitness.

Clone this wiki locally