more of the downsample file translated :)

This commit is contained in:
Rowan Torbitzky-Lane 2025-03-01 00:34:31 -06:00
parent 09b4c57784
commit fc2aaff280
4 changed files with 31 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import System.Random.Shuffle
import System.Random import System.Random
import Data.List import Data.List
import HushGP.Genome import HushGP.Genome
import HushGP.Utility
import HushGP.GP.PushData import HushGP.GP.PushData
import HushGP.GP.PushArgs import HushGP.GP.PushArgs
import HushGP.Tools.Metrics import HushGP.Tools.Metrics
@ -115,3 +116,7 @@ updateAtIndices' bigList (sval:svals) (idx:idxs) = updateAtIndices' (replaceAt i
updateCaseDistances :: [Individual] -> [PushData] -> [PushData] -> String -> Double -> [PushData] updateCaseDistances :: [Individual] -> [PushData] -> [PushData] -> String -> Double -> [PushData]
updateCaseDistances evaledPop downsampleData trainingData informedDownsamplingType solutionThreshold = undefined updateCaseDistances evaledPop downsampleData trainingData informedDownsamplingType solutionThreshold = undefined
-- map (\other -> getDistanceBetweenCases [[0,0],[0,0]] 0 other) [0..(length [3,4] - 1)] -- map (\other -> getDistanceBetweenCases [[0,0],[0,0]] 0 other) [0..(length [3,4] - 1)]
-- tempData = intTrainData !! 0
-- dCase = tempData{_downsampleIndex = Just 3, _caseDistances = Just [2,2,2,2,2]}
-- updateIn dCase (updateAtIndices [2,2,2,2,2] (map (\other -> getDistanceBetweenCases [[0,0],[0,0]] 0 0) [0..(length [3,4] - 1)]) [3,4])
-- Replacement for updateIn: dCase{_caseDistances = Just (updateAtIndices (extractDistance dCase) (map (\other -> getDistanceBetweenCases [[0,0],[0,0]] 0 0) [0..(length [3,4] - 1)]) [3,4])}

View File

@ -15,13 +15,13 @@ data PushData = PushData {
-- |Extracts the case distances from a PushData object. Errors if the -- |Extracts the case distances from a PushData object. Errors if the
-- _caseDistances list is Nothing. -- _caseDistances list is Nothing.
extractDistance :: PushData -> [Int] extractDistance :: PushData -> [Int]
extractDistance PushData{_caseDistances = Nothing} = error "Error: Case distances are empty!. This should never happen" extractDistance PushData{_caseDistances = Nothing} = error "Error: Case distances are Nothing!. They should be assigned first!"
extractDistance PushData{_caseDistances = Just xs} = xs extractDistance PushData{_caseDistances = Just xs} = xs
-- |Extracts the downsample index from a PushData object. Errors if the -- |Extracts the downsample index from a PushData object. Errors if the
-- _downsampleIndex is Nothing. -- _downsampleIndex is Nothing.
extractIndex :: PushData -> Int extractIndex :: PushData -> Int
extractIndex PushData{_downsampleIndex = Nothing} = error "Error: Case distances are empty!. This should never happen" extractIndex PushData{_downsampleIndex = Nothing} = error "Error: Downsample index is empty!. They should be assigned first!"
extractIndex PushData{_downsampleIndex = Just x} = x extractIndex PushData{_downsampleIndex = Just x} = x
-- |Filters a list by another list of indices. -- |Filters a list by another list of indices.

View File

@ -12,6 +12,10 @@ import HushGP.Push
import HushGP.Instructions.Utility import HushGP.Instructions.Utility
import HushGP.GP import HushGP.GP
-- temporary imports for testing until I get this updated.
import HushGP.Utility
import HushGP.GP.Downsample
testPlushy :: [Gene] testPlushy :: [Gene]
testPlushy = [ testPlushy = [
PlaceInput 0, PlaceInput 0,
@ -20,6 +24,16 @@ testPlushy = [
-- GeneFloat 3.2 -- GeneFloat 3.2
] ]
-- |Equivalent to ds-data
testIntDsData :: [PushData]
testIntDsData = [
(head intTrainData){_downsampleIndex = Just 3, _caseDistances = Just [2,2,2,2,2]},
(intTrainData !! 1){_downsampleIndex = Just 4, _caseDistances = Just [2,2,2,2,2]}
]
tempFunc :: [PushData]
tempFunc = mapIndexed (\idx dCase -> dCase{_caseDistances = Just (updateAtIndices (extractDistance dCase) (map (\other -> getDistanceBetweenCases [[0,0],[0,0]] idx other) [0..(length [3,4] - 1)]) [3,4])}) testIntDsData
-- | The target function for this run. The function the gp -- | The target function for this run. The function the gp
-- is trying to evolve. -- is trying to evolve.
targetFunction :: Integer -> Integer targetFunction :: Integer -> Integer

View File

@ -13,3 +13,13 @@ randomInstruction instructions = do
-- | Generates a list of random instructions from a list of instructions passed in. -- | Generates a list of random instructions from a list of instructions passed in.
randomInstructions :: Int -> [Gene] -> IO [Gene] randomInstructions :: Int -> [Gene] -> IO [Gene]
randomInstructions amt instructions = replicateM amt (randomInstruction instructions) randomInstructions amt instructions = replicateM amt (randomInstruction instructions)
-- | Maps a function like the normal mapping function and also applies an index to it.
mapIndexed :: (Int -> a -> b) -> [a] -> [b]
mapIndexed = mapIndexed' 0
-- | Internals for mapIndexed, can supply a starting index for rather than just 0
-- with mapIndexed.
mapIndexed' :: Int -> (Int -> a -> b) -> [a] -> [b]
mapIndexed' _ _ [] = []
mapIndexed' count f (x:xs) = f count x : mapIndexed' (count + 1) f xs