Browse Source

Add auto steps + correcting fractdim target

Now turmit can run to limit fractdim (when it stop raising)
The fractdim score is calculated given the target
Yann Weber 6 years ago
parent
commit
3f5adeedc4
2 changed files with 46 additions and 13 deletions
  1. 3
    5
      gte/__main__.py
  2. 43
    8
      gte/world.py

+ 3
- 5
gte/__main__.py View File

@@ -31,7 +31,7 @@ subparsers = parser.add_subparsers(help='sub-commands help')
31 31
 parser_evolve = subparsers.add_parser('evolve', help='evolving help')
32 32
 
33 33
 parser_evolve.add_argument('--steps', '-s', type=int, metavar='N',
34
-                           default=30000, help="Number of steps")
34
+                           default=None, help="Number of steps")
35 35
 
36 36
 parser_evolve.add_argument('--repeat-eval', '-R', type=int, metavar='N',
37 37
                            default=5)
@@ -204,10 +204,8 @@ elif 'pool_size' in args:
204 204
         # Displaying eval results
205 205
         logger.info('Generation evaluating ended in %.2fs' % (genstop - genstart))
206 206
 
207
-        if args.target is None:
208
-            scores = sorted(scores, key=lambda x: x[0], reverse=True)
209
-        else:
210
-            scores = sorted(scores, key=lambda x: abs(x[0] - args.target),)
207
+        scores = sorted(scores, key=lambda x: x[0], reverse=True)
208
+
211 209
         for i, (score, prog, sinfo) in enumerate(scores):
212 210
             logger.info('P%d %.3f:(D:%.3f,F:%.3f) : "%s"' % (i, score,
213 211
                                                              sinfo['D'],

+ 43
- 8
gte/world.py View File

@@ -35,24 +35,49 @@ def eval_prog(args):
35 35
         steps = args.steps
36 36
     else:
37 37
         steps = args.steps - int((args.steps / 1.5) // (args.repeat_eval - trynum))
38
-    for step in range(steps):
39
-        for turmit in turmits:
40
-            turmit()
38
+    
39
+    if not steps: # 0 or None
40
+        pfdim = 0
41
+        dfdim = 1
42
+        steps = 0
43
+        lim_reach = 0
44
+        retry_lim = 0
45
+        while lim_reach < 2:
46
+            for _ in range(3000):
47
+                for turmit in turmits:
48
+                    turmit()
49
+            steps += 0x1000
50
+            cfdim = w.fractdim() # delta fdim on not targeted dim
51
+            dfdim = cfdim - pfdim
52
+            pfdim = cfdim
53
+            if abs(dfdim) < 0.001:
54
+                lim_reach += 1
55
+            else:
56
+                retry_lim += 1
57
+                if retry_lim < 3:
58
+                    lim_reach = 0
59
+    else:
60
+        for step in range(steps):
61
+            for turmit in turmits:
62
+                turmit()
41 63
     stop = time.time()
42 64
 
43 65
     score_dir = sum([t.dirvar() for t in turmits]) / len(turmits)
44 66
     score_deter = sum([t.determinist() for t in turmits]) / len(turmits)
45
-    score_fract = w.fractdim()
67
+    score_fract, raw_fract = w.fractdim_target(args.target)
46 68
     score = (score_dir * score_fract) * (score_deter * 0.2 + 0.8)
47 69
     sinfo = {'F':score_fract, 'D':score_dir}
48 70
     #score = sum([score_fract] + [score_dir] * 4) / 5
49 71
     if not args.quiet:
50 72
         tall = time.time() - startall
51
-        msg = 'G%d P%d R%d: %d steps scores %.3f:(D:%.3f,F:%.3f,Dtr:%.3f) in %.3fs (%dus per step)\t%s'
73
+        msg = 'G%d P%d R%d: %d steps scores %.3f:(D:%.3f,F:%.3f,'
52 74
         msg %= (generation, progid, trynum, steps, score, score_dir,
53
-                score_fract, score_deter, tall,
54
-                ((stop - start)*1000000)//steps//len(turmits),
55
-                str(prog))
75
+                score_fract)
76
+        if args.target:
77
+            msg += 'RawF:%.3f,' % raw_fract
78
+        msg += 'Dtr:%.3f) in %.3fs (%dus per step)\t%s'
79
+        msg %= (score_deter, tall,
80
+                ((stop - start)*1000000)//steps//len(turmits), str(prog))
56 81
         logger.info(msg)
57 82
     return progid, score, sinfo
58 83
 
@@ -100,6 +125,16 @@ class World(object):
100 125
         ''' @brief Save as an image '''
101 126
         scipy.misc.imsave(filename, self._val)
102 127
     
128
+    def fractdim_target(self, target, threshold=None):
129
+        res = self.fractdim(threshold)
130
+        if target:
131
+            ret = (2.0 - (abs(target - res))*5)
132
+            if ret < 0:
133
+                ret = 0.0
134
+            return (ret, res)
135
+        else:
136
+            return (res, res)
137
+
103 138
     def fractdim(self, threshold=None):
104 139
         ''' @return Minkowski–Bouligand dimension (computed) '''
105 140
         if not self._gray:

Loading…
Cancel
Save