-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbdtmulti.hs
61 lines (53 loc) · 1.47 KB
/
bdtmulti.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module Main(
main,
ops,
terms,
tests
) where
import RGEP
import PGEP
import SymReg
import EA
import EAMonad
import Postfix
import Randomly
import Operators
import Selection
import BDT
import Multiplex
import Data.List
import Data.Function
import Control.Monad
exps = 1
ps = 2000
is = 60
gens = 100
pm = 0.002
pr = 0.02
pc1 = 0.7
pc2 = 0.7
x = 10000
k = 3
regs = k + 2^k
ops = [decide (show i ++ b) | i <- [1..regs], b <- ["True", "False"]]
terms = [decided "True", decided "False"]
tests = map (\(bs, b) -> (zipWith (\i b -> show i ++ show b) [1..length bs] bs, show b)) $ multicases k
eval Nothing = return 0
eval (Just tree) = return $ penalty $ evalcases tree tests --sizescale (treedepth tree) $ penalty $ evalcases tree tests
penalty n = if n <= 2^k then 0 else n
sizescale s c = (c^2) * (x/((s^2)+x))
run = rgep ps is pm pr pc1 pc2 gens ops terms eval
--run = pgep ps is pm pr pc1 pc2 gens ops terms eval
main = do
result <- replicateM exps experiment
writeFile "btest" $! foldl' (++) "" result
experiment = do
(p, e, l, g) <- runEAIO run ()
--putStrLn $ if bestFit p == sizescale 7 8 then "success" else "failure"
print $ rgepeval $ cdns2syms (cdnlen ops terms) ops terms $ bestInd p
--print $ pgepeval $ bestInd p
let (Just bestguy) = rgepeval $ cdns2syms (cdnlen ops terms) ops terms $ bestInd p
print $ penalty $ evalcases bestguy tests
putStrLn $ "With depth: " ++ show (treedepth bestguy)
putStrLn $ "and size: " ++ show (treesize bestguy)
return $! l