From 4facdd8a1a5f141b158acbe1959da3d10d4c8ce9 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 29 Nov 2023 17:40:38 -0600 Subject: implement parseGenome --- src/Genome.hs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Genome.hs b/src/Genome.hs index cb90ed1..efc79d5 100644 --- a/src/Genome.hs +++ b/src/Genome.hs @@ -12,12 +12,16 @@ module Genome , mutateGenomeRemoveGene , mutateGenome + + , parseGenome ) where -import Mind (NeuronIndex (..)) +import Mind (Edge (..), NeuronIndex (..)) +import qualified Mind as N (Network (..), createEmptyNetwork, connectNeurons) import System.Random import Data.Ix +import Data.Maybe data Gene = Gene { source :: NeuronIndex, sink :: NeuronIndex, weight :: Float } deriving (Eq, Show) @@ -199,3 +203,18 @@ mutateGenome g r = ] ) r in f g r' + + +-- parse a genome into a network +parseGenome :: Genome -> N.Network +parseGenome g = + foldl + (\net gene -> + let + m = N.connectNeurons net (source gene) (sink gene) (weight gene) + net' = if isJust m then fromJust m else error $ "bad gene: " ++ show gene + in + net' + ) + (N.createEmptyNetwork (numInput g) (numInternal g) (numOutput g)) + (genes g) -- cgit v1.2.1