Browse Source

Optimisation in World init + update default args

Yann Weber 6 years ago
parent
commit
b4b60721e3
2 changed files with 24 additions and 18 deletions
  1. 15
    11
      gte/__main__.py
  2. 9
    7
      gte/world.py

+ 15
- 11
gte/__main__.py View File

@@ -26,14 +26,15 @@ subparsers = parser.add_subparsers(help='sub-commands help')
26 26
 parser_evolve = subparsers.add_parser('evolve', help='evolving help')
27 27
 
28 28
 parser_evolve.add_argument('--steps', '-s', type=int, metavar='N',
29
-                           default=4000, help="Number of steps")
29
+                           default=30000, help="Number of steps")
30 30
 
31
-parser_evolve.add_argument('--repeat-eval', type=int, metavar='N', default=5)
31
+parser_evolve.add_argument('--repeat-eval', '-R', type=int, metavar='N',
32
+                           default=5)
32 33
 
33 34
 parser_evolve.add_argument('--world-height', '-y', type=int, metavar='HEIGHT',
34
-                           default=256)
35
+                           default=512)
35 36
 parser_evolve.add_argument('--world-width', '-x', type=int, metavar='WIDTH',
36
-                           default=256)
37
+                           default=512)
37 38
 
38 39
 parser_evolve.add_argument('--turmit-count', '-T', type=int, metavar='N',
39 40
                            default=3)
@@ -63,18 +64,20 @@ parser_evolve.add_argument('--log-progs', '-L', type=str, metavar='FILENAME',
63 64
 parser_evolve.add_argument('--quiet', '-q', action='store_const',
64 65
                            default=False, const=True)
65 66
 
67
+
68
+
66 69
 parser_gen = subparsers.add_parser('generate', help='evolving help')
67 70
 
68 71
 parser_gen.add_argument('--prog', '-P', type=str, default=None)
69 72
 parser_gen.add_argument('--output', '-o', type=str, default='gte.png')
70 73
 parser_gen.add_argument('--world-height', '-y', type=int, metavar='HEIGHT',
71
-                        default=256)
74
+                        default=512)
72 75
 parser_gen.add_argument('--world-width', '-x', type=int, metavar='WIDTH',
73
-                        default=256)
76
+                        default=512)
74 77
 parser_gen.add_argument('--turmit-count', '-T', type=int, metavar='N',
75
-                        default=10)
78
+                        default=3)
76 79
 parser_gen.add_argument('--steps', '-s', type=int, metavar='N',
77
-                        default=1024)
80
+                        default=30000)
78 81
 
79 82
 
80 83
 args = parser.parse_args()
@@ -113,7 +116,7 @@ if 'pool_size' in args:
113 116
         works = []
114 117
         for pid, prog in enumerate(progs):
115 118
             for i in range(args.repeat_eval):
116
-                works.append((pid, prog, i, args))
119
+                works.append((generation, pid, prog, i, args))
117 120
         res = pool.imap(eval_prog, works)
118 121
         scores = [0 for _ in range(len(progs))]
119 122
         for pid, score in res:
@@ -158,9 +161,10 @@ else:
158 161
     start = time.time()
159 162
     for step in range(args.steps):
160 163
         if step % 512 == 1:
161
-            msg = 'Step %d/%d %dus/step'
164
+            msg = 'Step %d/%d %dus/step fractdim=%.3f'
162 165
             msg %= (step, args.steps,
163
-                    ((time.time() - start)*1000000)//step//len(turmits))
166
+                    ((time.time() - start)*1000000)//step//len(turmits),
167
+                    w.fractdim())
164 168
             logger.info(msg)
165 169
         for turmit in turmits:
166 170
             turmit()

+ 9
- 7
gte/world.py View File

@@ -15,7 +15,7 @@ def eval_prog(args):
15 15
     ''' @brief Return an array of fractdim
16 16
         @param args : dirty argparser returned arguments
17 17
     '''
18
-    progid, prog, trynum, args = args
18
+    generation, progid, prog, trynum, args = args
19 19
     w = World(args.world_height, args.world_width)
20 20
     logger.debug('Running P%d run#%d %s' % (progid, trynum, prog))
21 21
     w.raz()
@@ -30,9 +30,8 @@ def eval_prog(args):
30 30
 
31 31
     score = w.fractdim()
32 32
     if not args.quiet:
33
-        msg = 'P%d run#%d scores %.3f in %.2fs (%dus per step)\t%s'
34
-        msg %= (progid, trynum, score,
35
-                stop - start,
33
+        msg = 'G%d P%d run#%d scores %.3f in %.2fs (%dus per step)\t%s'
34
+        msg %= (generation, progid, trynum, score, stop - start,
36 35
                 ((stop - start)*1000000)//args.steps//len(turmits),
37 36
                 str(prog))
38 37
         logger.info(msg)
@@ -59,12 +58,15 @@ class World(object):
59 58
     def width(self):
60 59
         return self._x
61 60
 
62
-    def raz(self, color=(0,0,0)):
61
+    def raz(self, color=None):
63 62
         ''' @brief Set all value to color
64 63
             @param color tuple : tuple(R,G,B)
65 64
         '''
66
-        self._val = [[color for _ in range(self._x)] for _ in range(self._y)]
67
-        self._val = np.array(self._val)
65
+        if color is None:
66
+            self._val = np.zeros([self._y, self._x, 3])
67
+        else:
68
+            self._val = [[color for _ in range(self._x)] for _ in range(self._y)]
69
+            self._val = np.array(self._val)
68 70
 
69 71
     def save(self, filename):
70 72
         ''' @brief Save as an image '''

Loading…
Cancel
Save