Skip to content

jmpg93/GeneticSwift

Repository files navigation

GeneticSwift

Carthage compatible SwiftPM compatible Swift 3.0.x

What is GeneticSwift?

GeneticSwift provides basic tools that allows to solve many different problems (optimization, approximation, prediction, etc) by using genetic algorithms.

A simple regression could be made with a single definition of the fitness function:

private func startRegresion() {
    let ancestor = DoublesChromosome(values: [1, 2, 3],
                                     valuesRange: 0..<10,
                                     multiplierRange: 0..<2,
                                     additionRange: 0..<0.5)
    
    let regressionPoints =  [ Point(1, 1), Point(2, 5), Point(3, 7) ]
    let regressionFunc = DoubleRegressionFitnessFunction<Point>(values: regressionPoints)
    
    let population = Population(ancestor: ancestor,
                                size: 40,
                                fitnessFunction: regressionFunc,
                                selectionMethod: ElitistSelectionMethod(select: 20))
    
    population.delegate = self
    population.next()
}

You will get the polynomial:

Found P(x) = -0.22 * X^3 + 1.13 * X^2 + 0.97 * X

About

Genetic algorithms written in Swift.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published