summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Genome.hs21
1 files changed, 20 insertions, 1 deletions
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)