rubyneat 0.4.0.alpha.4 → 0.4.0.alpha.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,444 @@
1
+ <div id="table-of-contents">
2
+ <h2>Table of Contents</h2>
3
+ <div id="text-table-of-contents">
4
+ <ul>
5
+ <li><a href="#orgheadline42">1. RubyNEAT &#x2013; Ruby implementation of Neural Evolution of Augmenting Topologies (NEAT)</a>
6
+ <ul>
7
+ <li><a href="#orgheadline1">1.1. What is NEAT?</a></li>
8
+ <li><a href="#orgheadline2">1.2. What is RubyNEAT?</a></li>
9
+ <li><a href="#orgheadline9">1.3. Architecture</a>
10
+ <ul>
11
+ <li><a href="#orgheadline3">1.3.1. Controller</a></li>
12
+ <li><a href="#orgheadline4">1.3.2. Evolver</a></li>
13
+ <li><a href="#orgheadline5">1.3.3. Expressor</a></li>
14
+ <li><a href="#orgheadline6">1.3.4. Evaluator</a></li>
15
+ <li><a href="#orgheadline7">1.3.5. Population</a></li>
16
+ <li><a href="#orgheadline8">1.3.6. Critter</a></li>
17
+ </ul>
18
+ </li>
19
+ <li><a href="#orgheadline11">1.4. Installation</a>
20
+ <ul>
21
+ <li><a href="#orgheadline10">1.4.1. Requirements</a></li>
22
+ </ul>
23
+ </li>
24
+ <li><a href="#orgheadline15">1.5. Examples</a>
25
+ <ul>
26
+ <li><a href="#orgheadline14">1.5.1. Note Well</a></li>
27
+ </ul>
28
+ </li>
29
+ <li><a href="#orgheadline41">1.6. RubyNEAT DSL</a>
30
+ <ul>
31
+ <li><a href="#orgheadline34">1.6.1. The XOR Neater Example</a></li>
32
+ <li><a href="#orgheadline40">1.6.2. Releases</a></li>
33
+ </ul>
34
+ </li>
35
+ </ul>
36
+ </li>
37
+ </ul>
38
+ </div>
39
+ </div>
40
+
41
+ &#x2014;
42
+ layout: default
43
+ title: RubyNEAT
44
+ &#x2014;
45
+
46
+ # RubyNEAT &#x2013; Ruby implementation of Neural Evolution of Augmenting Topologies (NEAT)<a id="orgheadline42"></a>
47
+
48
+ ## What is NEAT?<a id="orgheadline1"></a>
49
+
50
+ NEAT is an acronym for Neural Evolution of Augmenting Topologies.
51
+ In short, neural nets that are evolved from a minimal topology,
52
+ allowing selection to decide on what topologies are most adequate
53
+ for resolving the problem at hand.
54
+
55
+ ## What is RubyNEAT?<a id="orgheadline2"></a>
56
+
57
+ RubyNEAT is the world's first (and currently only) implementation
58
+ of the NEAT algorithm in the Ruby programming language. RubyNEAT
59
+ leverages some of the benefits of Ruby, such as metaprogramming,
60
+ to implement activation of the Neural Net.
61
+
62
+ Basically, the Neural Nets in RubyNEAT manifests themselves in the
63
+ Phenotypes as functional programs &#x2013; of a sort. You may think of it
64
+ as an application of Genetic Programming techniques to resolving the
65
+ NEAT algorithm. As such, once fit Critters (neural nets) are found,
66
+ they may be extracted as pure Ruby code, not needing the
67
+ RubyNEAT engine for activation.
68
+
69
+ ## Architecture<a id="orgheadline9"></a>
70
+
71
+ RubyNEAT comprises many interacting modules. While it is
72
+ not strictly necessary to understand RubyNEAT at this level
73
+ of detail, it would be beneficial for a number of reasons,
74
+ especially in understanding how to tweak the parameters
75
+ to improve performance for your application.
76
+
77
+ RubyNEAT comprises the following modules:
78
+ Controller, Expressor, Evaluator, Evolver, Population, and Critter.
79
+
80
+ ### Controller<a id="orgheadline3"></a>
81
+
82
+ The Controller mediates all aspects of RubyNEAT
83
+ evolution, the various modules involved and their
84
+ interactions, and also holds the settings the other
85
+ modules will refer to.
86
+
87
+ The Controller is singular. There can only be one
88
+ Controller in the RubyNEAT system. All other objects
89
+ associated with the Controller shall have embedded
90
+ in them a reference to their controller.
91
+
92
+ ### Evolver<a id="orgheadline4"></a>
93
+
94
+ The Evolver module houses the evolving algorithms
95
+ for RubyNEAT. It evolves the entire Population of Critters.
96
+
97
+ ### Expressor<a id="orgheadline5"></a>
98
+
99
+ The Expressor module is responsible for interpreting
100
+ the Genotype of the Critters and creating their
101
+ Phenotypes. The default Expressor generates Ruby code
102
+ and attaches that code to the Phenotype instances of the Critter.
103
+
104
+ It is entirely possible to swap in a different Expressor and
105
+ generate code for a different target language, or create some
106
+ other construct. There is no limit to what you could
107
+ have an Expressor do.
108
+
109
+ ### Evaluator<a id="orgheadline6"></a>
110
+
111
+ The Evaluator is a kind of bridge between the inner "biology" of the RubyNEAT "ecosystem" and the outside world. It has ties to the RubyNEAT DSL where you encode your own fitness functions and data links to some external problem space. It is, in a sense, the "gateway".
112
+
113
+ ### Population<a id="orgheadline7"></a>
114
+
115
+ The Population is what your intuition tells you. It is a environment that houses a collection of Critters.
116
+
117
+ ### Critter<a id="orgheadline8"></a>
118
+
119
+ The Critter is the embodiment of both the genetics for the neural net and also the expression of the same. It contains, in other words, the Genotype and the Phenotype.
120
+
121
+ Critters are mated through the Evolver, and have their genes expressed through the Expressor.
122
+
123
+ ## Installation<a id="orgheadline11"></a>
124
+
125
+ You may install RubyNEAT by cloning the repo at GitHub:
126
+ [RubyNEAT Github](https://github.com/flajann2/rubyneat)
127
+
128
+ Or you may get it via a gem
129
+
130
+ gem install rubyneat --pre
131
+
132
+ ### Requirements<a id="orgheadline10"></a>
133
+
134
+ You will need at least Ruby 2.0.0, though we strongly recommend 2.1.1
135
+ or better. We will NOT be supporting 1.9.x,
136
+ as that is being phased out anyway.
137
+
138
+ ## Examples<a id="orgheadline15"></a>
139
+
140
+ Clone:
141
+
142
+ git clone git@github.com:flajann2/rubyneat_examples.git
143
+
144
+ and cd into the '''rubyneat<sub>examples</sub>''' directory.
145
+
146
+ Type:
147
+
148
+ neat list neaters
149
+
150
+ to get a list of neaters. To run one like, say, the XOR test:
151
+
152
+ neat run xor
153
+
154
+ ### Note Well<a id="orgheadline14"></a>
155
+
156
+ The pole-balancing invpend neater is still under
157
+ development. It will display a window with the cart and pole,
158
+ but will not balance yet. Just a matter of me
159
+ finishing up that code. All the others work.
160
+
161
+ 1. RubyNEAT
162
+
163
+ - GitHUB
164
+ [RubyNEAT GitHub](https://github.com/flajann2/rubyneat)
165
+
166
+ - Ruby GEM
167
+
168
+ gem install rubyneat --pre
169
+
170
+ 2. RubyNEAT Examples
171
+
172
+ - Github
173
+ [Example Neaters on GitHub](https://github.com/flajann2/rubyneat_examples)
174
+
175
+ ## RubyNEAT DSL<a id="orgheadline41"></a>
176
+
177
+ I will take the '''XOR''' neater and document it.
178
+ This is not the perfect way to go,
179
+ but I will get more extensive later.
180
+
181
+ ### The XOR Neater Example<a id="orgheadline34"></a>
182
+
183
+ require 'xor'
184
+ include NEAT::DSL
185
+
186
+ - The first lines here includes the special XOR library, which is basically:
187
+
188
+ def xor(*inp)
189
+ inp.map{|n| (n > 0) ? 1 : 0}.reduce {|p, i| p + ((i > 0) ? 1 : 0) } == 1
190
+ end
191
+
192
+ -Basic settings for the '''XOR''', which can handle more than 2 inputs.
193
+
194
+ XOR_INPUTS = 2
195
+ XOR_STATES = 2 ** XOR_INPUTS
196
+ MAX_FIT = XOR_STATES
197
+ ALMOST_FIT = XOR_STATES - 0.5
198
+
199
+ - The actual definition of the Neater. Here you specify the parameters RubyNEAT
200
+ will use to run the evolution, as well as the CPPN neuron types, the fitness function,
201
+ etc.
202
+
203
+ define "XOR System" do
204
+
205
+ - Inputs defined as name: Neuron, name: Neuron &#x2026; hash. In this segment, we
206
+ create a block to generate the hash since we can have a variable number of
207
+ inputs to the XOR. The input names must be unique. Note that a bias neuron
208
+ is also supplied, and it is always called :bias.
209
+
210
+ inputs {
211
+ cinv = Hash[(1..XOR_INPUTS).map{|i| [("i%s" % i).to_sym, InputNeuron]}]
212
+ cinv[:bias] = BiasNeuron
213
+ cinv
214
+ }
215
+
216
+ - Outputs are defined in a similar fashion to the inputs. The names of all the
217
+ output neurons must be unique. Here in this example we only have one output, and
218
+ we use the hyperbolic tan Neuron as the output. There is also a sigmoid Neuron
219
+ that could be used as well, but the input levels would have to be conditioned
220
+ to vary from 0 to 1 instead of from -1 to one.
221
+
222
+ outputs out: TanhNeuron
223
+
224
+ - Hidden neuron specification is optional.
225
+ The names given here are largely meaningless, but but follow the same rules
226
+ for uniqueness. The neurons specified will be selected randomly as the topologies
227
+ are augmented.
228
+
229
+ hidden tan: TanhNeuron
230
+
231
+ 1. Settings
232
+
233
+ For RubyNEAT. Extensive documentation will be provided on a later date
234
+ as to the meanings, which closely follow the parameters for Ken Stanley's NEAT
235
+ implementation.
236
+
237
+ 1. General
238
+
239
+ hash_on_fitness false
240
+ start_population_size 30
241
+ population_size 30
242
+ max_generations 10000
243
+ max_population_history 10
244
+
245
+ 2. Evolver probabilities and SDs
246
+
247
+ Perturbations
248
+
249
+ mutate_perturb_gene_weights_prob 0.10
250
+ mutate_perturb_gene_weights_sd 0.25
251
+
252
+ 3. Complete Change of weight
253
+
254
+ mutate_change_gene_weights_prob 0.10
255
+ mutate_change_gene_weights_sd 1.00
256
+
257
+ 4. Adding new neurons and genes
258
+
259
+ mutate_add_neuron_prob 0.05
260
+ mutate_add_gene_prob 0.20
261
+
262
+ 5. Switching genes on and off
263
+
264
+ mutate_gene_disable_prob 0.01
265
+ mutate_gene_reenable_prob 0.01
266
+
267
+ interspecies_mate_rate 0.03
268
+ mate_only_prob 0.10 *0.7
269
+
270
+ 6. Mating
271
+
272
+ survival_threshold 0.20 # top % allowed to mate in a species.
273
+ survival_mininum_per_species 4 # for small populations, we need SOMETHING to go on.
274
+
275
+ 7. Fitness costs
276
+
277
+ fitness_cost_per_neuron 0.00001
278
+ fitness_cost_per_gene 0.00001
279
+
280
+ 8. Speciation
281
+
282
+ compatibility_threshold 2.5
283
+ disjoint_coefficient 0.6
284
+ excess_coefficient 0.6
285
+ weight_coefficient 0.2
286
+ max_species 20
287
+ dropoff_age 15
288
+ smallest_species 5
289
+
290
+ 9. Sequencing
291
+
292
+ The evaluation function is called repeatedly, and each iteration is given a
293
+ monotonically increasing integer which represents the sequence number. The results
294
+ of each run is returned, and those results are evaluated elsewhere in the Neater.
295
+
296
+ start_sequence_at 0
297
+ end_sequence_at 2 ** XOR_INPUTS - 1
298
+
299
+ 2. The Evolution Block
300
+
301
+ evolve do
302
+
303
+ 1. The Query Block
304
+
305
+ This query shall return a vector result that will serve
306
+ as the inputs to the critter.
307
+
308
+ query { |seq|
309
+ * We'll use the seq to create the xor sequences via
310
+ * the least signficant bits.
311
+ condition_boolean_vector (0 ... XOR_INPUTS).map{|i| (seq & (1 << i)) != 0}
312
+ }
313
+
314
+ 2. The Compare Block
315
+
316
+ Compare the fitness of two critters. We may choose a different ordering here.
317
+
318
+ compare {|f1, f2| f2 <=> f1 }
319
+
320
+ 3. The Cost of Fitness Block
321
+
322
+ Here we integrate the cost with the fitness.
323
+
324
+ cost { |fitvec, cost|
325
+ fit = XOR_STATES - fitvec.reduce {|a,r| a+r} - cost
326
+ $log.debug ">>>>>>> fitvec *{fitvec} => *{fit}, cost *{cost}"
327
+ fit
328
+ }
329
+
330
+ 4. The Fitness Block
331
+
332
+ The fitness block is called for each activation and is given the input vector,
333
+ the output vector, and the sequence number given to the query. The results are
334
+ evaluated and a fitness scalar is returned.
335
+
336
+ \#+BEGIN<sub>SRC</sub> ruby
337
+ fitness { |vin, vout, seq|
338
+ unless vout **\*** :error
339
+ bin = uncondition<sub>boolean</sub><sub>vector</sub> vin
340
+ bout = uncondition<sub>boolean</sub><sub>vector</sub> vout
341
+ bactual = [xor(\*vin)]
342
+ vactual = condition<sub>boolean</sub><sub>vector</sub> bactual
343
+ fit = (bout **\*** bactual) ? 0.00 : 1.00
344
+ **simple<sub>fitness</sub><sub>error</sub>(vout, vactual.map{|f| f \* 0.50 })
345
+ bfit = (bout \*\*** bactual) ? 'T' : 'F'
346
+ fit
347
+ else
348
+ $log.debug "Error on \*{vin} [\*{seq}]"
349
+ 1.0
350
+ end
351
+ }
352
+ \\#+ END<sub>SRC</sub>
353
+
354
+ 5. The Termination Condition
355
+
356
+ When the desired fitness level is reached, you may want to end the
357
+ Neater run. If so, provide a block to do just that.
358
+
359
+ stop_on_fitness { |fitness, c|
360
+ puts "*** Generation Run *{c.generation_num}, best is *{fitness[:best]} ***\n\n"
361
+ fitness[:best] >= ALMOST_FIT
362
+ }
363
+ end
364
+
365
+ 3. Report Generating Block
366
+
367
+ This particular report block just adds something to the log. You could easily
368
+ replace that with a visual update if you like, etc.
369
+
370
+ report do |rept|
371
+ $log.info "REPORT *{rept.to_yaml}"
372
+ end
373
+
374
+ 4. Engine Run Block
375
+
376
+ The block here is called upon the completion of each generation. The
377
+ 'c' parameter is the RubyNEAT Controller, the same as given to the stop<sub>on</sub><sub>fitness</sub>
378
+ block.
379
+
380
+ run_engine do |c|
381
+ $log.info "******** Run of generation %s completed, history count %d ********" %
382
+ [c.generation_num, c.population_history.size]
383
+ end
384
+
385
+ ### Releases<a id="orgheadline40"></a>
386
+
387
+ 1. v0.4.0.alpha.4
388
+
389
+ - First crude cut of a dashboard rubyneat<sub>dashboard</sub>
390
+
391
+ 2. 0.3.5.alpha.6
392
+
393
+ - Command line workflow is a bit cleaner
394
+ - Removed neater examples completely and place them in
395
+ <https://github.com/flajann2/rubyneat_examples>
396
+ - Cleaned up the internal docs a bit
397
+ - Uniquely Generated Named Objects (UGNOs) cleaned up to be respectable
398
+
399
+ 3. 2015-06-08
400
+
401
+ - Working on the Iterated ES HyperNEAT still,
402
+ after being side-tracked by having to make a living.
403
+ Also creating a maze environment for the critters to
404
+ operate as bots in order to test the new ES HyperNEAT extension.
405
+ - rnDSL, as a result of TWEANN Compositions, is undergoing
406
+ radical changes. All example Neaters will be
407
+ eventually update to reflect the new syntax.
408
+
409
+ 4. 2014-09-25
410
+
411
+ Hot on the efforts on adding two major features to RubyNEAT:
412
+
413
+ - TWEANN Compositions &#x2013; you will be able to define composites of TWEANNs on
414
+ a per critter basis. This should mirror how, say, biological brains composite
415
+ themselves into regions of speciality. You may specify different selections
416
+ of neurons for each TWEANN. This is totally experiential, so we'll
417
+ see if this results in better convergence for some problems.
418
+
419
+ - iterated ES HyperNEAT &#x2013; one of the compsitions
420
+ above can be specified as a Hyper TWEANN, and just
421
+ represent one of the many compositions you may have.
422
+
423
+ - The syntax of the Neater DSL will change quite a bit to
424
+ reflect the new features, and all of the examples will
425
+ be rewritten to show this.
426
+
427
+ Do not confuse the ANN compositions here with CPPNs,
428
+ which are completely different. By default, all TWEANNs
429
+ in HyperNEAT are potential CPPNs anyway, as
430
+ you can specify more than one neuron type.
431
+
432
+ 5. 2014-08-03
433
+
434
+ Just released a very crude alpha cut of a
435
+ dashboard for RubyNEAT. You will have to
436
+ install it manually, along with rubyneat.
437
+ The gem is rubyneat<sub>dashboard</sub>.
438
+
439
+ - I am currently working on a Dashboard for RubyNEAT.
440
+ It will be a gemmable plugin that will allow you to
441
+ use the browser as the dashboard. It will have realtime
442
+ updates and the like, allowing you to monitor the progress
443
+ of your Neaters, and to view and possibly set parameters,
444
+ and to see what your Critters look like.
@@ -0,0 +1,525 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+
9
+ <title>RubyNEAT</title>
10
+ <meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.
11
+ ">
12
+
13
+ <link rel="stylesheet" href="/css/main.css">
14
+ <link rel="canonical" href="http://rubyneat.de/index.org">
15
+ <link rel="alternate" type="application/rss+xml" title="RubyNEAT" href="http://rubyneat.de/feed.xml">
16
+ </head>
17
+
18
+
19
+ <body>
20
+
21
+ <header class="site-header">
22
+
23
+ <div class="wrapper">
24
+
25
+ <a class="site-title" href="/">RubyNEAT</a>
26
+
27
+ <nav class="site-nav">
28
+ <a href="#" class="menu-icon">
29
+ <svg viewBox="0 0 18 15">
30
+ <path fill="#424242" d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.031C17.335,0,18,0.665,18,1.484L18,1.484z"/>
31
+ <path fill="#424242" d="M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0c0-0.82,0.665-1.484,1.484-1.484 h15.031C17.335,6.031,18,6.696,18,7.516L18,7.516z"/>
32
+ <path fill="#424242" d="M18,13.516C18,14.335,17.335,15,16.516,15H1.484C0.665,15,0,14.335,0,13.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.031C17.335,12.031,18,12.696,18,13.516L18,13.516z"/>
33
+ </svg>
34
+ </a>
35
+
36
+ <div class="trigger">
37
+
38
+
39
+ <a class="page-link" href="/about/">About</a>
40
+
41
+
42
+
43
+
44
+
45
+ <a class="page-link" href="/index.org">RubyNEAT</a>
46
+
47
+
48
+
49
+
50
+ </div>
51
+ </nav>
52
+
53
+ </div>
54
+
55
+ </header>
56
+
57
+
58
+ <div class="page-content">
59
+ <div class="wrapper">
60
+ * RubyNEAT -- Ruby implementation of Neural Evolution of Augmenting Topologies (NEAT)
61
+ ** What is NEAT?
62
+ NEAT is an acronym for Neural Evolution of Augmenting Topologies.
63
+ In short, neural nets that are evolved from a minimal topology,
64
+ allowing selection to decide on what topologies are most adequate
65
+ for resolving the problem at hand.
66
+
67
+ ** What is RubyNEAT?
68
+ RubyNEAT is the world's first (and currently only) implementation
69
+ of the NEAT algorithm in the Ruby programming language. RubyNEAT
70
+ leverages some of the benefits of Ruby, such as metaprogramming,
71
+ to implement activation of the Neural Net.
72
+
73
+ Basically, the Neural Nets in RubyNEAT manifests themselves in the
74
+ Phenotypes as functional programs -- of a sort. You may think of it
75
+ as an application of Genetic Programming techniques to resolving the
76
+ NEAT algorithm. As such, once fit Critters (neural nets) are found,
77
+ they may be extracted as pure Ruby code, not needing the
78
+ RubyNEAT engine for activation.
79
+
80
+ ** Architecture
81
+ RubyNEAT comprises many interacting modules. While it is
82
+ not strictly necessary to understand RubyNEAT at this level
83
+ of detail, it would be beneficial for a number of reasons,
84
+ especially in understanding how to tweak the parameters
85
+ to improve performance for your application.
86
+
87
+ RubyNEAT comprises the following modules:
88
+ Controller, Expressor, Evaluator, Evolver, Population, and Critter.
89
+
90
+ *** Controller
91
+ The Controller mediates all aspects of RubyNEAT
92
+ evolution, the various modules involved and their
93
+ interactions, and also holds the settings the other
94
+ modules will refer to.
95
+
96
+ The Controller is singular. There can only be one
97
+ Controller in the RubyNEAT system. All other objects
98
+ associated with the Controller shall have embedded
99
+ in them a reference to their controller.
100
+
101
+ *** Evolver
102
+ The Evolver module houses the evolving algorithms
103
+ for RubyNEAT. It evolves the entire Population of Critters.
104
+
105
+ *** Expressor
106
+ The Expressor module is responsible for interpreting
107
+ the Genotype of the Critters and creating their
108
+ Phenotypes. The default Expressor generates Ruby code
109
+ and attaches that code to the Phenotype instances of the Critter.
110
+
111
+ It is entirely possible to swap in a different Expressor and
112
+ generate code for a different target language, or create some
113
+ other construct. There is no limit to what you could
114
+ have an Expressor do.
115
+
116
+ *** Evaluator
117
+ The Evaluator is a kind of bridge between the inner "biology" of the RubyNEAT "ecosystem" and the outside world. It has ties to the RubyNEAT DSL where you encode your own fitness functions and data links to some external problem space. It is, in a sense, the "gateway".
118
+
119
+ *** Population
120
+ The Population is what your intuition tells you. It is a environment that houses a collection of Critters.
121
+
122
+ *** Critter
123
+ The Critter is the embodiment of both the genetics for the neural net and also the expression of the same. It contains, in other words, the Genotype and the Phenotype.
124
+
125
+ Critters are mated through the Evolver, and have their genes expressed through the Expressor.
126
+
127
+ ** Installation
128
+ You may install RubyNEAT by cloning the repo at GitHub:
129
+ [[https://github.com/flajann2/rubyneat][RubyNEAT Github]]
130
+
131
+ Or you may get it via a gem
132
+ #+BEGIN_SRC bash
133
+ gem install rubyneat --pre
134
+ #+END_SRC
135
+
136
+ *** Requirements
137
+ You will need at least Ruby 2.0.0, though we strongly recommend 2.1.1
138
+ or better. We will NOT be supporting 1.9.x,
139
+ as that is being phased out anyway.
140
+
141
+ ** Examples
142
+ Clone:
143
+
144
+ #+BEGIN_SRC bash
145
+ git clone git@github.com:flajann2/rubyneat_examples.git
146
+ #+END_SRC
147
+
148
+ and cd into the '''rubyneat_examples''' directory.
149
+
150
+ Type:
151
+
152
+ #+BEGIN_SRC bash
153
+ neat list neaters
154
+ #+END_SRC
155
+
156
+ to get a list of neaters. To run one like, say, the XOR test:
157
+
158
+ #+BEGIN_SRC bash
159
+ neat run xor
160
+ #+END_SRC
161
+
162
+ *** Note Well
163
+ The pole-balancing invpend neater is still under
164
+ development. It will display a window with the cart and pole,
165
+ but will not balance yet. Just a matter of me
166
+ finishing up that code. All the others work.
167
+
168
+ **** RubyNEAT
169
+ - GitHUB
170
+ [[https://github.com/flajann2/rubyneat][RubyNEAT GitHub]]
171
+
172
+ - Ruby GEM
173
+ #+BEGIN_SRC bash
174
+ gem install rubyneat --pre
175
+ #+END_SRC
176
+
177
+ **** RubyNEAT Examples
178
+ - Github
179
+ [[https://github.com/flajann2/rubyneat_examples][Example Neaters on GitHub]]
180
+
181
+ ** RubyNEAT DSL
182
+ I will take the '''XOR''' neater and document it.
183
+ This is not the perfect way to go,
184
+ but I will get more extensive later.
185
+
186
+ *** The XOR Neater Example
187
+ #+BEGIN_SRC ruby
188
+ require 'xor'
189
+ include NEAT::DSL
190
+ #+END_SRC
191
+
192
+ - The first lines here includes the special XOR library, which is basically:
193
+
194
+ #+BEGIN_SRC ruby
195
+ def xor(*inp)
196
+ inp.map{|n| (n > 0) ? 1 : 0}.reduce {|p, i| p + ((i > 0) ? 1 : 0) } == 1
197
+ end
198
+ #+END_SRC
199
+
200
+
201
+ -Basic settings for the '''XOR''', which can handle more than 2 inputs.
202
+
203
+ #+BEGIN_SRC ruby
204
+ XOR_INPUTS = 2
205
+ XOR_STATES = 2 ** XOR_INPUTS
206
+ MAX_FIT = XOR_STATES
207
+ ALMOST_FIT = XOR_STATES - 0.5
208
+ #+END_SRC
209
+
210
+ - The actual definition of the Neater. Here you specify the parameters RubyNEAT
211
+ will use to run the evolution, as well as the CPPN neuron types, the fitness function,
212
+ etc.
213
+
214
+ #+BEGIN_SRC ruby
215
+ define "XOR System" do
216
+ #+END_SRC
217
+
218
+ - Inputs defined as name: Neuron, name: Neuron ... hash. In this segment, we
219
+ create a block to generate the hash since we can have a variable number of
220
+ inputs to the XOR. The input names must be unique. Note that a bias neuron
221
+ is also supplied, and it is always called :bias.
222
+
223
+ #+BEGIN_SRC ruby
224
+ inputs {
225
+ cinv = Hash[(1..XOR_INPUTS).map{|i| [("i%s" % i).to_sym, InputNeuron]}]
226
+ cinv[:bias] = BiasNeuron
227
+ cinv
228
+ }
229
+ #+END_SRC
230
+
231
+ - Outputs are defined in a similar fashion to the inputs. The names of all the
232
+ output neurons must be unique. Here in this example we only have one output, and
233
+ we use the hyperbolic tan Neuron as the output. There is also a sigmoid Neuron
234
+ that could be used as well, but the input levels would have to be conditioned
235
+ to vary from 0 to 1 instead of from -1 to one.
236
+
237
+ #+BEGIN_SRC ruby
238
+ outputs out: TanhNeuron
239
+ #+END_SRC
240
+
241
+ - Hidden neuron specification is optional.
242
+ The names given here are largely meaningless, but but follow the same rules
243
+ for uniqueness. The neurons specified will be selected randomly as the topologies
244
+ are augmented.
245
+
246
+ #+BEGIN_SRC ruby
247
+ hidden tan: TanhNeuron
248
+ #+END_SRC
249
+
250
+ **** Settings
251
+ For RubyNEAT. Extensive documentation will be provided on a later date
252
+ as to the meanings, which closely follow the parameters for Ken Stanley's NEAT
253
+ implementation.
254
+
255
+ ****** General
256
+ #+BEGIN_SRC ruby
257
+ hash_on_fitness false
258
+ start_population_size 30
259
+ population_size 30
260
+ max_generations 10000
261
+ max_population_history 10
262
+ #+END_SRC
263
+
264
+ ****** Evolver probabilities and SDs
265
+ Perturbations
266
+ #+BEGIN_SRC ruby
267
+ mutate_perturb_gene_weights_prob 0.10
268
+ mutate_perturb_gene_weights_sd 0.25
269
+ #+END_SRC
270
+
271
+ ****** Complete Change of weight
272
+ #+BEGIN_SRC ruby
273
+ mutate_change_gene_weights_prob 0.10
274
+ mutate_change_gene_weights_sd 1.00
275
+ #+END_SRC
276
+
277
+ ****** Adding new neurons and genes
278
+ #+BEGIN_SRC ruby
279
+ mutate_add_neuron_prob 0.05
280
+ mutate_add_gene_prob 0.20
281
+ #+END_SRC
282
+
283
+ ****** Switching genes on and off
284
+ #+BEGIN_SRC ruby
285
+ mutate_gene_disable_prob 0.01
286
+ mutate_gene_reenable_prob 0.01
287
+
288
+ interspecies_mate_rate 0.03
289
+ mate_only_prob 0.10 *0.7
290
+ #+END_SRC
291
+
292
+ ****** Mating
293
+ #+BEGIN_SRC ruby
294
+ survival_threshold 0.20 # top % allowed to mate in a species.
295
+ survival_mininum_per_species 4 # for small populations, we need SOMETHING to go on.
296
+ #+END_SRC
297
+
298
+ ****** Fitness costs
299
+ #+BEGIN_SRC ruby
300
+ fitness_cost_per_neuron 0.00001
301
+ fitness_cost_per_gene 0.00001
302
+ #+END_SRC
303
+
304
+ ****** Speciation
305
+
306
+ #+BEGIN_SRC ruby
307
+ compatibility_threshold 2.5
308
+ disjoint_coefficient 0.6
309
+ excess_coefficient 0.6
310
+ weight_coefficient 0.2
311
+ max_species 20
312
+ dropoff_age 15
313
+ smallest_species 5
314
+ #+END_SRC
315
+
316
+ ****** Sequencing
317
+ The evaluation function is called repeatedly, and each iteration is given a
318
+ monotonically increasing integer which represents the sequence number. The results
319
+ of each run is returned, and those results are evaluated elsewhere in the Neater.
320
+
321
+ #+BEGIN_SRC ruby
322
+ start_sequence_at 0
323
+ end_sequence_at 2 ** XOR_INPUTS - 1
324
+ #+END_SRC
325
+
326
+ **** The Evolution Block
327
+
328
+ #+BEGIN_SRC ruby
329
+ evolve do
330
+ #+END_SRC
331
+
332
+ ****** The Query Block
333
+ This query shall return a vector result that will serve
334
+ as the inputs to the critter.
335
+
336
+ #+BEGIN_SRC ruby
337
+ query { |seq|
338
+ * We'll use the seq to create the xor sequences via
339
+ * the least signficant bits.
340
+ condition_boolean_vector (0 ... XOR_INPUTS).map{|i| (seq & (1 << i)) != 0}
341
+ }
342
+ #+END_SRC
343
+
344
+ ****** The Compare Block
345
+ Compare the fitness of two critters. We may choose a different ordering here.
346
+
347
+ #+BEGIN_SRC ruby
348
+ compare {|f1, f2| f2 <=> f1 }
349
+ #+END_SRC
350
+
351
+ ****** The Cost of Fitness Block
352
+ Here we integrate the cost with the fitness.
353
+
354
+ #+BEGIN_SRC ruby
355
+ cost { |fitvec, cost|
356
+ fit = XOR_STATES - fitvec.reduce {|a,r| a+r} - cost
357
+ $log.debug ">>>>>>> fitvec *{fitvec} => *{fit}, cost *{cost}"
358
+ fit
359
+ }
360
+ #+END_SRC
361
+
362
+ ****** The Fitness Block
363
+ The fitness block is called for each activation and is given the input vector,
364
+ the output vector, and the sequence number given to the query. The results are
365
+ evaluated and a fitness scalar is returned.
366
+
367
+ #+BEGIN_SRC ruby
368
+ fitness { |vin, vout, seq|
369
+ unless vout *** :error
370
+ bin = uncondition_boolean_vector vin
371
+ bout = uncondition_boolean_vector vout
372
+ bactual = [xor(*vin)]
373
+ vactual = condition_boolean_vector bactual
374
+ fit = (bout *** bactual) ? 0.00 : 1.00
375
+ *simple_fitness_error(vout, vactual.map{|f| f * 0.50 })
376
+ bfit = (bout *** bactual) ? 'T' : 'F'
377
+ fit
378
+ else
379
+ $log.debug "Error on *{vin} [*{seq}]"
380
+ 1.0
381
+ end
382
+ }
383
+ #+ END_SRC
384
+
385
+ ****** The Termination Condition
386
+ When the desired fitness level is reached, you may want to end the
387
+ Neater run. If so, provide a block to do just that.
388
+
389
+ #+BEGIN_SRC ruby
390
+ stop_on_fitness { |fitness, c|
391
+ puts "*** Generation Run *{c.generation_num}, best is *{fitness[:best]} ***\n\n"
392
+ fitness[:best] >= ALMOST_FIT
393
+ }
394
+ end
395
+ #+END_SRC
396
+
397
+ **** Report Generating Block
398
+ This particular report block just adds something to the log. You could easily
399
+ replace that with a visual update if you like, etc.
400
+
401
+ #+BEGIN_SRC ruby
402
+ report do |rept|
403
+ $log.info "REPORT *{rept.to_yaml}"
404
+ end
405
+ #+END_SRC
406
+
407
+ **** Engine Run Block
408
+ The block here is called upon the completion of each generation. The
409
+ 'c' parameter is the RubyNEAT Controller, the same as given to the stop_on_fitness
410
+ block.
411
+
412
+ #+BEGIN_SRC ruby
413
+ run_engine do |c|
414
+ $log.info "******** Run of generation %s completed, history count %d ********" %
415
+ [c.generation_num, c.population_history.size]
416
+ end
417
+ #+END_SRC
418
+
419
+ *** Releases
420
+ **** v0.4.0.alpha.4
421
+ + First crude cut of a dashboard rubyneat_dashboard
422
+
423
+ **** 0.3.5.alpha.6
424
+ + Command line workflow is a bit cleaner
425
+ + Removed neater examples completely and place them in
426
+ https://github.com/flajann2/rubyneat_examples
427
+ + Cleaned up the internal docs a bit
428
+ + Uniquely Generated Named Objects (UGNOs) cleaned up to be respectable
429
+
430
+ **** 2015-06-08
431
+ + Working on the Iterated ES HyperNEAT still,
432
+ after being side-tracked by having to make a living.
433
+ Also creating a maze environment for the critters to
434
+ operate as bots in order to test the new ES HyperNEAT extension.
435
+ + rnDSL, as a result of TWEANN Compositions, is undergoing
436
+ radical changes. All example Neaters will be
437
+ eventually update to reflect the new syntax.
438
+
439
+ **** 2014-09-25
440
+ Hot on the efforts on adding two major features to RubyNEAT:
441
+
442
+ + TWEANN Compositions -- you will be able to define composites of TWEANNs on
443
+ a per critter basis. This should mirror how, say, biological brains composite
444
+ themselves into regions of speciality. You may specify different selections
445
+ of neurons for each TWEANN. This is totally experiential, so we'll
446
+ see if this results in better convergence for some problems.
447
+
448
+ + iterated ES HyperNEAT -- one of the compsitions
449
+ above can be specified as a Hyper TWEANN, and just
450
+ represent one of the many compositions you may have.
451
+
452
+ + The syntax of the Neater DSL will change quite a bit to
453
+ reflect the new features, and all of the examples will
454
+ be rewritten to show this.
455
+
456
+ Do not confuse the ANN compositions here with CPPNs,
457
+ which are completely different. By default, all TWEANNs
458
+ in HyperNEAT are potential CPPNs anyway, as
459
+ you can specify more than one neuron type.
460
+
461
+ **** 2014-08-03
462
+ Just released a very crude alpha cut of a
463
+ dashboard for RubyNEAT. You will have to
464
+ install it manually, along with rubyneat.
465
+ The gem is rubyneat_dashboard.
466
+
467
+ + I am currently working on a Dashboard for RubyNEAT.
468
+ It will be a gemmable plugin that will allow you to
469
+ use the browser as the dashboard. It will have realtime
470
+ updates and the like, allowing you to monitor the progress
471
+ of your Neaters, and to view and possibly set parameters,
472
+ and to see what your Critters look like.
473
+
474
+
475
+ </div>
476
+ </div>
477
+
478
+ <footer class="site-footer">
479
+
480
+ <div class="wrapper">
481
+
482
+ <h2 class="footer-heading">RubyNEAT</h2>
483
+
484
+ <div class="footer-col-wrapper">
485
+ <div class="footer-col footer-col-1">
486
+ <ul class="contact-list">
487
+ <li>RubyNEAT</li>
488
+ <li><a href="mailto:fred.mitchell@gmx.de">fred.mitchell@gmx.de</a></li>
489
+ </ul>
490
+ </div>
491
+
492
+ <div class="footer-col footer-col-2">
493
+ <ul class="social-media-list">
494
+
495
+ <li>
496
+ <a href="https://github.com/flajann2"><span class="icon icon--github"><svg viewBox="0 0 16 16"><path fill="#828282" d="M7.999,0.431c-4.285,0-7.76,3.474-7.76,7.761 c0,3.428,2.223,6.337,5.307,7.363c0.388,0.071,0.53-0.168,0.53-0.374c0-0.184-0.007-0.672-0.01-1.32 c-2.159,0.469-2.614-1.04-2.614-1.04c-0.353-0.896-0.862-1.135-0.862-1.135c-0.705-0.481,0.053-0.472,0.053-0.472 c0.779,0.055,1.189,0.8,1.189,0.8c0.692,1.186,1.816,0.843,2.258,0.645c0.071-0.502,0.271-0.843,0.493-1.037 C4.86,11.425,3.049,10.76,3.049,7.786c0-0.847,0.302-1.54,0.799-2.082C3.768,5.507,3.501,4.718,3.924,3.65 c0,0,0.652-0.209,2.134,0.796C6.677,4.273,7.34,4.187,8,4.184c0.659,0.003,1.323,0.089,1.943,0.261 c1.482-1.004,2.132-0.796,2.132-0.796c0.423,1.068,0.157,1.857,0.077,2.054c0.497,0.542,0.798,1.235,0.798,2.082 c0,2.981-1.814,3.637-3.543,3.829c0.279,0.24,0.527,0.713,0.527,1.437c0,1.037-0.01,1.874-0.01,2.129 c0,0.208,0.14,0.449,0.534,0.373c3.081-1.028,5.302-3.935,5.302-7.362C15.76,3.906,12.285,0.431,7.999,0.431z"/></svg>
497
+ </span><span class="username">flajann2</span></a>
498
+
499
+ </li>
500
+
501
+
502
+
503
+ <li>
504
+ <a href="https://twitter.com/flajann"><span class="icon icon--twitter"><svg viewBox="0 0 16 16"><path fill="#828282" d="M15.969,3.058c-0.586,0.26-1.217,0.436-1.878,0.515c0.675-0.405,1.194-1.045,1.438-1.809c-0.632,0.375-1.332,0.647-2.076,0.793c-0.596-0.636-1.446-1.033-2.387-1.033c-1.806,0-3.27,1.464-3.27,3.27 c0,0.256,0.029,0.506,0.085,0.745C5.163,5.404,2.753,4.102,1.14,2.124C0.859,2.607,0.698,3.168,0.698,3.767 c0,1.134,0.577,2.135,1.455,2.722C1.616,6.472,1.112,6.325,0.671,6.08c0,0.014,0,0.027,0,0.041c0,1.584,1.127,2.906,2.623,3.206 C3.02,9.402,2.731,9.442,2.433,9.442c-0.211,0-0.416-0.021-0.615-0.059c0.416,1.299,1.624,2.245,3.055,2.271 c-1.119,0.877-2.529,1.4-4.061,1.4c-0.264,0-0.524-0.015-0.78-0.046c1.447,0.928,3.166,1.469,5.013,1.469 c6.015,0,9.304-4.983,9.304-9.304c0-0.142-0.003-0.283-0.009-0.423C14.976,4.29,15.531,3.714,15.969,3.058z"/></svg>
505
+ </span><span class="username">flajann</span></a>
506
+
507
+ </li>
508
+
509
+ </ul>
510
+ </div>
511
+
512
+ <div class="footer-col footer-col-3">
513
+ <p>Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.
514
+ </p>
515
+ </div>
516
+ </div>
517
+
518
+ </div>
519
+
520
+ </footer>
521
+
522
+
523
+ </body>
524
+
525
+ </html>