From 5383356791286fd127346b66831e8c83c73877fa Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Tue, 25 Feb 2025 23:32:34 -0600 Subject: [PATCH] fix count discrepancy, thx Dr. Spector :) --- src/HushGP/GP.hs | 1 - src/HushGP/Instructions/Utility.hs | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/HushGP/GP.hs b/src/HushGP/GP.hs index 7cdd5d8..4a5a9ee 100644 --- a/src/HushGP/GP.hs +++ b/src/HushGP/GP.hs @@ -85,4 +85,3 @@ gpLoop' pushArgs generation evaluations population indexedTrainingData = do bestIndPassesDownsample = False -- TODO: fix this later epsilonPushArgs :: PushArgs epsilonPushArgs = pushArgs {epsilons = Nothing} -- TODO: And this ---gpLoop' _ _ _ _ _ = error "How did this happen?" diff --git a/src/HushGP/Instructions/Utility.hs b/src/HushGP/Instructions/Utility.hs index 1ab6f61..6ddd11b 100644 --- a/src/HushGP/Instructions/Utility.hs +++ b/src/HushGP/Instructions/Utility.hs @@ -171,7 +171,13 @@ findContainer _ _ = Block [] -- |Utility Function: A helper function for instructionCodeDiscrepancy. The full description is there. countDiscrepancy :: Gene -> Gene -> Integer -countDiscrepancy (Block xs) (Block ys) = sum [if uncurry (==) tup then 0 else 1 | tup <- zip xs ys] + abs (toInteger (length xs) - toInteger (length ys)) +-- countDiscrepancy (Block xs) (Block ys) = sum [if uncurry (==) tup then 0 else 1 | tup <- zip xs ys] + abs (toInteger (length xs) - toInteger (length ys)) +-- countDiscrepancy (Block xs) (Block ys) = sum [if isBlock (fst tup) && isBlock (snd tup) then uncurry countDiscrepancy tup else if uncurry (==) tup then 0 else 1 | tup <- zip xs ys] + abs (toInteger (length xs) - toInteger (length ys)) +countDiscrepancy (Block xs) (Block []) = codeRecursiveSize (Block xs) +countDiscrepancy (Block []) (Block ys) = codeRecursiveSize (Block ys) +countDiscrepancy (Block (x:xs)) (Block (y:ys)) = if x == y then 1 + countDiscrepancy (Block xs) (Block ys) else countDiscrepancy (Block xs) (Block ys) +countDiscrepancy _ (Block ys) = 1 + codeRecursiveSize (Block ys) +countDiscrepancy (Block xs) _ = 1 + codeRecursiveSize (Block xs) countDiscrepancy xgene ygene = if xgene == ygene then 1 else 0 -- |Utility Function: Extracts the first gene from a block. Returns itself if not a block