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

+ 9
- 7
gte/world.py View File

15
     ''' @brief Return an array of fractdim
15
     ''' @brief Return an array of fractdim
16
         @param args : dirty argparser returned arguments
16
         @param args : dirty argparser returned arguments
17
     '''
17
     '''
18
-    progid, prog, trynum, args = args
18
+    generation, progid, prog, trynum, args = args
19
     w = World(args.world_height, args.world_width)
19
     w = World(args.world_height, args.world_width)
20
     logger.debug('Running P%d run#%d %s' % (progid, trynum, prog))
20
     logger.debug('Running P%d run#%d %s' % (progid, trynum, prog))
21
     w.raz()
21
     w.raz()
30
 
30
 
31
     score = w.fractdim()
31
     score = w.fractdim()
32
     if not args.quiet:
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
                 ((stop - start)*1000000)//args.steps//len(turmits),
35
                 ((stop - start)*1000000)//args.steps//len(turmits),
37
                 str(prog))
36
                 str(prog))
38
         logger.info(msg)
37
         logger.info(msg)
59
     def width(self):
58
     def width(self):
60
         return self._x
59
         return self._x
61
 
60
 
62
-    def raz(self, color=(0,0,0)):
61
+    def raz(self, color=None):
63
         ''' @brief Set all value to color
62
         ''' @brief Set all value to color
64
             @param color tuple : tuple(R,G,B)
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
     def save(self, filename):
71
     def save(self, filename):
70
         ''' @brief Save as an image '''
72
         ''' @brief Save as an image '''

Loading…
Cancel
Save