module Moo.GeneticAlgorithm.Niching
( fitnessSharing
) where
import Moo.GeneticAlgorithm.Types
fitnessSharing ::
(Phenotype a -> Phenotype a -> Double)
-> Double
-> Double
-> ProblemType
-> Population a
-> Population a
fitnessSharing dist r alpha Maximizing phenotypes =
let ms = map (nicheCount dist r alpha phenotypes) phenotypes
in zipWith (\(genome, value) m -> (genome, value/m)) phenotypes ms
fitnessSharing dist r alpha Minimizing phenotypes =
let ms = map (nicheCount dist r alpha phenotypes) phenotypes
in zipWith (\(genome, value) m -> (genome, value*m)) phenotypes ms
type DistanceFunction a = Phenotype a -> Phenotype a -> Double
nicheCount :: DistanceFunction a
-> Double -> Double
-> Population a -> Phenotype a -> Double
nicheCount dist r alpha population phenotype =
sum $ map (sharing dist r alpha phenotype) population
sharing :: DistanceFunction a
-> Double -> Double
-> DistanceFunction a
sharing dist r alpha pi pj =
let dij = dist pi pj
in if dij < r
then 1.0 - (dij/r)**alpha
else 0.0