int regression start
This commit is contained in:
parent
feddc3cbfe
commit
b88a4944f9
10
HushGP.cabal
10
HushGP.cabal
@ -36,7 +36,9 @@ library
|
||||
|
||||
-- Modules exported by the library.
|
||||
exposed-modules: HushGP.Push
|
||||
, HushGP.GP
|
||||
, HushGP.TH
|
||||
, HushGP.Utility
|
||||
, HushGP.Genome
|
||||
, HushGP.State
|
||||
, HushGP.Instructions
|
||||
, HushGP.Instructions.IntInstructions
|
||||
@ -58,10 +60,10 @@ library
|
||||
, HushGP.PushTests.IntTests
|
||||
, HushGP.PushTests.GenericTests
|
||||
, HushGP.PushTests.UtilTests
|
||||
, HushGP.GP
|
||||
, HushGP.GP.PushArgs
|
||||
, HushGP.TH
|
||||
, HushGP.Utility
|
||||
, HushGP.Genome
|
||||
, HushGP.Problems.IntegerRegression
|
||||
|
||||
|
||||
-- Modules included in this library but not exported.
|
||||
-- other-modules:
|
||||
|
@ -4,6 +4,8 @@ import HushGP.State
|
||||
import Data.Map qualified as Map
|
||||
import HushGP.Instructions
|
||||
|
||||
-- | The structure holding the arguments for the various aspects
|
||||
-- of the evolutionary run in Hush.
|
||||
data PushArgs = PushArgs
|
||||
{
|
||||
-- | For alternation, std deviation fo index when alternating.
|
||||
@ -42,8 +44,12 @@ data PushArgs = PushArgs
|
||||
downsampleParentsGens :: Int,
|
||||
-- | Whether or not to add the best individual to the next generation.
|
||||
elitism :: Bool,
|
||||
-- User must provide their own error function. TODO: This
|
||||
-- errorFunction :: (PushArgs -> )
|
||||
-- | User must provide their own error function.
|
||||
-- Arg 1: PushArgs for the current set of arguments.
|
||||
-- Arg 2: ([[Gene]], [Gene]) is the input data. Input is the first index and output is the second index.
|
||||
-- Arg 3: [Gene] is the plushy representation of a program.
|
||||
-- Returns the error list for a given set of inputs of type [Double].
|
||||
errorFunction :: PushArgs -> [[Gene]] -> [Gene] -> [Double],
|
||||
-- | Type of informed downsampling. "solved", "elite", "soft".
|
||||
informedDownsamplingType :: String,
|
||||
-- | List of instructions to use in the evolutionary run.
|
||||
@ -76,10 +82,10 @@ data PushArgs = PushArgs
|
||||
stepLimit :: Int,
|
||||
-- | For tournament selection, amount of individuals in each tournament.
|
||||
tournamentSize :: Int,
|
||||
-- Training data for the gp, must be provided.
|
||||
-- trainingData :: something
|
||||
-- Testing data for the gp, must be provided if there is any.
|
||||
-- testingData :: something
|
||||
-- | Training data for the gp, must be provided.
|
||||
trainingData :: [[Gene]],
|
||||
-- | Testing data for the gp, must be provided if there is any.
|
||||
testingData :: [[Gene]],
|
||||
-- | Addition rate for UMAD (deletion rate derived from this).
|
||||
umadRate :: Float,
|
||||
-- | Genetic operators and probabilities for their use, should sum to one
|
||||
@ -87,6 +93,8 @@ data PushArgs = PushArgs
|
||||
variation :: Map.Map String Float
|
||||
}
|
||||
|
||||
-- | The default values for which all runs of Hush derive
|
||||
-- their args from.
|
||||
defaultPushArgs :: PushArgs
|
||||
defaultPushArgs = PushArgs {
|
||||
alignmentDeviation = 2,
|
||||
@ -106,7 +114,7 @@ defaultPushArgs = PushArgs {
|
||||
downsampleParentRate = 0.01,
|
||||
downsampleParentsGens = 10,
|
||||
elitism = False,
|
||||
-- errorFunction = something,
|
||||
errorFunction = error "Must supply the error function yourself",
|
||||
informedDownsamplingType = "solved",
|
||||
instructionList = allInstructions,
|
||||
maxMotelyBatchSize = 10,
|
||||
@ -124,8 +132,8 @@ defaultPushArgs = PushArgs {
|
||||
ssxNotBmx = False,
|
||||
stepLimit = 1000,
|
||||
tournamentSize = 5,
|
||||
-- testingData = [],
|
||||
-- trainingData = [],
|
||||
testingData = [],
|
||||
trainingData = [],
|
||||
umadRate = 0.1,
|
||||
variation = Map.fromList [("umad", 1.0)]
|
||||
}
|
||||
|
41
src/HushGP/Problems/IntegerRegression.hs
Normal file
41
src/HushGP/Problems/IntegerRegression.hs
Normal file
@ -0,0 +1,41 @@
|
||||
module HushGP.Problems.IntegerRegression where
|
||||
|
||||
import HushGP.State
|
||||
import HushGP.Instructions
|
||||
import Data.List.Split
|
||||
import HushGP.GP.PushArgs
|
||||
import HushGP.Genome
|
||||
import HushGP.Push
|
||||
import Data.Map qualified as Map
|
||||
|
||||
-- | The target function for this run. The function the gp
|
||||
-- is trying to evolve.
|
||||
targetFunction :: Integer -> Integer
|
||||
targetFunction x = (x * x * x) + (2 * x)
|
||||
|
||||
-- | The training data for the model.
|
||||
trainData :: ([[Gene]], [Gene])
|
||||
trainData = (chunksOf 1 $ map GeneInt [-10..10], map (GeneInt . targetFunction) [-10..11])
|
||||
|
||||
-- | The testing data for the model.
|
||||
testData :: ([[Gene]], [Gene])
|
||||
testData = (chunksOf 1 $ map GeneInt $ [-20..(-11)] <> [11..21], map (GeneInt . targetFunction) ([-20..(-11)] <> [11..21]))
|
||||
|
||||
-- | The instructions used to
|
||||
runInstructions :: [Gene]
|
||||
runInstructions =
|
||||
[
|
||||
PlaceInput 0,
|
||||
Close,
|
||||
GeneInt 1,
|
||||
GeneInt 0
|
||||
]
|
||||
<> allIntInstructions
|
||||
|
||||
-- |The error function for a single set of inputs and outputs.
|
||||
intErrorFunction :: PushArgs -> ([Gene], Gene) -> [Gene] -> [Double]
|
||||
intErrorFunction args (inputData, outputData) plushy =
|
||||
head $ _int $ interpretExec loadedState
|
||||
where
|
||||
loadedState :: State
|
||||
loadedState = (loadProgram (plushyToPush plushy) emptyState){_input = Map.fromList (zip [0..] inputData)}
|
@ -21,9 +21,9 @@ data Gene
|
||||
| GeneVectorBool [Bool]
|
||||
| GeneVectorString [String]
|
||||
| GeneVectorChar [Char]
|
||||
| -- | State -> State is the function itself. String stores the name of the function.
|
||||
StateFunc (State -> State, String)
|
||||
| PlaceInput String
|
||||
-- | State -> State is the function itself. String stores the name of the function.
|
||||
| StateFunc (State -> State, String)
|
||||
| PlaceInput Int
|
||||
| Close
|
||||
| Open Int
|
||||
| Skip
|
||||
@ -160,7 +160,7 @@ data State = State
|
||||
_vectorString :: [[String]],
|
||||
_vectorChar :: [[Char]],
|
||||
_parameter :: [Gene],
|
||||
_input :: Map.Map String Gene
|
||||
_input :: Map.Map Int Gene
|
||||
}
|
||||
deriving (Show, Eq, Ord)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user