diff --git a/src/HushGP/GP/Downsample.hs b/src/HushGP/GP/Downsample.hs index 65ec7ab..a9df5a4 100644 --- a/src/HushGP/GP/Downsample.hs +++ b/src/HushGP/GP/Downsample.hs @@ -15,9 +15,9 @@ assignIndiciesToData oldData = zipWith (\dat idx -> dat{_downsampleIndex = Just -- |Initializes cases distances for passed training data. initializeCaseDistances :: PushArgs -> [PushData] -initializeCaseDistances (PushArgs {trainingData = tData, populationSize = popSize}) = [ dat{_caseDistances = Just (replicate (length tData) (fromIntegral @Int @Double popSize))} | dat <- tData ] +initializeCaseDistances (PushArgs {trainingData = tData, populationSize = popSize}) = [ dat{_caseDistances = Just (replicate (length tData) popSize)} | dat <- tData ] --- |Updates the cases distances when downsampling +-- |Updates the cases distances when downsampling. updateCaseDistances :: [Individual] -> [PushData] -> [PushData] -> String -> Double -> [PushData] updateCaseDistances evaledPop downsampleData trainingData informedDownsamplingType solutionThreshold = undefined @@ -70,7 +70,7 @@ selectDownsampleMaxminAdaptive (PushArgs {caseDelta = cDelta}) pushData = do -- original pushData wrapped in a list, the second [PushData] holds the rest of the list -- without the aformentioned head. The Int is the caseDelta derived from the downsample rate -- and the length of the original [pushData]. -selectDownsampleMaxminAdaptive' :: [PushData] -> [PushData] -> Double -> IO [PushData] +selectDownsampleMaxminAdaptive' :: [PushData] -> [PushData] -> Int -> IO [PushData] selectDownsampleMaxminAdaptive' newDownsample casesToPickFrom cDelta = do let newDistances = map extractDistance newDownsample let minCaseDistances = minOfColumns (map (\distList -> filterByIndex distList (map extractIndex casesToPickFrom)) newDistances) @@ -82,3 +82,15 @@ selectDownsampleMaxminAdaptive' newDownsample casesToPickFrom cDelta = do ((casesToPickFrom !! selectedCaseIndex) : newDownsample) (shuffle' (deleteAt selectedCaseIndex casesToPickFrom) (length casesToPickFrom - 1) stdGen) cDelta +-- |Returns the distance between two cases given a list of individual error vectors, and the index these +-- cases exist in the error vector. Only makes the distinction between zero and nonzero errors" +getDistanceBetweenCases :: [[Int]] -> Int -> Int -> Int +getDistanceBetweenCases errorLists caseIndex0 caseIndex1 = + if lhe < caseIndex0 || lhe < caseIndex1 || caseIndex0 < 0 || caseIndex1 < 0 + then length errorLists + else undefined + where + lhe :: Int + lhe = length $ head errorLists + errors0 :: [Int] + errors0 = map (\lst -> lst !! caseIndex0) errorLists diff --git a/src/HushGP/GP/PushArgs.hs b/src/HushGP/GP/PushArgs.hs index d66d188..f70e5db 100644 --- a/src/HushGP/GP/PushArgs.hs +++ b/src/HushGP/GP/PushArgs.hs @@ -96,7 +96,7 @@ data PushArgs = PushArgs epsilons :: Maybe [Double], -- | Used with the CaseMaxminAuto downsampling strategy. Tells downsampling to stop when -- the maximum minimum distance is too far away. - caseDelta :: Double + caseDelta :: Int } -- | The default values for which all runs of Hush derive diff --git a/src/HushGP/GP/PushData.hs b/src/HushGP/GP/PushData.hs index 38ec51a..8a21cde 100644 --- a/src/HushGP/GP/PushData.hs +++ b/src/HushGP/GP/PushData.hs @@ -9,12 +9,12 @@ data PushData = PushData { _inputData :: [Gene], _outputData :: Gene, _downsampleIndex :: Maybe Int, - _caseDistances :: Maybe [Double] + _caseDistances :: Maybe [Int] } deriving (Show) -- |Extracts the case distances from a PushData object. Errors if the -- _caseDistances list is Nothing. -extractDistance :: PushData -> [Double] +extractDistance :: PushData -> [Int] extractDistance PushData{_caseDistances = Nothing} = error "Error: Case distances are empty!. This should never happen" extractDistance PushData{_caseDistances = Just xs} = xs diff --git a/src/HushGP/Tools/Metrics.hs b/src/HushGP/Tools/Metrics.hs index 5b46f33..429cdda 100644 --- a/src/HushGP/Tools/Metrics.hs +++ b/src/HushGP/Tools/Metrics.hs @@ -5,7 +5,7 @@ import System.Random import System.Random.Shuffle -- |Maps minimum over the transposed [[Double]]. -minOfColumns :: [[Double]] -> [Double] +minOfColumns :: [[Int]] -> [Int] minOfColumns columns = map minimum (transpose columns) -- |Returns the index of the maximum value in a list, randomly tiebreaking.