## Blunder Finger

> This module applies a basic genetic algorithms on the sample level. The basic ideas are described here: www.obitko.com/tutorials/genetic-algorithms/

The general algorithm follows the pattern:

- 1. [Start] Generate a random population of chromosomes (possible solutions)
- 2. [Fitness] Calculate the fitness f(x) of each of the chromosomes x of the population
- 3. [New population] Use the following steps to generate a new population:
  - a. [Selection] Choose two parent chromosomes, by weighting their chance of getting selected with the fitness (the better the fitness, the greater the chance to be selected)
  - b. [Crossover] According to a probability of crossover, mix the genes. It is possible that the offspring is a 1:1 copy of one parent.
  - c. [Mutation] According to a probability of mutation, mutate the genes at each defined Locus
  - d. [Accepting] Add the offspring to the new population
- 4. [Replace] Use the new population as the base population of the next iteration.
- 5. [Test] If a condition for stopping the algorithm has been defined, check the condition and stop if necessary, return the solution.
- 6. [Loop] Otherwise, go back to step 2

In FScape, the algorithm is interpreted as follows:

- A chromosome consists of a time window of a given number of samples (Chromosome length).
- The original population is created by reading a corresponding time window from an input sound (Population input). For a given size of population (parameter Population), the time window in the input sound is shifted sample-frame by sample-frame. E.g. if chromosome length is 32 and population is 8, the first individual is read from sample frames (0...31), the second individual from (1...32), etc., the eighth individual from (7...38).
- A number of iterations of breeding is carried out (Iterations), consisting of:
  - Calculating the fitness of each indivdual of the current input population, by comparing it with a corresponding time window in a fitting sound (Fit input), and calculating the root-mean-error. This is performed in the time domain sample-by-sample, or, if Domain is set to "Wavelet" by transforming both population and fitness sound chunk into the wavelet domain.
  - For multichannel sounds, according to the parameter Multichannel fitness, either the worst-case the best-case or the mean of all the channel fitnesses are taken.
  - Generate the next output population by choosing Population parents from the input generation, with a probability depending on their fitness, and breeding each offspring. To breed offspring, the chromosomes of the two parents are cut at Crossing points positions and mixed. Afterwards, with a probability given by Mutation probability, the resulting offspring is mutated. Mutation is performed, by the noise amount given by Mutation amount to the chromosome.
  - The output population of the iteration is used as input population of the next iteration
- The resulting population of these iterations is written out to the target sound file. Each chromosome is first highpass filtered by differentiating, the concatenated output stream lowpass filtered by integration, to prevent clicking at chromosome borders.
- If Elitism is checked, incest is introduced in the iterations, by copying directly the "best" two parents from one population to the next.

last modified: 10-Jun-09