summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-11-29 17:40:38 -0600
committersanine <sanine.not@pm.me>2023-11-29 17:40:38 -0600
commit4facdd8a1a5f141b158acbe1959da3d10d4c8ce9 (patch)
treea176feaa35fb8a8364742787f760de748ab95636 /src
parent98eabf2989cb3706ee05b6481b0a7221a6c23a51 (diff)
implement parseGenome
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)