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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.sass-cache/bc401a9774cbf72f4f089136a23a587fd10c0a99/_base.scssc +0 -0
- data/.sass-cache/bc401a9774cbf72f4f089136a23a587fd10c0a99/_layout.scssc +0 -0
- data/.sass-cache/bc401a9774cbf72f4f089136a23a587fd10c0a99/_syntax-highlighting.scssc +0 -0
- data/.semver +1 -1
- data/Gemfile +4 -14
- data/Gemfile.lock +65 -62
- data/Gemfile.lock.orig +2 -2
- data/Gemfile.orig +2 -2
- data/README.md +2 -0
- data/Rakefile +3 -3
- data/_site/about/index.html +135 -0
- data/_site/css/main.css +457 -0
- data/_site/docs.md +285 -0
- data/_site/feed.xml +42 -0
- data/_site/index.html +858 -0
- data/_site/index.md +444 -0
- data/_site/index.org +525 -0
- data/_site/jekyll/update/2016/03/25/welcome-to-jekyll.html +136 -0
- data/_site/params.json +6 -0
- data/_site/stylesheets/github-light.css +116 -0
- data/_site/stylesheets/normalize.css +424 -0
- data/_site/stylesheets/stylesheet.css +245 -0
- data/rubyneat.gemspec +33 -24
- metadata +30 -43
data/_site/docs.md
ADDED
@@ -0,0 +1,285 @@
|
|
1
|
+
# Introduction to RubyNEAT
|
2
|
+
|
3
|
+
## What is NEAT?
|
4
|
+
NEAT is an acronym for Neural Evolution of Augmenting Topologies. In short, neural nets that are evolved from a minimal topology, allowing selection to decide on what topologies are most adequate for resolving the problem at hand.
|
5
|
+
|
6
|
+
## What is RubyNEAT?
|
7
|
+
RubyNEAT is the world's first (and currently only) implementation of the NEAT algorithm in the Ruby programming language. RubyNEAT leverages some of the benefits of Ruby, such as metaprogramming, to implement activation of the Neural Net.
|
8
|
+
|
9
|
+
Basically, the Neural Nets in RubyNEAT manifests themselves in the Phenotypes as functional programs -- of a sort. You may think of it as an application of Genetic Programming techniques to resolving the NEAT algorithm. As such, once fit Critters (neural nets) are found, they may be extracted as pure Ruby code, not needing the RubyNEAT engine for activation.
|
10
|
+
|
11
|
+
## Architecture
|
12
|
+
|
13
|
+
RubyNEAT comprises many interacting modules. While it is not strictly necessary to understand RubyNEAT at this level of detail, it would be beneficial for a number of reasons, especially in understanding how to tweak the parameters to improve performance for your application.
|
14
|
+
|
15
|
+
RubyNEAT comprises the following modules: Controller, Expressor, Evaluator, Evolver, Population, and Critter.
|
16
|
+
|
17
|
+
#### Controller
|
18
|
+
The Controller mediates all aspects of RubyNEAT evolution, the various modules involved and their interactions, and also holds the settings the other modules will refer to.
|
19
|
+
|
20
|
+
The Controller is singular. There can only be one Controller in the RubyNEAT system. All other objects associated with the Controller shall have embedded in them a reference to their controller.
|
21
|
+
|
22
|
+
#### Evolver
|
23
|
+
The Evolver module houses the evolving algorithms for RubyNEAT. It evolves the entire Population of Critters.
|
24
|
+
|
25
|
+
#### Expressor
|
26
|
+
The Expressor module is responsible for interpreting the Genotype of the Critters and creating their Phenotypes. The default Expressor generates Ruby code and attaches that code to the Phenotype instances of the Critter.
|
27
|
+
|
28
|
+
It is entirely possible to swap in a different Expressor and generate code for a different target language, or create some other construct. There is no limit to what you could have an Expressor do.
|
29
|
+
|
30
|
+
#### Evaluator
|
31
|
+
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".
|
32
|
+
|
33
|
+
#### Population
|
34
|
+
The Population is what your intuition tells you. It is a environment that houses a collection of Critters.
|
35
|
+
|
36
|
+
#### Critter
|
37
|
+
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.
|
38
|
+
|
39
|
+
Critters are mated through the Evolver, and have their genes expressed through the Expressor.
|
40
|
+
|
41
|
+
### Installation
|
42
|
+
|
43
|
+
You may install RubyNEAT by cloning the repo at GitHub:
|
44
|
+
[https://github.com/flajann2/rubyneat RubyNEAT Github]
|
45
|
+
|
46
|
+
Or you may get it via a gem
|
47
|
+
> gem install rubyneat --pre
|
48
|
+
|
49
|
+
#### Requirements
|
50
|
+
You will need at least Ruby 2.0.0, though we strongly recommend 2.1.1 or better. We will NOT be supporting 1.9.x, as that is being phased out anyway.
|
51
|
+
|
52
|
+
### Examples
|
53
|
+
Clone:
|
54
|
+
> git clone git@github.com:flajann2/rubyneat_examples.git
|
55
|
+
|
56
|
+
and cd into the '''rubyneat_examples''' directory.
|
57
|
+
|
58
|
+
Type:
|
59
|
+
> neat list neaters
|
60
|
+
|
61
|
+
to get a list of neaters. To run one like, say, the XOR test:
|
62
|
+
> neat run xor
|
63
|
+
|
64
|
+
### Note Well
|
65
|
+
The pole-balancing invpend neater is still under development. It will display a window with the cart and pole, but will not balance yet. Just a matter of me finishing up that code. All the others work.
|
66
|
+
|
67
|
+
#### RubyNEAT
|
68
|
+
|
69
|
+
* GitHUB
|
70
|
+
** [https://github.com/flajann2/rubyneat RubyNEAT GitHub]
|
71
|
+
|
72
|
+
* Ruby GEM
|
73
|
+
** > gem install rubyneat --pre
|
74
|
+
|
75
|
+
#### RubyNEAT Examples
|
76
|
+
* Github
|
77
|
+
** [https://github.com/flajann2/rubyneat_examples Example Neaters on GitHub]
|
78
|
+
|
79
|
+
### RubyNEAT DSL
|
80
|
+
|
81
|
+
I will take the '''XOR''' neater and document it. This is not the perfect way to go, but I will get more extensive later.
|
82
|
+
|
83
|
+
#### The XOR Neater Example
|
84
|
+
require 'xor'
|
85
|
+
include NEAT::DSL
|
86
|
+
|
87
|
+
-The first lines here includes the special XOR library, which is basically:
|
88
|
+
def xor(*inp)
|
89
|
+
inp.map{|n| (n > 0) ? 1 : 0}.reduce {|p, i| p + ((i > 0) ? 1 : 0) } == 1
|
90
|
+
end
|
91
|
+
-
|
92
|
+
|
93
|
+
-Basic settings for the '''XOR''', which can handle more than 2 inputs.
|
94
|
+
XOR_INPUTS = 2
|
95
|
+
XOR_STATES = 2 ** XOR_INPUTS
|
96
|
+
MAX_FIT = XOR_STATES
|
97
|
+
ALMOST_FIT = XOR_STATES - 0.5
|
98
|
+
|
99
|
+
- The actual definition of the Neater. Here you specify the parameters RubyNEAT
|
100
|
+
will use to run the evolution, as well as the CPPN neuron types, the fitness function,
|
101
|
+
etc.
|
102
|
+
define "XOR System" do
|
103
|
+
|
104
|
+
- Inputs defined as name: Neuron, name: Neuron ... hash. In this segment, we
|
105
|
+
create a block to generate the hash since we can have a variable number of
|
106
|
+
inputs to the XOR. The input names must be unique. Note that a bias neuron
|
107
|
+
is also supplied, and it is always called :bias.
|
108
|
+
inputs {
|
109
|
+
cinv = Hash[(1..XOR_INPUTS).map{|i| [("i%s" % i).to_sym, InputNeuron]}]
|
110
|
+
cinv[:bias] = BiasNeuron
|
111
|
+
cinv
|
112
|
+
}
|
113
|
+
|
114
|
+
- Outputs are defined in a similar fashion to the inputs. The names of all the
|
115
|
+
output neurons must be unique. Here in this example we only have one output, and
|
116
|
+
we use the hyperbolic tan Neuron as the output. There is also a sigmoid Neuron
|
117
|
+
that could be used as well, but the input levels would have to be conditioned
|
118
|
+
to vary from 0 to 1 instead of from -1 to one.
|
119
|
+
outputs out: TanhNeuron
|
120
|
+
|
121
|
+
- Hidden neuron specification is optional.
|
122
|
+
The names given here are largely meaningless, but but follow the same rules
|
123
|
+
for uniqueness. The neurons specified will be selected randomly as the topologies
|
124
|
+
are augmented.
|
125
|
+
hidden tan: TanhNeuron
|
126
|
+
|
127
|
+
##### Settings
|
128
|
+
For RubyNEAT. Extensive documentation will be provided on a later date
|
129
|
+
as to the meanings, which closely follow the parameters for Ken Stanley's NEAT
|
130
|
+
implementation.
|
131
|
+
####### General
|
132
|
+
hash_on_fitness false
|
133
|
+
start_population_size 30
|
134
|
+
population_size 30
|
135
|
+
max_generations 10000
|
136
|
+
max_population_history 10
|
137
|
+
|
138
|
+
####### Evolver probabilities and SDs
|
139
|
+
- Perturbations
|
140
|
+
mutate_perturb_gene_weights_prob 0.10
|
141
|
+
mutate_perturb_gene_weights_sd 0.25
|
142
|
+
|
143
|
+
####### Complete Change of weight
|
144
|
+
mutate_change_gene_weights_prob 0.10
|
145
|
+
mutate_change_gene_weights_sd 1.00
|
146
|
+
|
147
|
+
####### Adding new neurons and genes
|
148
|
+
mutate_add_neuron_prob 0.05
|
149
|
+
mutate_add_gene_prob 0.20
|
150
|
+
|
151
|
+
####### Switching genes on and off
|
152
|
+
mutate_gene_disable_prob 0.01
|
153
|
+
mutate_gene_reenable_prob 0.01
|
154
|
+
|
155
|
+
interspecies_mate_rate 0.03
|
156
|
+
mate_only_prob 0.10 #0.7
|
157
|
+
|
158
|
+
####### Mating
|
159
|
+
survival_threshold 0.20 # top % allowed to mate in a species.
|
160
|
+
survival_mininum_per_species 4 # for small populations, we need SOMETHING to go on.
|
161
|
+
|
162
|
+
####### Fitness costs
|
163
|
+
fitness_cost_per_neuron 0.00001
|
164
|
+
fitness_cost_per_gene 0.00001
|
165
|
+
|
166
|
+
####### Speciation
|
167
|
+
compatibility_threshold 2.5
|
168
|
+
disjoint_coefficient 0.6
|
169
|
+
excess_coefficient 0.6
|
170
|
+
weight_coefficient 0.2
|
171
|
+
max_species 20
|
172
|
+
dropoff_age 15
|
173
|
+
smallest_species 5
|
174
|
+
|
175
|
+
####### Sequencing
|
176
|
+
The evaluation function is called repeatedly, and each iteration is given a
|
177
|
+
monotonically increasing integer which represents the sequence number. The results
|
178
|
+
of each run is returned, and those results are evaluated elsewhere in the Neater.
|
179
|
+
start_sequence_at 0
|
180
|
+
end_sequence_at 2 ** XOR_INPUTS - 1
|
181
|
+
end
|
182
|
+
|
183
|
+
##### The Evolution Block
|
184
|
+
evolve do
|
185
|
+
|
186
|
+
####### The Query Block
|
187
|
+
This query shall return a vector result that will serve
|
188
|
+
as the inputs to the critter.
|
189
|
+
query { |seq|
|
190
|
+
# We'll use the seq to create the xor sequences via
|
191
|
+
# the least signficant bits.
|
192
|
+
condition_boolean_vector (0 ... XOR_INPUTS).map{|i| (seq & (1 << i)) != 0}
|
193
|
+
}
|
194
|
+
|
195
|
+
####### The Compare Block
|
196
|
+
Compare the fitness of two critters. We may choose a different ordering here.
|
197
|
+
compare {|f1, f2| f2 <=> f1 }
|
198
|
+
|
199
|
+
####### The Cost of Fitness Block
|
200
|
+
Here we integrate the cost with the fitness.
|
201
|
+
cost { |fitvec, cost|
|
202
|
+
fit = XOR_STATES - fitvec.reduce {|a,r| a+r} - cost
|
203
|
+
$log.debug ">>>>>>> fitvec #{fitvec} => #{fit}, cost #{cost}"
|
204
|
+
fit
|
205
|
+
}
|
206
|
+
|
207
|
+
####### The Fitness Block
|
208
|
+
The fitness block is called for each activation and is given the input vector,
|
209
|
+
the output vector, and the sequence number given to the query. The results are
|
210
|
+
evaluated and a fitness scalar is returned.
|
211
|
+
fitness { |vin, vout, seq|
|
212
|
+
unless vout ### :error
|
213
|
+
bin = uncondition_boolean_vector vin
|
214
|
+
bout = uncondition_boolean_vector vout
|
215
|
+
bactual = [xor(*vin)]
|
216
|
+
vactual = condition_boolean_vector bactual
|
217
|
+
fit = (bout ### bactual) ? 0.00 : 1.00
|
218
|
+
#simple_fitness_error(vout, vactual.map{|f| f * 0.50 })
|
219
|
+
bfit = (bout ### bactual) ? 'T' : 'F'
|
220
|
+
fit
|
221
|
+
else
|
222
|
+
$log.debug "Error on #{vin} [#{seq}]"
|
223
|
+
1.0
|
224
|
+
end
|
225
|
+
}
|
226
|
+
|
227
|
+
####### The Termination Condition
|
228
|
+
When the desired fitness level is reached, you may want to end the
|
229
|
+
Neater run. If so, provide a block to do just that.
|
230
|
+
stop_on_fitness { |fitness, c|
|
231
|
+
puts "*** Generation Run #{c.generation_num}, best is #{fitness[:best]} ***\n\n"
|
232
|
+
fitness[:best] >= ALMOST_FIT
|
233
|
+
}
|
234
|
+
end
|
235
|
+
|
236
|
+
##### Report Generating Block
|
237
|
+
This particular report block just adds something to the log. You could easily
|
238
|
+
replace that with a visual update if you like, etc.
|
239
|
+
report do |rept|
|
240
|
+
$log.info "REPORT #{rept.to_yaml}"
|
241
|
+
end
|
242
|
+
|
243
|
+
##### Engine Run Block
|
244
|
+
The block here is called upon the completion of each generation. The
|
245
|
+
'c' parameter is the RubyNEAT Controller, the same as given to the stop_on_fitness
|
246
|
+
block.
|
247
|
+
run_engine do |c|
|
248
|
+
$log.info "******** Run of generation %s completed, history count %d ********" %
|
249
|
+
[c.generation_num, c.population_history.size]
|
250
|
+
end
|
251
|
+
|
252
|
+
#### Releases
|
253
|
+
|
254
|
+
### v0.4.0.alpha.4
|
255
|
+
* First crude cut of a dashboard rubyneat_dashboard#
|
256
|
+
|
257
|
+
*** 0.3.5.alpha.6
|
258
|
+
* Command line workflow is a bit cleaner
|
259
|
+
* Removed neater examples completely and place them in
|
260
|
+
https://github.com/flajann2/rubyneat_examples
|
261
|
+
* Cleaned up the internal docs a bit
|
262
|
+
* Uniquely Generated Named Objects (UGNOs) cleaned up to be respectable
|
263
|
+
|
264
|
+
|
265
|
+
*** 2015-06-08
|
266
|
+
* Working on the Iterated ES HyperNEAT still, after being side-tracked by having to make a living. Also creating a maze environment for the critters to operate as bots in order to test the new ES HyperNEAT extension.
|
267
|
+
* rnDSL, as a result of TWEANN Compositions, is undergoing radical changes. All example Neaters will be eventually update to reflect the new syntax.
|
268
|
+
|
269
|
+
*** 2014-09-25
|
270
|
+
Hot on the efforts on adding two major features to RubyNEAT:
|
271
|
+
|
272
|
+
* TWEANN Compositions -- you will be able to define composites of TWEANNs on a per critter basis. This should mirror how, say, biological brains composite themselves into regions of speciality. You may specify different selections of neurons for each TWEANN. This is totally experiential, so we'll see if this results in better convergence for some problems.
|
273
|
+
|
274
|
+
* iterated ES HyperNEAT -- one of the compsitions above can be specified as a Hyper TWEANN, and just represent one of the many compositions you may have.
|
275
|
+
|
276
|
+
* The syntax of the Neater DSL will change quite a bit to reflect the new features, and all of the examples will be rewritten to show this.
|
277
|
+
|
278
|
+
Do not confuse the ANN compositions here with CPPNs, which are completely different. By default, all TWEANNs in HyperNEAT are potential CPPNs anyway, as you can specify more than one neuron type.
|
279
|
+
|
280
|
+
|
281
|
+
*** 2014-08-03
|
282
|
+
Just released a very crude alpha cut of a dashboard for RubyNEAT. You will have to install it manually, along with rubyneat. The gem is rubyneat_dashboard.
|
283
|
+
|
284
|
+
* I am currently working on a Dashboard for RubyNEAT. It will be a gemmable plugin that will allow you to use the browser as the dashboard. It will have realtime updates and the like, allowing you to monitor the progress of your Neaters, and to view and possibly set parameters, and to see what your Critters look like.
|
285
|
+
|
data/_site/feed.xml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
3
|
+
<channel>
|
4
|
+
<title>RubyNEAT</title>
|
5
|
+
<description>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.
|
6
|
+
</description>
|
7
|
+
<link>http://rubyneat.de/</link>
|
8
|
+
<atom:link href="http://rubyneat.de/feed.xml" rel="self" type="application/rss+xml"/>
|
9
|
+
<pubDate>Sat, 26 Mar 2016 01:52:52 +0100</pubDate>
|
10
|
+
<lastBuildDate>Sat, 26 Mar 2016 01:52:52 +0100</lastBuildDate>
|
11
|
+
<generator>Jekyll v3.1.2</generator>
|
12
|
+
|
13
|
+
<item>
|
14
|
+
<title>Welcome to Jekyll!</title>
|
15
|
+
<description><p>You’ll find this post in your <code class="highlighter-rouge">_posts</code> directory. Go ahead and edit it and re-build the site to see your changes. You can rebuild the site in many different ways, but the most common way is to run <code class="highlighter-rouge">jekyll serve</code>, which launches a web server and auto-regenerates your site when a file is updated.</p>
|
16
|
+
|
17
|
+
<p>To add new posts, simply add a file in the <code class="highlighter-rouge">_posts</code> directory that follows the convention <code class="highlighter-rouge">YYYY-MM-DD-name-of-post.ext</code> and includes the necessary front matter. Take a look at the source for this post to get an idea about how it works.</p>
|
18
|
+
|
19
|
+
<p>Jekyll also offers powerful support for code snippets:</p>
|
20
|
+
|
21
|
+
<figure class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">def</span> <span class="nf">print_hi</span><span class="p">(</span><span class="nb">name</span><span class="p">)</span>
|
22
|
+
<span class="nb">puts</span> <span class="s2">"Hi, </span><span class="si">#{</span><span class="nb">name</span><span class="si">}</span><span class="s2">"</span>
|
23
|
+
<span class="k">end</span>
|
24
|
+
<span class="n">print_hi</span><span class="p">(</span><span class="s1">'Tom'</span><span class="p">)</span>
|
25
|
+
<span class="c1">#=&gt; prints 'Hi, Tom' to STDOUT.</span></code></pre></figure>
|
26
|
+
|
27
|
+
<p>Check out the <a href="http://jekyllrb.com/docs/home">Jekyll docs</a> for more info on how to get the most out of Jekyll. File all bugs/feature requests at <a href="https://github.com/jekyll/jekyll">Jekyll’s GitHub repo</a>. If you have questions, you can ask them on <a href="https://talk.jekyllrb.com/">Jekyll Talk</a>.</p>
|
28
|
+
|
29
|
+
</description>
|
30
|
+
<pubDate>Fri, 25 Mar 2016 23:35:08 +0100</pubDate>
|
31
|
+
<link>http://rubyneat.de/jekyll/update/2016/03/25/welcome-to-jekyll.html</link>
|
32
|
+
<guid isPermaLink="true">http://rubyneat.de/jekyll/update/2016/03/25/welcome-to-jekyll.html</guid>
|
33
|
+
|
34
|
+
|
35
|
+
<category>jekyll</category>
|
36
|
+
|
37
|
+
<category>update</category>
|
38
|
+
|
39
|
+
</item>
|
40
|
+
|
41
|
+
</channel>
|
42
|
+
</rss>
|
data/_site/index.html
ADDED
@@ -0,0 +1,858 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
5
|
+
<head>
|
6
|
+
<!-- 2016-03-26 Sat 01:43 -->
|
7
|
+
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
9
|
+
<title></title>
|
10
|
+
<meta name="generator" content="Org-mode" />
|
11
|
+
<meta name="author" content="Lord Alveric" />
|
12
|
+
<style type="text/css">
|
13
|
+
<!--/*--><![CDATA[/*><!--*/
|
14
|
+
.title { text-align: center;
|
15
|
+
margin-bottom: .2em; }
|
16
|
+
.subtitle { text-align: center;
|
17
|
+
font-size: medium;
|
18
|
+
font-weight: bold;
|
19
|
+
margin-top:0; }
|
20
|
+
.todo { font-family: monospace; color: red; }
|
21
|
+
.done { font-family: monospace; color: green; }
|
22
|
+
.priority { font-family: monospace; color: orange; }
|
23
|
+
.tag { background-color: #eee; font-family: monospace;
|
24
|
+
padding: 2px; font-size: 80%; font-weight: normal; }
|
25
|
+
.timestamp { color: #bebebe; }
|
26
|
+
.timestamp-kwd { color: #5f9ea0; }
|
27
|
+
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
|
28
|
+
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
|
29
|
+
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
|
30
|
+
.underline { text-decoration: underline; }
|
31
|
+
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
|
32
|
+
p.verse { margin-left: 3%; }
|
33
|
+
pre {
|
34
|
+
border: 1px solid #ccc;
|
35
|
+
box-shadow: 3px 3px 3px #eee;
|
36
|
+
padding: 8pt;
|
37
|
+
font-family: monospace;
|
38
|
+
overflow: auto;
|
39
|
+
margin: 1.2em;
|
40
|
+
}
|
41
|
+
pre.src {
|
42
|
+
position: relative;
|
43
|
+
overflow: visible;
|
44
|
+
padding-top: 1.2em;
|
45
|
+
}
|
46
|
+
pre.src:before {
|
47
|
+
display: none;
|
48
|
+
position: absolute;
|
49
|
+
background-color: white;
|
50
|
+
top: -10px;
|
51
|
+
right: 10px;
|
52
|
+
padding: 3px;
|
53
|
+
border: 1px solid black;
|
54
|
+
}
|
55
|
+
pre.src:hover:before { display: inline;}
|
56
|
+
pre.src-sh:before { content: 'sh'; }
|
57
|
+
pre.src-bash:before { content: 'sh'; }
|
58
|
+
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
|
59
|
+
pre.src-R:before { content: 'R'; }
|
60
|
+
pre.src-perl:before { content: 'Perl'; }
|
61
|
+
pre.src-java:before { content: 'Java'; }
|
62
|
+
pre.src-sql:before { content: 'SQL'; }
|
63
|
+
|
64
|
+
table { border-collapse:collapse; }
|
65
|
+
caption.t-above { caption-side: top; }
|
66
|
+
caption.t-bottom { caption-side: bottom; }
|
67
|
+
td, th { vertical-align:top; }
|
68
|
+
th.org-right { text-align: center; }
|
69
|
+
th.org-left { text-align: center; }
|
70
|
+
th.org-center { text-align: center; }
|
71
|
+
td.org-right { text-align: right; }
|
72
|
+
td.org-left { text-align: left; }
|
73
|
+
td.org-center { text-align: center; }
|
74
|
+
dt { font-weight: bold; }
|
75
|
+
.footpara { display: inline; }
|
76
|
+
.footdef { margin-bottom: 1em; }
|
77
|
+
.figure { padding: 1em; }
|
78
|
+
.figure p { text-align: center; }
|
79
|
+
.inlinetask {
|
80
|
+
padding: 10px;
|
81
|
+
border: 2px solid gray;
|
82
|
+
margin: 10px;
|
83
|
+
background: #ffffcc;
|
84
|
+
}
|
85
|
+
#org-div-home-and-up
|
86
|
+
{ text-align: right; font-size: 70%; white-space: nowrap; }
|
87
|
+
textarea { overflow-x: auto; }
|
88
|
+
.linenr { font-size: smaller }
|
89
|
+
.code-highlighted { background-color: #ffff00; }
|
90
|
+
.org-info-js_info-navigation { border-style: none; }
|
91
|
+
#org-info-js_console-label
|
92
|
+
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
|
93
|
+
.org-info-js_search-highlight
|
94
|
+
{ background-color: #ffff00; color: #000000; font-weight: bold; }
|
95
|
+
/*]]>*/-->
|
96
|
+
</style>
|
97
|
+
<script type="text/javascript">
|
98
|
+
/*
|
99
|
+
@licstart The following is the entire license notice for the
|
100
|
+
JavaScript code in this tag.
|
101
|
+
|
102
|
+
Copyright (C) 2012-2013 Free Software Foundation, Inc.
|
103
|
+
|
104
|
+
The JavaScript code in this tag is free software: you can
|
105
|
+
redistribute it and/or modify it under the terms of the GNU
|
106
|
+
General Public License (GNU GPL) as published by the Free Software
|
107
|
+
Foundation, either version 3 of the License, or (at your option)
|
108
|
+
any later version. The code is distributed WITHOUT ANY WARRANTY;
|
109
|
+
without even the implied warranty of MERCHANTABILITY or FITNESS
|
110
|
+
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
|
111
|
+
|
112
|
+
As additional permission under GNU GPL version 3 section 7, you
|
113
|
+
may distribute non-source (e.g., minimized or compacted) forms of
|
114
|
+
that code without the copy of the GNU GPL normally required by
|
115
|
+
section 4, provided you include this license notice and a URL
|
116
|
+
through which recipients can access the Corresponding Source.
|
117
|
+
|
118
|
+
|
119
|
+
@licend The above is the entire license notice
|
120
|
+
for the JavaScript code in this tag.
|
121
|
+
*/
|
122
|
+
<!--/*--><![CDATA[/*><!--*/
|
123
|
+
function CodeHighlightOn(elem, id)
|
124
|
+
{
|
125
|
+
var target = document.getElementById(id);
|
126
|
+
if(null != target) {
|
127
|
+
elem.cacheClassElem = elem.className;
|
128
|
+
elem.cacheClassTarget = target.className;
|
129
|
+
target.className = "code-highlighted";
|
130
|
+
elem.className = "code-highlighted";
|
131
|
+
}
|
132
|
+
}
|
133
|
+
function CodeHighlightOff(elem, id)
|
134
|
+
{
|
135
|
+
var target = document.getElementById(id);
|
136
|
+
if(elem.cacheClassElem)
|
137
|
+
elem.className = elem.cacheClassElem;
|
138
|
+
if(elem.cacheClassTarget)
|
139
|
+
target.className = elem.cacheClassTarget;
|
140
|
+
}
|
141
|
+
/*]]>*///-->
|
142
|
+
</script>
|
143
|
+
</head>
|
144
|
+
<body>
|
145
|
+
<div id="content">
|
146
|
+
<div id="table-of-contents">
|
147
|
+
<h2>Table of Contents</h2>
|
148
|
+
<div id="text-table-of-contents">
|
149
|
+
<ul>
|
150
|
+
<li><a href="#orgheadline42">1. RubyNEAT – Ruby implementation of Neural Evolution of Augmenting Topologies (NEAT)</a>
|
151
|
+
<ul>
|
152
|
+
<li><a href="#orgheadline1">1.1. What is NEAT?</a></li>
|
153
|
+
<li><a href="#orgheadline2">1.2. What is RubyNEAT?</a></li>
|
154
|
+
<li><a href="#orgheadline9">1.3. Architecture</a>
|
155
|
+
<ul>
|
156
|
+
<li><a href="#orgheadline3">1.3.1. Controller</a></li>
|
157
|
+
<li><a href="#orgheadline4">1.3.2. Evolver</a></li>
|
158
|
+
<li><a href="#orgheadline5">1.3.3. Expressor</a></li>
|
159
|
+
<li><a href="#orgheadline6">1.3.4. Evaluator</a></li>
|
160
|
+
<li><a href="#orgheadline7">1.3.5. Population</a></li>
|
161
|
+
<li><a href="#orgheadline8">1.3.6. Critter</a></li>
|
162
|
+
</ul>
|
163
|
+
</li>
|
164
|
+
<li><a href="#orgheadline11">1.4. Installation</a>
|
165
|
+
<ul>
|
166
|
+
<li><a href="#orgheadline10">1.4.1. Requirements</a></li>
|
167
|
+
</ul>
|
168
|
+
</li>
|
169
|
+
<li><a href="#orgheadline15">1.5. Examples</a>
|
170
|
+
<ul>
|
171
|
+
<li><a href="#orgheadline14">1.5.1. Note Well</a></li>
|
172
|
+
</ul>
|
173
|
+
</li>
|
174
|
+
<li><a href="#orgheadline41">1.6. RubyNEAT DSL</a>
|
175
|
+
<ul>
|
176
|
+
<li><a href="#orgheadline34">1.6.1. The XOR Neater Example</a></li>
|
177
|
+
<li><a href="#orgheadline40">1.6.2. Releases</a></li>
|
178
|
+
</ul>
|
179
|
+
</li>
|
180
|
+
</ul>
|
181
|
+
</li>
|
182
|
+
</ul>
|
183
|
+
</div>
|
184
|
+
</div>
|
185
|
+
<p>
|
186
|
+
—
|
187
|
+
layout: default
|
188
|
+
title: RubyNEAT
|
189
|
+
—
|
190
|
+
</p>
|
191
|
+
<div id="outline-container-orgheadline42" class="outline-2">
|
192
|
+
<h2 id="orgheadline42"><span class="section-number-2">1</span> RubyNEAT – Ruby implementation of Neural Evolution of Augmenting Topologies (NEAT)</h2>
|
193
|
+
<div class="outline-text-2" id="text-1">
|
194
|
+
</div><div id="outline-container-orgheadline1" class="outline-3">
|
195
|
+
<h3 id="orgheadline1"><span class="section-number-3">1.1</span> What is NEAT?</h3>
|
196
|
+
<div class="outline-text-3" id="text-1-1">
|
197
|
+
<p>
|
198
|
+
NEAT is an acronym for Neural Evolution of Augmenting Topologies.
|
199
|
+
In short, neural nets that are evolved from a minimal topology,
|
200
|
+
allowing selection to decide on what topologies are most adequate
|
201
|
+
for resolving the problem at hand.
|
202
|
+
</p>
|
203
|
+
</div>
|
204
|
+
</div>
|
205
|
+
|
206
|
+
<div id="outline-container-orgheadline2" class="outline-3">
|
207
|
+
<h3 id="orgheadline2"><span class="section-number-3">1.2</span> What is RubyNEAT?</h3>
|
208
|
+
<div class="outline-text-3" id="text-1-2">
|
209
|
+
<p>
|
210
|
+
RubyNEAT is the world's first (and currently only) implementation
|
211
|
+
of the NEAT algorithm in the Ruby programming language. RubyNEAT
|
212
|
+
leverages some of the benefits of Ruby, such as metaprogramming,
|
213
|
+
to implement activation of the Neural Net.
|
214
|
+
</p>
|
215
|
+
|
216
|
+
<p>
|
217
|
+
Basically, the Neural Nets in RubyNEAT manifests themselves in the
|
218
|
+
Phenotypes as functional programs – of a sort. You may think of it
|
219
|
+
as an application of Genetic Programming techniques to resolving the
|
220
|
+
NEAT algorithm. As such, once fit Critters (neural nets) are found,
|
221
|
+
they may be extracted as pure Ruby code, not needing the
|
222
|
+
RubyNEAT engine for activation.
|
223
|
+
</p>
|
224
|
+
</div>
|
225
|
+
</div>
|
226
|
+
|
227
|
+
<div id="outline-container-orgheadline9" class="outline-3">
|
228
|
+
<h3 id="orgheadline9"><span class="section-number-3">1.3</span> Architecture</h3>
|
229
|
+
<div class="outline-text-3" id="text-1-3">
|
230
|
+
<p>
|
231
|
+
RubyNEAT comprises many interacting modules. While it is
|
232
|
+
not strictly necessary to understand RubyNEAT at this level
|
233
|
+
of detail, it would be beneficial for a number of reasons,
|
234
|
+
especially in understanding how to tweak the parameters
|
235
|
+
to improve performance for your application.
|
236
|
+
</p>
|
237
|
+
|
238
|
+
<p>
|
239
|
+
RubyNEAT comprises the following modules:
|
240
|
+
Controller, Expressor, Evaluator, Evolver, Population, and Critter.
|
241
|
+
</p>
|
242
|
+
</div>
|
243
|
+
|
244
|
+
<div id="outline-container-orgheadline3" class="outline-4">
|
245
|
+
<h4 id="orgheadline3"><span class="section-number-4">1.3.1</span> Controller</h4>
|
246
|
+
<div class="outline-text-4" id="text-1-3-1">
|
247
|
+
<p>
|
248
|
+
The Controller mediates all aspects of RubyNEAT
|
249
|
+
evolution, the various modules involved and their
|
250
|
+
interactions, and also holds the settings the other
|
251
|
+
modules will refer to.
|
252
|
+
</p>
|
253
|
+
|
254
|
+
<p>
|
255
|
+
The Controller is singular. There can only be one
|
256
|
+
Controller in the RubyNEAT system. All other objects
|
257
|
+
associated with the Controller shall have embedded
|
258
|
+
in them a reference to their controller.
|
259
|
+
</p>
|
260
|
+
</div>
|
261
|
+
</div>
|
262
|
+
|
263
|
+
<div id="outline-container-orgheadline4" class="outline-4">
|
264
|
+
<h4 id="orgheadline4"><span class="section-number-4">1.3.2</span> Evolver</h4>
|
265
|
+
<div class="outline-text-4" id="text-1-3-2">
|
266
|
+
<p>
|
267
|
+
The Evolver module houses the evolving algorithms
|
268
|
+
for RubyNEAT. It evolves the entire Population of Critters.
|
269
|
+
</p>
|
270
|
+
</div>
|
271
|
+
</div>
|
272
|
+
|
273
|
+
<div id="outline-container-orgheadline5" class="outline-4">
|
274
|
+
<h4 id="orgheadline5"><span class="section-number-4">1.3.3</span> Expressor</h4>
|
275
|
+
<div class="outline-text-4" id="text-1-3-3">
|
276
|
+
<p>
|
277
|
+
The Expressor module is responsible for interpreting
|
278
|
+
the Genotype of the Critters and creating their
|
279
|
+
Phenotypes. The default Expressor generates Ruby code
|
280
|
+
and attaches that code to the Phenotype instances of the Critter.
|
281
|
+
</p>
|
282
|
+
|
283
|
+
<p>
|
284
|
+
It is entirely possible to swap in a different Expressor and
|
285
|
+
generate code for a different target language, or create some
|
286
|
+
other construct. There is no limit to what you could
|
287
|
+
have an Expressor do.
|
288
|
+
</p>
|
289
|
+
</div>
|
290
|
+
</div>
|
291
|
+
|
292
|
+
<div id="outline-container-orgheadline6" class="outline-4">
|
293
|
+
<h4 id="orgheadline6"><span class="section-number-4">1.3.4</span> Evaluator</h4>
|
294
|
+
<div class="outline-text-4" id="text-1-3-4">
|
295
|
+
<p>
|
296
|
+
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".
|
297
|
+
</p>
|
298
|
+
</div>
|
299
|
+
</div>
|
300
|
+
|
301
|
+
<div id="outline-container-orgheadline7" class="outline-4">
|
302
|
+
<h4 id="orgheadline7"><span class="section-number-4">1.3.5</span> Population</h4>
|
303
|
+
<div class="outline-text-4" id="text-1-3-5">
|
304
|
+
<p>
|
305
|
+
The Population is what your intuition tells you. It is a environment that houses a collection of Critters.
|
306
|
+
</p>
|
307
|
+
</div>
|
308
|
+
</div>
|
309
|
+
|
310
|
+
<div id="outline-container-orgheadline8" class="outline-4">
|
311
|
+
<h4 id="orgheadline8"><span class="section-number-4">1.3.6</span> Critter</h4>
|
312
|
+
<div class="outline-text-4" id="text-1-3-6">
|
313
|
+
<p>
|
314
|
+
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.
|
315
|
+
</p>
|
316
|
+
|
317
|
+
<p>
|
318
|
+
Critters are mated through the Evolver, and have their genes expressed through the Expressor.
|
319
|
+
</p>
|
320
|
+
</div>
|
321
|
+
</div>
|
322
|
+
</div>
|
323
|
+
|
324
|
+
<div id="outline-container-orgheadline11" class="outline-3">
|
325
|
+
<h3 id="orgheadline11"><span class="section-number-3">1.4</span> Installation</h3>
|
326
|
+
<div class="outline-text-3" id="text-1-4">
|
327
|
+
<p>
|
328
|
+
You may install RubyNEAT by cloning the repo at GitHub:
|
329
|
+
<a href="https://github.com/flajann2/rubyneat">RubyNEAT Github</a>
|
330
|
+
</p>
|
331
|
+
|
332
|
+
<p>
|
333
|
+
Or you may get it via a gem
|
334
|
+
</p>
|
335
|
+
<div class="org-src-container">
|
336
|
+
|
337
|
+
<pre class="src src-bash">gem install rubyneat --pre
|
338
|
+
</pre>
|
339
|
+
</div>
|
340
|
+
</div>
|
341
|
+
|
342
|
+
<div id="outline-container-orgheadline10" class="outline-4">
|
343
|
+
<h4 id="orgheadline10"><span class="section-number-4">1.4.1</span> Requirements</h4>
|
344
|
+
<div class="outline-text-4" id="text-1-4-1">
|
345
|
+
<p>
|
346
|
+
You will need at least Ruby 2.0.0, though we strongly recommend 2.1.1
|
347
|
+
or better. We will NOT be supporting 1.9.x,
|
348
|
+
as that is being phased out anyway.
|
349
|
+
</p>
|
350
|
+
</div>
|
351
|
+
</div>
|
352
|
+
</div>
|
353
|
+
|
354
|
+
<div id="outline-container-orgheadline15" class="outline-3">
|
355
|
+
<h3 id="orgheadline15"><span class="section-number-3">1.5</span> Examples</h3>
|
356
|
+
<div class="outline-text-3" id="text-1-5">
|
357
|
+
<p>
|
358
|
+
Clone:
|
359
|
+
</p>
|
360
|
+
|
361
|
+
<div class="org-src-container">
|
362
|
+
|
363
|
+
<pre class="src src-bash">git clone git@github.com:flajann2/rubyneat_examples.git
|
364
|
+
</pre>
|
365
|
+
</div>
|
366
|
+
|
367
|
+
<p>
|
368
|
+
and cd into the '''rubyneat<sub>examples</sub>''' directory.
|
369
|
+
</p>
|
370
|
+
|
371
|
+
<p>
|
372
|
+
Type:
|
373
|
+
</p>
|
374
|
+
|
375
|
+
<div class="org-src-container">
|
376
|
+
|
377
|
+
<pre class="src src-bash">neat list neaters
|
378
|
+
</pre>
|
379
|
+
</div>
|
380
|
+
|
381
|
+
<p>
|
382
|
+
to get a list of neaters. To run one like, say, the XOR test:
|
383
|
+
</p>
|
384
|
+
|
385
|
+
<div class="org-src-container">
|
386
|
+
|
387
|
+
<pre class="src src-bash">neat run xor
|
388
|
+
</pre>
|
389
|
+
</div>
|
390
|
+
</div>
|
391
|
+
|
392
|
+
<div id="outline-container-orgheadline14" class="outline-4">
|
393
|
+
<h4 id="orgheadline14"><span class="section-number-4">1.5.1</span> Note Well</h4>
|
394
|
+
<div class="outline-text-4" id="text-1-5-1">
|
395
|
+
<p>
|
396
|
+
The pole-balancing invpend neater is still under
|
397
|
+
development. It will display a window with the cart and pole,
|
398
|
+
but will not balance yet. Just a matter of me
|
399
|
+
finishing up that code. All the others work.
|
400
|
+
</p>
|
401
|
+
</div>
|
402
|
+
|
403
|
+
<ol class="org-ol"><li><a id="orgheadline12"></a>RubyNEAT<br /><div class="outline-text-5" id="text-1-5-1-1">
|
404
|
+
<ul class="org-ul">
|
405
|
+
<li>GitHUB
|
406
|
+
<a href="https://github.com/flajann2/rubyneat">RubyNEAT GitHub</a></li>
|
407
|
+
|
408
|
+
<li><p>
|
409
|
+
Ruby GEM
|
410
|
+
</p>
|
411
|
+
<div class="org-src-container">
|
412
|
+
|
413
|
+
<pre class="src src-bash">gem install rubyneat --pre
|
414
|
+
</pre>
|
415
|
+
</div></li>
|
416
|
+
</ul>
|
417
|
+
</div></li>
|
418
|
+
|
419
|
+
<li><a id="orgheadline13"></a>RubyNEAT Examples<br /><div class="outline-text-5" id="text-1-5-1-2">
|
420
|
+
<ul class="org-ul">
|
421
|
+
<li>Github
|
422
|
+
<a href="https://github.com/flajann2/rubyneat_examples">Example Neaters on GitHub</a></li>
|
423
|
+
</ul>
|
424
|
+
</div></li></ol>
|
425
|
+
</div>
|
426
|
+
</div>
|
427
|
+
|
428
|
+
<div id="outline-container-orgheadline41" class="outline-3">
|
429
|
+
<h3 id="orgheadline41"><span class="section-number-3">1.6</span> RubyNEAT DSL</h3>
|
430
|
+
<div class="outline-text-3" id="text-1-6">
|
431
|
+
<p>
|
432
|
+
I will take the '''XOR''' neater and document it.
|
433
|
+
This is not the perfect way to go,
|
434
|
+
but I will get more extensive later.
|
435
|
+
</p>
|
436
|
+
</div>
|
437
|
+
|
438
|
+
<div id="outline-container-orgheadline34" class="outline-4">
|
439
|
+
<h4 id="orgheadline34"><span class="section-number-4">1.6.1</span> The XOR Neater Example</h4>
|
440
|
+
<div class="outline-text-4" id="text-1-6-1">
|
441
|
+
<div class="org-src-container">
|
442
|
+
|
443
|
+
<pre class="src src-ruby">require <span style="color: #d01A4E;">'xor'</span>
|
444
|
+
include <span style="color: #268bd2;">NEAT</span>::<span style="color: #268bd2;">DSL</span>
|
445
|
+
</pre>
|
446
|
+
</div>
|
447
|
+
|
448
|
+
<ul class="org-ul">
|
449
|
+
<li>The first lines here includes the special XOR library, which is basically:</li>
|
450
|
+
</ul>
|
451
|
+
|
452
|
+
<div class="org-src-container">
|
453
|
+
|
454
|
+
<pre class="src src-ruby"><span style="color: #b58900; font-weight: bold;">def</span> <span style="color: #2aa198;">xor</span>(*inp)
|
455
|
+
inp.map{|n| (n > 0) ? 1 : 0}.reduce {|p, i| p + ((i > 0) ? 1 : 0) } == 1
|
456
|
+
<span style="color: #b58900; font-weight: bold;">end</span>
|
457
|
+
</pre>
|
458
|
+
</div>
|
459
|
+
|
460
|
+
|
461
|
+
<p>
|
462
|
+
-Basic settings for the '''XOR''', which can handle more than 2 inputs.
|
463
|
+
</p>
|
464
|
+
|
465
|
+
<div class="org-src-container">
|
466
|
+
|
467
|
+
<pre class="src src-ruby"><span style="color: #268bd2;">XOR_INPUTS</span> = 2
|
468
|
+
<span style="color: #268bd2;">XOR_STATES</span> = 2 ** <span style="color: #268bd2;">XOR_INPUTS</span>
|
469
|
+
<span style="color: #268bd2;">MAX_FIT</span> = <span style="color: #268bd2;">XOR_STATES</span>
|
470
|
+
<span style="color: #268bd2;">ALMOST_FIT</span> = <span style="color: #268bd2;">XOR_STATES</span> - 0.5
|
471
|
+
</pre>
|
472
|
+
</div>
|
473
|
+
|
474
|
+
<ul class="org-ul">
|
475
|
+
<li>The actual definition of the Neater. Here you specify the parameters RubyNEAT
|
476
|
+
will use to run the evolution, as well as the CPPN neuron types, the fitness function,
|
477
|
+
etc.</li>
|
478
|
+
</ul>
|
479
|
+
|
480
|
+
<div class="org-src-container">
|
481
|
+
|
482
|
+
<pre class="src src-ruby">define <span style="color: #d01A4E;">"XOR System"</span> <span style="color: #b58900; font-weight: bold;">do</span>
|
483
|
+
</pre>
|
484
|
+
</div>
|
485
|
+
|
486
|
+
<ul class="org-ul">
|
487
|
+
<li>Inputs defined as name: Neuron, name: Neuron … hash. In this segment, we
|
488
|
+
create a block to generate the hash since we can have a variable number of
|
489
|
+
inputs to the XOR. The input names must be unique. Note that a bias neuron
|
490
|
+
is also supplied, and it is always called :bias.</li>
|
491
|
+
</ul>
|
492
|
+
|
493
|
+
<div class="org-src-container">
|
494
|
+
|
495
|
+
<pre class="src src-ruby">inputs {
|
496
|
+
cinv = <span style="color: #268bd2;">Hash</span>[(1..<span style="color: #268bd2;">XOR_INPUTS</span>).map{|i| [(<span style="color: #d01A4E;">"i%s"</span> % i).to_sym, <span style="color: #268bd2;">InputNeuron</span>]}]
|
497
|
+
cinv[<span style="color: #BFEBBF;">:bias</span>] = <span style="color: #268bd2;">BiasNeuron</span>
|
498
|
+
cinv
|
499
|
+
}
|
500
|
+
</pre>
|
501
|
+
</div>
|
502
|
+
|
503
|
+
<ul class="org-ul">
|
504
|
+
<li>Outputs are defined in a similar fashion to the inputs. The names of all the
|
505
|
+
output neurons must be unique. Here in this example we only have one output, and
|
506
|
+
we use the hyperbolic tan Neuron as the output. There is also a sigmoid Neuron
|
507
|
+
that could be used as well, but the input levels would have to be conditioned
|
508
|
+
to vary from 0 to 1 instead of from -1 to one.</li>
|
509
|
+
</ul>
|
510
|
+
|
511
|
+
<div class="org-src-container">
|
512
|
+
|
513
|
+
<pre class="src src-ruby">outputs <span style="color: #BFEBBF;">out</span>: <span style="color: #268bd2;">TanhNeuron</span>
|
514
|
+
</pre>
|
515
|
+
</div>
|
516
|
+
|
517
|
+
<ul class="org-ul">
|
518
|
+
<li>Hidden neuron specification is optional.
|
519
|
+
The names given here are largely meaningless, but but follow the same rules
|
520
|
+
for uniqueness. The neurons specified will be selected randomly as the topologies
|
521
|
+
are augmented.</li>
|
522
|
+
</ul>
|
523
|
+
|
524
|
+
<div class="org-src-container">
|
525
|
+
|
526
|
+
<pre class="src src-ruby">hidden <span style="color: #BFEBBF;">tan</span>: <span style="color: #268bd2;">TanhNeuron</span>
|
527
|
+
</pre>
|
528
|
+
</div>
|
529
|
+
</div>
|
530
|
+
|
531
|
+
<ol class="org-ol"><li><a id="orgheadline25"></a>Settings<br /><div class="outline-text-5" id="text-1-6-1-1">
|
532
|
+
<p>
|
533
|
+
For RubyNEAT. Extensive documentation will be provided on a later date
|
534
|
+
as to the meanings, which closely follow the parameters for Ken Stanley's NEAT
|
535
|
+
implementation.
|
536
|
+
</p>
|
537
|
+
</div>
|
538
|
+
|
539
|
+
<ol class="org-ol"><li><a id="orgheadline16"></a>General<br /><div class="outline-text-7" id="text-1-6-1-1-0-1">
|
540
|
+
<div class="org-src-container">
|
541
|
+
|
542
|
+
<pre class="src src-ruby">hash_on_fitness <span style="color: #cb4b16;">false</span>
|
543
|
+
start_population_size 30
|
544
|
+
population_size 30
|
545
|
+
max_generations 10000
|
546
|
+
max_population_history 10
|
547
|
+
</pre>
|
548
|
+
</div>
|
549
|
+
</div></li>
|
550
|
+
|
551
|
+
<li><a id="orgheadline17"></a>Evolver probabilities and SDs<br /><div class="outline-text-7" id="text-1-6-1-1-0-2">
|
552
|
+
<p>
|
553
|
+
Perturbations
|
554
|
+
</p>
|
555
|
+
<div class="org-src-container">
|
556
|
+
|
557
|
+
<pre class="src src-ruby">mutate_perturb_gene_weights_prob 0.10
|
558
|
+
mutate_perturb_gene_weights_sd 0.25
|
559
|
+
</pre>
|
560
|
+
</div>
|
561
|
+
</div></li>
|
562
|
+
|
563
|
+
<li><a id="orgheadline18"></a>Complete Change of weight<br /><div class="outline-text-7" id="text-1-6-1-1-0-3">
|
564
|
+
<div class="org-src-container">
|
565
|
+
|
566
|
+
<pre class="src src-ruby">mutate_change_gene_weights_prob 0.10
|
567
|
+
mutate_change_gene_weights_sd 1.00
|
568
|
+
</pre>
|
569
|
+
</div>
|
570
|
+
</div></li>
|
571
|
+
|
572
|
+
<li><a id="orgheadline19"></a>Adding new neurons and genes<br /><div class="outline-text-7" id="text-1-6-1-1-0-4">
|
573
|
+
<div class="org-src-container">
|
574
|
+
|
575
|
+
<pre class="src src-ruby">mutate_add_neuron_prob 0.05
|
576
|
+
mutate_add_gene_prob 0.20
|
577
|
+
</pre>
|
578
|
+
</div>
|
579
|
+
</div></li>
|
580
|
+
|
581
|
+
<li><a id="orgheadline20"></a>Switching genes on and off<br /><div class="outline-text-7" id="text-1-6-1-1-0-5">
|
582
|
+
<div class="org-src-container">
|
583
|
+
|
584
|
+
<pre class="src src-ruby">mutate_gene_disable_prob 0.01
|
585
|
+
mutate_gene_reenable_prob 0.01
|
586
|
+
|
587
|
+
interspecies_mate_rate 0.03
|
588
|
+
mate_only_prob 0.10 *0.7
|
589
|
+
</pre>
|
590
|
+
</div>
|
591
|
+
</div></li>
|
592
|
+
|
593
|
+
<li><a id="orgheadline21"></a>Mating<br /><div class="outline-text-7" id="text-1-6-1-1-0-6">
|
594
|
+
<div class="org-src-container">
|
595
|
+
|
596
|
+
<pre class="src src-ruby">survival_threshold 0.20 <span style="color: #7E7D7E;"># </span><span style="color: #7E7D7E;">top % allowed to mate in a species.</span>
|
597
|
+
survival_mininum_per_species 4 <span style="color: #7E7D7E;"># </span><span style="color: #7E7D7E;">for small populations, we need SOMETHING to go on.</span>
|
598
|
+
</pre>
|
599
|
+
</div>
|
600
|
+
</div></li>
|
601
|
+
|
602
|
+
<li><a id="orgheadline22"></a>Fitness costs<br /><div class="outline-text-7" id="text-1-6-1-1-0-7">
|
603
|
+
<div class="org-src-container">
|
604
|
+
|
605
|
+
<pre class="src src-ruby">fitness_cost_per_neuron 0.00001
|
606
|
+
fitness_cost_per_gene 0.00001
|
607
|
+
</pre>
|
608
|
+
</div>
|
609
|
+
</div></li>
|
610
|
+
|
611
|
+
<li><a id="orgheadline23"></a>Speciation<br /><div class="outline-text-7" id="text-1-6-1-1-0-8">
|
612
|
+
<div class="org-src-container">
|
613
|
+
|
614
|
+
<pre class="src src-ruby">compatibility_threshold 2.5
|
615
|
+
disjoint_coefficient 0.6
|
616
|
+
excess_coefficient 0.6
|
617
|
+
weight_coefficient 0.2
|
618
|
+
max_species 20
|
619
|
+
dropoff_age 15
|
620
|
+
smallest_species 5
|
621
|
+
</pre>
|
622
|
+
</div>
|
623
|
+
</div></li>
|
624
|
+
|
625
|
+
<li><a id="orgheadline24"></a>Sequencing<br /><div class="outline-text-7" id="text-1-6-1-1-0-9">
|
626
|
+
<p>
|
627
|
+
The evaluation function is called repeatedly, and each iteration is given a
|
628
|
+
monotonically increasing integer which represents the sequence number. The results
|
629
|
+
of each run is returned, and those results are evaluated elsewhere in the Neater.
|
630
|
+
</p>
|
631
|
+
|
632
|
+
<div class="org-src-container">
|
633
|
+
|
634
|
+
<pre class="src src-ruby">start_sequence_at 0
|
635
|
+
end_sequence_at 2 ** <span style="color: #268bd2;">XOR_INPUTS</span> - 1
|
636
|
+
</pre>
|
637
|
+
</div>
|
638
|
+
</div></li></ol></li>
|
639
|
+
|
640
|
+
<li><a id="orgheadline31"></a>The Evolution Block<br /><div class="outline-text-5" id="text-1-6-1-2">
|
641
|
+
<div class="org-src-container">
|
642
|
+
|
643
|
+
<pre class="src src-ruby">evolve <span style="color: #b58900; font-weight: bold;">do</span>
|
644
|
+
</pre>
|
645
|
+
</div>
|
646
|
+
</div>
|
647
|
+
|
648
|
+
<ol class="org-ol"><li><a id="orgheadline26"></a>The Query Block<br /><div class="outline-text-7" id="text-1-6-1-2-0-1">
|
649
|
+
<p>
|
650
|
+
This query shall return a vector result that will serve
|
651
|
+
as the inputs to the critter.
|
652
|
+
</p>
|
653
|
+
|
654
|
+
<div class="org-src-container">
|
655
|
+
|
656
|
+
<pre class="src src-ruby">query { |seq|
|
657
|
+
* <span style="color: #268bd2;">We</span><span style="color: #d01A4E;">'ll use the seq to create the xor sequences via</span>
|
658
|
+
<span style="color: #d01A4E;"> * the least signficant bits.</span>
|
659
|
+
<span style="color: #d01A4E;"> condition_boolean_vector (0 ... XOR_INPUTS).map{|i| (seq & (1 << i)) != 0}</span>
|
660
|
+
<span style="color: #d01A4E;">}</span>
|
661
|
+
</pre>
|
662
|
+
</div>
|
663
|
+
</div></li>
|
664
|
+
|
665
|
+
<li><a id="orgheadline27"></a>The Compare Block<br /><div class="outline-text-7" id="text-1-6-1-2-0-2">
|
666
|
+
<p>
|
667
|
+
Compare the fitness of two critters. We may choose a different ordering here.
|
668
|
+
</p>
|
669
|
+
|
670
|
+
<div class="org-src-container">
|
671
|
+
|
672
|
+
<pre class="src src-ruby">compare {|f1, f2| f2 <=> f1 }
|
673
|
+
</pre>
|
674
|
+
</div>
|
675
|
+
</div></li>
|
676
|
+
|
677
|
+
<li><a id="orgheadline28"></a>The Cost of Fitness Block<br /><div class="outline-text-7" id="text-1-6-1-2-0-3">
|
678
|
+
<p>
|
679
|
+
Here we integrate the cost with the fitness.
|
680
|
+
</p>
|
681
|
+
|
682
|
+
<div class="org-src-container">
|
683
|
+
|
684
|
+
<pre class="src src-ruby">cost { |fitvec, cost|
|
685
|
+
fit = <span style="color: #268bd2;">XOR_STATES</span> - fitvec.reduce {|a,r| a+r} - cost
|
686
|
+
<span style="color: #cb4b16;">$log</span>.debug <span style="color: #d01A4E;">">>>>>>> fitvec *{fitvec} => *{fit}, cost *{cost}"</span>
|
687
|
+
fit
|
688
|
+
}
|
689
|
+
</pre>
|
690
|
+
</div>
|
691
|
+
</div></li>
|
692
|
+
|
693
|
+
<li><a id="orgheadline29"></a>The Fitness Block<br /><div class="outline-text-7" id="text-1-6-1-2-0-4">
|
694
|
+
<p>
|
695
|
+
The fitness block is called for each activation and is given the input vector,
|
696
|
+
the output vector, and the sequence number given to the query. The results are
|
697
|
+
evaluated and a fitness scalar is returned.
|
698
|
+
</p>
|
699
|
+
|
700
|
+
<p>
|
701
|
+
#+BEGIN<sub>SRC</sub> ruby
|
702
|
+
fitness { |vin, vout, seq|
|
703
|
+
unless vout <b>*</b> :error
|
704
|
+
bin = uncondition<sub>boolean</sub><sub>vector</sub> vin
|
705
|
+
bout = uncondition<sub>boolean</sub><sub>vector</sub> vout
|
706
|
+
bactual = [xor(*vin)]
|
707
|
+
vactual = condition<sub>boolean</sub><sub>vector</sub> bactual
|
708
|
+
fit = (bout <b>*</b> bactual) ? 0.00 : 1.00
|
709
|
+
<b>simple<sub>fitness</sub><sub>error</sub>(vout, vactual.map{|f| f * 0.50 })
|
710
|
+
bfit = (bout **</b> bactual) ? 'T' : 'F'
|
711
|
+
fit
|
712
|
+
else
|
713
|
+
$log.debug "Error on *{vin} [*{seq}]"
|
714
|
+
1.0
|
715
|
+
end
|
716
|
+
}
|
717
|
+
#+ END<sub>SRC</sub>
|
718
|
+
</p>
|
719
|
+
</div></li>
|
720
|
+
|
721
|
+
<li><a id="orgheadline30"></a>The Termination Condition<br /><div class="outline-text-7" id="text-1-6-1-2-0-5">
|
722
|
+
<p>
|
723
|
+
When the desired fitness level is reached, you may want to end the
|
724
|
+
Neater run. If so, provide a block to do just that.
|
725
|
+
</p>
|
726
|
+
|
727
|
+
<div class="org-src-container">
|
728
|
+
|
729
|
+
<pre class="src src-ruby"> stop_on_fitness { |fitness, c|
|
730
|
+
puts <span style="color: #d01A4E;">"*** Generation Run *{c.generation_num}, best is *{fitness[:best]} ***\n\n"</span>
|
731
|
+
fitness[<span style="color: #BFEBBF;">:best</span>] >= <span style="color: #268bd2;">ALMOST_FIT</span>
|
732
|
+
}
|
733
|
+
<span style="color: #b58900; font-weight: bold;">end</span>
|
734
|
+
</pre>
|
735
|
+
</div>
|
736
|
+
</div></li></ol></li>
|
737
|
+
|
738
|
+
<li><a id="orgheadline32"></a>Report Generating Block<br /><div class="outline-text-5" id="text-1-6-1-3">
|
739
|
+
<p>
|
740
|
+
This particular report block just adds something to the log. You could easily
|
741
|
+
replace that with a visual update if you like, etc.
|
742
|
+
</p>
|
743
|
+
|
744
|
+
<div class="org-src-container">
|
745
|
+
|
746
|
+
<pre class="src src-ruby">report <span style="color: #b58900; font-weight: bold;">do</span> |rept|
|
747
|
+
<span style="color: #cb4b16;">$log</span>.info <span style="color: #d01A4E;">"REPORT *{rept.to_yaml}"</span>
|
748
|
+
<span style="color: #b58900; font-weight: bold;">end</span>
|
749
|
+
</pre>
|
750
|
+
</div>
|
751
|
+
</div></li>
|
752
|
+
|
753
|
+
<li><a id="orgheadline33"></a>Engine Run Block<br /><div class="outline-text-5" id="text-1-6-1-4">
|
754
|
+
<p>
|
755
|
+
The block here is called upon the completion of each generation. The
|
756
|
+
'c' parameter is the RubyNEAT Controller, the same as given to the stop<sub>on</sub><sub>fitness</sub>
|
757
|
+
block.
|
758
|
+
</p>
|
759
|
+
|
760
|
+
<div class="org-src-container">
|
761
|
+
|
762
|
+
<pre class="src src-ruby">run_engine <span style="color: #b58900; font-weight: bold;">do</span> |c|
|
763
|
+
<span style="color: #cb4b16;">$log</span>.info <span style="color: #d01A4E;">"******** Run of generation %s completed, history count %d ********"</span> %
|
764
|
+
[c.generation_num, c.population_history.size]
|
765
|
+
<span style="color: #b58900; font-weight: bold;">end</span>
|
766
|
+
</pre>
|
767
|
+
</div>
|
768
|
+
</div></li></ol>
|
769
|
+
</div>
|
770
|
+
|
771
|
+
<div id="outline-container-orgheadline40" class="outline-4">
|
772
|
+
<h4 id="orgheadline40"><span class="section-number-4">1.6.2</span> Releases</h4>
|
773
|
+
<div class="outline-text-4" id="text-1-6-2">
|
774
|
+
</div><ol class="org-ol"><li><a id="orgheadline35"></a>v0.4.0.alpha.4<br /><div class="outline-text-5" id="text-1-6-2-1">
|
775
|
+
<ul class="org-ul">
|
776
|
+
<li>First crude cut of a dashboard rubyneat<sub>dashboard</sub></li>
|
777
|
+
</ul>
|
778
|
+
</div></li>
|
779
|
+
|
780
|
+
<li><a id="orgheadline36"></a>0.3.5.alpha.6<br /><div class="outline-text-5" id="text-1-6-2-2">
|
781
|
+
<ul class="org-ul">
|
782
|
+
<li>Command line workflow is a bit cleaner</li>
|
783
|
+
<li>Removed neater examples completely and place them in
|
784
|
+
<a href="https://github.com/flajann2/rubyneat_examples">https://github.com/flajann2/rubyneat_examples</a></li>
|
785
|
+
<li>Cleaned up the internal docs a bit</li>
|
786
|
+
<li>Uniquely Generated Named Objects (UGNOs) cleaned up to be respectable</li>
|
787
|
+
</ul>
|
788
|
+
</div></li>
|
789
|
+
|
790
|
+
<li><a id="orgheadline37"></a>2015-06-08<br /><div class="outline-text-5" id="text-1-6-2-3">
|
791
|
+
<ul class="org-ul">
|
792
|
+
<li>Working on the Iterated ES HyperNEAT still,
|
793
|
+
after being side-tracked by having to make a living.
|
794
|
+
Also creating a maze environment for the critters to
|
795
|
+
operate as bots in order to test the new ES HyperNEAT extension.</li>
|
796
|
+
<li>rnDSL, as a result of TWEANN Compositions, is undergoing
|
797
|
+
radical changes. All example Neaters will be
|
798
|
+
eventually update to reflect the new syntax.</li>
|
799
|
+
</ul>
|
800
|
+
</div></li>
|
801
|
+
|
802
|
+
<li><a id="orgheadline38"></a>2014-09-25<br /><div class="outline-text-5" id="text-1-6-2-4">
|
803
|
+
<p>
|
804
|
+
Hot on the efforts on adding two major features to RubyNEAT:
|
805
|
+
</p>
|
806
|
+
|
807
|
+
<ul class="org-ul">
|
808
|
+
<li>TWEANN Compositions – you will be able to define composites of TWEANNs on
|
809
|
+
a per critter basis. This should mirror how, say, biological brains composite
|
810
|
+
themselves into regions of speciality. You may specify different selections
|
811
|
+
of neurons for each TWEANN. This is totally experiential, so we'll
|
812
|
+
see if this results in better convergence for some problems.</li>
|
813
|
+
|
814
|
+
<li>iterated ES HyperNEAT – one of the compsitions
|
815
|
+
above can be specified as a Hyper TWEANN, and just
|
816
|
+
represent one of the many compositions you may have.</li>
|
817
|
+
|
818
|
+
<li>The syntax of the Neater DSL will change quite a bit to
|
819
|
+
reflect the new features, and all of the examples will
|
820
|
+
be rewritten to show this.</li>
|
821
|
+
</ul>
|
822
|
+
|
823
|
+
<p>
|
824
|
+
Do not confuse the ANN compositions here with CPPNs,
|
825
|
+
which are completely different. By default, all TWEANNs
|
826
|
+
in HyperNEAT are potential CPPNs anyway, as
|
827
|
+
you can specify more than one neuron type.
|
828
|
+
</p>
|
829
|
+
</div></li>
|
830
|
+
|
831
|
+
<li><a id="orgheadline39"></a>2014-08-03<br /><div class="outline-text-5" id="text-1-6-2-5">
|
832
|
+
<p>
|
833
|
+
Just released a very crude alpha cut of a
|
834
|
+
dashboard for RubyNEAT. You will have to
|
835
|
+
install it manually, along with rubyneat.
|
836
|
+
The gem is rubyneat<sub>dashboard</sub>.
|
837
|
+
</p>
|
838
|
+
|
839
|
+
<ul class="org-ul">
|
840
|
+
<li>I am currently working on a Dashboard for RubyNEAT.
|
841
|
+
It will be a gemmable plugin that will allow you to
|
842
|
+
use the browser as the dashboard. It will have realtime
|
843
|
+
updates and the like, allowing you to monitor the progress
|
844
|
+
of your Neaters, and to view and possibly set parameters,
|
845
|
+
and to see what your Critters look like.</li>
|
846
|
+
</ul>
|
847
|
+
</div></li></ol>
|
848
|
+
</div>
|
849
|
+
</div>
|
850
|
+
</div>
|
851
|
+
</div>
|
852
|
+
<div id="postamble" class="status">
|
853
|
+
<p class="author">Author: Lord Alveric</p>
|
854
|
+
<p class="date">Created: 2016-03-26 Sat 01:43</p>
|
855
|
+
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
|
856
|
+
</div>
|
857
|
+
</body>
|
858
|
+
</html>
|