neet 0.3.0.0 → 0.3.1.0
raw patch · 3 files changed
+80/−3 lines, 3 files
Files
- neet.cabal +2/−2
- src/Neet/Population.hs +2/−1
- src/Neet/Training.hs +76/−0
neet.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: neet-version: 0.3.0.0+version: 0.3.1.0 synopsis: A NEAT library for Haskell -- description: homepage: https://github.com/raymoo/NEET@@ -23,7 +23,7 @@ library exposed-modules: Neet.Genome, Control.Monad.Fresh.Class, Neet.Parameters, Neet.Network,- Neet.Species, Neet.Population, Neet.Examples.XOR, Neet+ Neet.Species, Neet.Population, Neet.Examples.XOR, Neet, Neet.Training -- other-modules: other-extensions: FunctionalDependencies, MultiParamTypeClasses build-depends: base >=4.7 && <4.8, MonadRandom >=0.4 && <0.5,
src/Neet/Population.hs view
@@ -394,7 +394,7 @@ newParams :: Parameters newParams = case specParams params of- Simple _ -> newParams+ Simple _ -> params Target dp st@SpeciesTarget{..} | specCount > snd targetCount -> let newDP = dp { delta_t = delta_t dp + adjustAmount }@@ -421,6 +421,7 @@ , popParams = newParams , nextSpec = nextSpec' , popGen = popGen pop + 1+ , popPhase = newPhase }
+ src/Neet/Training.hs view
@@ -0,0 +1,76 @@+{-+Copyright (C) 2015 Leon Medvinsky++This program is free software; you can redistribute it and/or+modify it under the terms of the GNU General Public License+as published by the Free Software Foundation; either version 3+of the License, or (at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program; if not, write to the Free Software+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+-}++{-|+Module : Neet.Training+Description : Generic training abstraction+Copyright : (c) Leon Medvinsky, 2015++License : GPL-3+Maintainer : lmedvinsky@hotmail.com+Stability : experimental+Portability : ghc+-}++module Neet.Training ( Training(..)+ , trainSingle+ , trainTraversable+ ) where++import Control.Applicative+import qualified Data.Traversable as T+import Data.Traversable (Traversable)+++-- | Training structure. The idea is that if it is 'StillTraining', it is+-- presenting you with something that must have its score evaluated, and+-- a way to advance the training by providing that score. If it is 'DoneTraining',+-- everything has been iterated through.+data Training candidate score result =+ StillTraining candidate (score -> Training candidate score result)+ | DoneTraining result+++instance (Show c, Show r) => Show (Training c s r) where+ show (DoneTraining res) = "DoneTraining " ++ show res+ show (StillTraining c _) = "StillTraining " ++ show c ++ " <function>"+++instance Functor (Training candidate score) where+ fmap f (DoneTraining res) = DoneTraining (f res)+ fmap f (StillTraining cand k) = StillTraining cand ((fmap . fmap) f k)+++instance Applicative (Training candidate score) where+ pure = DoneTraining+ (<*>) = apTraining+++apTraining :: Training c s (r1 -> r2) -> Training c s r1 -> Training c s r2+apTraining (DoneTraining f) tcsr1 = fmap f tcsr1+apTraining (StillTraining cand k) tcsr1 = StillTraining cand go+ where go score = apTraining (k score) tcsr1+++trainSingle :: a -> Training a b b+trainSingle a = StillTraining a k+ where k b = DoneTraining b+++trainTraversable :: Traversable t => t a -> Training a b (t b)+trainTraversable = T.traverse trainSingle