Skip to content

peheje/DifferentialEvolution

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Differential evolution algorithm

Inspired by this paper. (Jakob Vesterstram, Rene Thomsen, 2004)

Implemented in various languages

Usage

Implement a function with signature float array -> float, the closer to 0 the function returns, the better the parameters fit.

Examples for the F# implementation

Using these parameters:

let optimizer = systemOfEquations
let generations = 1000
let argsize = 2
let popsize = 200
let min, max = -100.0, 100.0

You can solve systems of equations:

// Solve systems of equations like, x + y = 6 and -3x + y = 2
let systemOfEquations (xs: float array) =
    let x = xs[0]
    let y = xs[1]
    abs (x + y - 6.0) + abs (-3.0 * x + y - 2.0)

Outputs:

xs = [|1.0; 5.0|]
score = 0.0

Also solve nonlinear system of equations with constraints, like this example from Matlabs documentation:

let nonlinearSystemOfEquationsWithConstraints (xs: float array) =
    let x = xs[0]
    let y = xs[1]
    let t1 = (x + 1.0)*(10.0 - x)*((1.0 + y*y)/(1.0 + y*y + y))
    let t2 = (y + 2.0)*(20.0 - y)*((1.0 + x*x)/(1.0 + x*x + x))
    let c1 = x*x + y*y
    let e = if c1 > 10.0 then c1 else 0.0

    abs(t1) + abs(t2) + e

Which outputs:

xs = [|-1.0; -2.0|]
score = 0.0

Another example:

// There are 36 heads and 100 legs, how many horses and jockeys are there?
let horsesAndJockeys (xs: float array) =
    let horses = xs[0]
    let jockeys = xs[1]
    let legs = horses * 4.0 + jockeys * 2.0
    let heads = horses + jockeys
    abs (36.0 - heads) + abs (100.0 - legs)

Outputs:

xs = [|14.0; 22.0|] 
score = 0.0

Not guaranteed to find any solution or any good solution.

Parameters

Beside setting the argsize and min/max parameters, which depends on the optimizer function, you can tune the parameters generations, popsize, crossoverOdds and mutateOdds.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published