Fenetics is a simple F# library which demonstrates genetic algorithms in action, the name is a contraction of F(#) and (G)enetics. This is lab project and as such not a commercial component, not even a potential candidate but rather a slow move towards building enterprise-level F# libraries.
Genetic algorithms are a wonderful domain where biology overlaps with algorithmic. In this F# library it is shown how with functional programming one can easily demonstrate the general principles of this highly ingenious mechanism which underlies our own evolution and life itself.
The simple generational genetic algorithm implemented in this library is as follows
As population and individuals we have taken 'string' objects and you get hence the following abstraction:
- an initial population of individuals is chosen (random)
- the fitness of each individual in that population is evaluated
- a loop consisting of the following is performed until termination: (time limit, sufficient fitness achieved, etc.)
- the best-fit individuals for reproduction is selected
- a new breed of individuals is created through crossover and mutation operations
- the individual fitness of new individuals is evaluated
- the least-fit population is replaced with new individuals
This analogy is on its own quite something which you can look at as totally twisted or brilliant, depending on your scientific inclination.
So, the library allows you to move from an initial population of words to a given target-word. While this is not immediately useful in real-life, it does solve the general problem of finding a needle in a huge haystack. Indeed, its well-known that genetic algorithms work well, very well actually, when a certain space consists of multiple extrema's which are usually not analytically defined.
Aside from the scientific context the library collects useful code related to string manipulations, color tricks, data (string) conversions and displaying of data in WPF through F#. It's also a bag of good practices regarding:
- words are individual beings
- sentences are living populations
- inter-breeding is done through mixing letters
- code indentation
- documentating in F#
- organization of files
- usage of modules, namespaces and files