rubyneat 0.3.5.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.directory +4 -0
- data/.gitignore.orig +20 -0
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/dictionaries/trader.xml +3 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +5 -0
- data/.idea/modules.xml +9 -0
- data/.idea/rubyneat.iml +197 -0
- data/.idea/runConfigurations/invpend_neat.xml +26 -0
- data/.idea/runConfigurations/sigdebug_neat.xml +24 -0
- data/.idea/runConfigurations/xor_neat.xml +26 -0
- data/.idea/runConfigurations/xordebug_neat.xml +24 -0
- data/.idea/runConfigurations/xorsin_neat.xml +24 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/workspace.xml +1124 -0
- data/.semver +5 -0
- data/.yardoc/checksums +11 -0
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/Gemfile +32 -0
- data/Gemfile.lock +135 -0
- data/Gemfile.lock.orig +147 -0
- data/Guardfile +8 -0
- data/Rakefile +61 -0
- data/bin/neat +83 -0
- data/config/application.rb +5 -0
- data/doc/ControllerPoint.html +125 -0
- data/doc/CuteA.html +286 -0
- data/doc/CuteB.html +297 -0
- data/doc/DSL.html +883 -0
- data/doc/NEAT/BasicNeuronTypes/BiasNeuron.html +518 -0
- data/doc/NEAT/BasicNeuronTypes/CosineNeuron.html +274 -0
- data/doc/NEAT/BasicNeuronTypes/InputNeuron.html +366 -0
- data/doc/NEAT/BasicNeuronTypes/SigmoidNeuron.html +275 -0
- data/doc/NEAT/BasicNeuronTypes/SineNeuron.html +274 -0
- data/doc/NEAT/BasicNeuronTypes/TanhNeuron.html +274 -0
- data/doc/NEAT/BasicNeuronTypes.html +136 -0
- data/doc/NEAT/Controller/NeatSettings.html +3985 -0
- data/doc/NEAT/Controller.html +2490 -0
- data/doc/NEAT/Critter/Genotype/Gene.html +979 -0
- data/doc/NEAT/Critter/Genotype.html +1601 -0
- data/doc/NEAT/Critter/Phenotype.html +603 -0
- data/doc/NEAT/Critter.html +1037 -0
- data/doc/NEAT/DSL.html +1255 -0
- data/doc/NEAT/Evaluator.html +420 -0
- data/doc/NEAT/Evolver/CritterOp.html +551 -0
- data/doc/NEAT/Evolver.html +602 -0
- data/doc/NEAT/Expressor.html +327 -0
- data/doc/NEAT/Graph/DependencyResolver.html +478 -0
- data/doc/NEAT/Graph/GraphException.html +123 -0
- data/doc/NEAT/Graph.html +402 -0
- data/doc/NEAT/NeatException.html +123 -0
- data/doc/NEAT/NeatOb.html +567 -0
- data/doc/NEAT/Neuron.html +1067 -0
- data/doc/NEAT/Operator.html +162 -0
- data/doc/NEAT/Population.html +1961 -0
- data/doc/NEAT/Trait.html +169 -0
- data/doc/NEAT.html +588 -0
- data/doc/_index.html +373 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file_list.html +53 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +373 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +1415 -0
- data/doc/top-level-namespace.html +164 -0
- data/foo/foo_aquarium_example.rb +38 -0
- data/foo/foo_gosu.rb +99 -0
- data/foo/foo_rubygoo.rb +104 -0
- data/foo/foo_sdl.rb +34 -0
- data/foo/icon.png +0 -0
- data/lib/rubyneat/critter.rb +374 -0
- data/lib/rubyneat/default_neat.rb +10 -0
- data/lib/rubyneat/dsl.rb +130 -0
- data/lib/rubyneat/evaluator.rb +51 -0
- data/lib/rubyneat/evolver.rb +315 -0
- data/lib/rubyneat/expressor.rb +110 -0
- data/lib/rubyneat/graph.rb +95 -0
- data/lib/rubyneat/neuron.rb +152 -0
- data/lib/rubyneat/population.rb +227 -0
- data/lib/rubyneat/rubyneat.rb +429 -0
- data/lib/rubyneat.rb +8 -0
- data/neater/invpend_neat.rb +150 -0
- data/neater/rnlib/inverted_pendulum.rb +380 -0
- data/neater/rnlib/xor.rb +10 -0
- data/neater/sigdebug_neat.rb +136 -0
- data/neater/xor_neat.rb +137 -0
- data/neater/xoranalog_neat.rb +138 -0
- data/neater/xorsin_neat.rb +143 -0
- data/projectFilesBackup/.idea/rubyneat.iml +180 -0
- data/public/.directory +4 -0
- data/public/background.png +0 -0
- data/public/background.xcf +0 -0
- data/public/cart.png +0 -0
- data/public/cart.xcf +0 -0
- data/public/metalpoles_molton_ball_l.jpg +0 -0
- data/public/old_background.png +0 -0
- data/public/pointer.png +0 -0
- data/public/pointer.xcf +0 -0
- data/public/pole.kra +0 -0
- data/public/pole.png +0 -0
- data/public/pole.xcf +0 -0
- data/public/wheel-of-year-stone-DD-131-WOYS.jpg +0 -0
- data/public/wheel.png +0 -0
- data/public/wheel.xcf +0 -0
- data/public/wood-planks-texture.jpg +0 -0
- data/rdoc/ControllerPoint.html +116 -0
- data/rdoc/CuteA.html +177 -0
- data/rdoc/CuteB.html +178 -0
- data/rdoc/DSLSetup.html +177 -0
- data/rdoc/GameTestWindow.html +242 -0
- data/rdoc/GameWindow.html +292 -0
- data/rdoc/Gemfile.html +215 -0
- data/rdoc/Gemfile_lock.html +327 -0
- data/rdoc/GraphTest.html +210 -0
- data/rdoc/Guardfile.html +198 -0
- data/rdoc/InvertedPendulum/Cart.html +668 -0
- data/rdoc/InvertedPendulum/DSL.html +259 -0
- data/rdoc/InvertedPendulum/InvPendWindow.html +402 -0
- data/rdoc/InvertedPendulum.html +198 -0
- data/rdoc/Logger.html +98 -0
- data/rdoc/NEAT/BasicNeuronTypes/BiasNeuron.html +265 -0
- data/rdoc/NEAT/BasicNeuronTypes/CosineNeuron.html +162 -0
- data/rdoc/NEAT/BasicNeuronTypes/InputNeuron.html +206 -0
- data/rdoc/NEAT/BasicNeuronTypes/SigmoidNeuron.html +162 -0
- data/rdoc/NEAT/BasicNeuronTypes/SineNeuron.html +162 -0
- data/rdoc/NEAT/BasicNeuronTypes/TanhNeuron.html +161 -0
- data/rdoc/NEAT/BasicNeuronTypes.html +107 -0
- data/rdoc/NEAT/Controller/NeatSettings.html +880 -0
- data/rdoc/NEAT/Controller.html +729 -0
- data/rdoc/NEAT/Critter/Genotype/Gene.html +457 -0
- data/rdoc/NEAT/Critter/Genotype.html +735 -0
- data/rdoc/NEAT/Critter/Phenotype.html +330 -0
- data/rdoc/NEAT/Critter.html +489 -0
- data/rdoc/NEAT/DSL.html +729 -0
- data/rdoc/NEAT/Evaluator.html +256 -0
- data/rdoc/NEAT/Evolver/CritterOp.html +349 -0
- data/rdoc/NEAT/Evolver.html +891 -0
- data/rdoc/NEAT/Expressor.html +402 -0
- data/rdoc/NEAT/Graph/DependencyResolver.html +291 -0
- data/rdoc/NEAT/Graph/GraphException.html +105 -0
- data/rdoc/NEAT/Graph.html +263 -0
- data/rdoc/NEAT/NeatException.html +105 -0
- data/rdoc/NEAT/NeatOb.html +325 -0
- data/rdoc/NEAT/Neuron.html +481 -0
- data/rdoc/NEAT/Operator.html +109 -0
- data/rdoc/NEAT/Population.html +935 -0
- data/rdoc/NEAT/Trait.html +117 -0
- data/rdoc/NEAT.html +422 -0
- data/rdoc/Object.html +384 -0
- data/rdoc/Phi.html +98 -0
- data/rdoc/Player.html +383 -0
- data/rdoc/Rakefile.html +254 -0
- data/rdoc/RubyNEAT/Application.html +105 -0
- data/rdoc/RubyNEAT.html +98 -0
- data/rdoc/SDL/Event2.html +98 -0
- data/rdoc/SDL.html +98 -0
- data/rdoc/Vector.html +195 -0
- data/rdoc/created.rid +125 -0
- data/rdoc/doc/ControllerPoint_html.html +299 -0
- data/rdoc/doc/CuteA_html.html +438 -0
- data/rdoc/doc/CuteB_html.html +436 -0
- data/rdoc/doc/DSL_html.html +992 -0
- data/rdoc/doc/NEAT/BasicNeuronTypes/BiasNeuron_html.html +617 -0
- data/rdoc/doc/NEAT/BasicNeuronTypes/CosineNeuron_html.html +413 -0
- data/rdoc/doc/NEAT/BasicNeuronTypes/InputNeuron_html.html +498 -0
- data/rdoc/doc/NEAT/BasicNeuronTypes/SigmoidNeuron_html.html +413 -0
- data/rdoc/doc/NEAT/BasicNeuronTypes/SineNeuron_html.html +413 -0
- data/rdoc/doc/NEAT/BasicNeuronTypes/TanhNeuron_html.html +412 -0
- data/rdoc/doc/NEAT/BasicNeuronTypes_html.html +310 -0
- data/rdoc/doc/NEAT/Controller/NeatSettings_html.html +3324 -0
- data/rdoc/doc/NEAT/Controller_html.html +2212 -0
- data/rdoc/doc/NEAT/Critter/Genotype/Gene_html.html +997 -0
- data/rdoc/doc/NEAT/Critter/Genotype_html.html +1556 -0
- data/rdoc/doc/NEAT/Critter/Phenotype_html.html +687 -0
- data/rdoc/doc/NEAT/Critter_html.html +1037 -0
- data/rdoc/doc/NEAT/DSL_html.html +1349 -0
- data/rdoc/doc/NEAT/Evaluator_html.html +556 -0
- data/rdoc/doc/NEAT/Evolver/CritterOp_html.html +690 -0
- data/rdoc/doc/NEAT/Evolver_html.html +677 -0
- data/rdoc/doc/NEAT/Expressor_html.html +468 -0
- data/rdoc/doc/NEAT/Graph/DependencyResolver_html.html +598 -0
- data/rdoc/doc/NEAT/Graph/GraphException_html.html +299 -0
- data/rdoc/doc/NEAT/Graph_html.html +527 -0
- data/rdoc/doc/NEAT/NeatException_html.html +299 -0
- data/rdoc/doc/NEAT/NeatOb_html.html +671 -0
- data/rdoc/doc/NEAT/Neuron_html.html +1095 -0
- data/rdoc/doc/NEAT/Operator_html.html +337 -0
- data/rdoc/doc/NEAT/Population_html.html +1795 -0
- data/rdoc/doc/NEAT/Trait_html.html +344 -0
- data/rdoc/doc/NEAT_html.html +736 -0
- data/rdoc/doc/_index_html.html +559 -0
- data/rdoc/doc/class_list_html.html +369 -0
- data/rdoc/doc/css/common_css.html +188 -0
- data/rdoc/doc/css/full_list_css.html +243 -0
- data/rdoc/doc/css/style_css.html +530 -0
- data/rdoc/doc/file_list_html.html +240 -0
- data/rdoc/doc/frames_html.html +217 -0
- data/rdoc/doc/index_html.html +559 -0
- data/rdoc/doc/js/app_js.html +423 -0
- data/rdoc/doc/js/full_list_js.html +372 -0
- data/rdoc/doc/js/jquery_js.html +1536 -0
- data/rdoc/doc/method_list_html.html +1375 -0
- data/rdoc/doc/top-level-namespace_html.html +317 -0
- data/rdoc/fonts/Lato-Light.ttf +0 -0
- data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
- data/rdoc/fonts/Lato-Regular.ttf +0 -0
- data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/rdoc/fonts.css +167 -0
- data/rdoc/images/add.png +0 -0
- data/rdoc/images/arrow_up.png +0 -0
- data/rdoc/images/brick.png +0 -0
- data/rdoc/images/brick_link.png +0 -0
- data/rdoc/images/bug.png +0 -0
- data/rdoc/images/bullet_black.png +0 -0
- data/rdoc/images/bullet_toggle_minus.png +0 -0
- data/rdoc/images/bullet_toggle_plus.png +0 -0
- data/rdoc/images/date.png +0 -0
- data/rdoc/images/delete.png +0 -0
- data/rdoc/images/find.png +0 -0
- data/rdoc/images/loadingAnimation.gif +0 -0
- data/rdoc/images/macFFBgHack.png +0 -0
- data/rdoc/images/package.png +0 -0
- data/rdoc/images/page_green.png +0 -0
- data/rdoc/images/page_white_text.png +0 -0
- data/rdoc/images/page_white_width.png +0 -0
- data/rdoc/images/plugin.png +0 -0
- data/rdoc/images/ruby.png +0 -0
- data/rdoc/images/tag_blue.png +0 -0
- data/rdoc/images/tag_green.png +0 -0
- data/rdoc/images/transparent.png +0 -0
- data/rdoc/images/wrench.png +0 -0
- data/rdoc/images/wrench_orange.png +0 -0
- data/rdoc/images/zoom.png +0 -0
- data/rdoc/index.html +282 -0
- data/rdoc/js/darkfish.js +140 -0
- data/rdoc/js/jquery.js +18 -0
- data/rdoc/js/navigation.js +142 -0
- data/rdoc/js/search.js +109 -0
- data/rdoc/js/search_index.js +1 -0
- data/rdoc/js/searcher.js +228 -0
- data/rdoc/rdoc.css +580 -0
- data/rdoc/rubyneat_gemspec.html +387 -0
- data/rdoc/table_of_contents.html +2502 -0
- data/rdoc/xordebug_log.html +170598 -0
- data/rdoc/xorsin_log.html +22569 -0
- data/rubyneat.gemspec +347 -0
- data/rubyneat.gemspec.orig +375 -0
- data/spec/lib/rubyneat/rubyneat_spec.rb +132 -0
- metadata +555 -0
@@ -0,0 +1,891 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>class NEAT::Evolver - rubyneat 0.3.4</title>
|
8
|
+
|
9
|
+
<link href="../fonts.css" rel="stylesheet">
|
10
|
+
<link href="../rdoc.css" rel="stylesheet">
|
11
|
+
|
12
|
+
<script type="text/javascript">
|
13
|
+
var rdoc_rel_prefix = "../";
|
14
|
+
</script>
|
15
|
+
|
16
|
+
<script src="../js/jquery.js"></script>
|
17
|
+
<script src="../js/navigation.js"></script>
|
18
|
+
<script src="../js/search_index.js"></script>
|
19
|
+
<script src="../js/search.js"></script>
|
20
|
+
<script src="../js/searcher.js"></script>
|
21
|
+
<script src="../js/darkfish.js"></script>
|
22
|
+
|
23
|
+
|
24
|
+
<body id="top" role="document" class="class">
|
25
|
+
<nav role="navigation">
|
26
|
+
<div id="project-navigation">
|
27
|
+
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
28
|
+
<h2>
|
29
|
+
<a href="../index.html" rel="home">Home</a>
|
30
|
+
</h2>
|
31
|
+
|
32
|
+
<div id="table-of-contents-navigation">
|
33
|
+
<a href="../table_of_contents.html#pages">Pages</a>
|
34
|
+
<a href="../table_of_contents.html#classes">Classes</a>
|
35
|
+
<a href="../table_of_contents.html#methods">Methods</a>
|
36
|
+
</div>
|
37
|
+
</div>
|
38
|
+
|
39
|
+
<div id="search-section" role="search" class="project-section initially-hidden">
|
40
|
+
<form action="#" method="get" accept-charset="utf-8">
|
41
|
+
<div id="search-field-wrapper">
|
42
|
+
<input id="search-field" role="combobox" aria-label="Search"
|
43
|
+
aria-autocomplete="list" aria-controls="search-results"
|
44
|
+
type="text" name="search" placeholder="Search" spellcheck="false"
|
45
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
46
|
+
</div>
|
47
|
+
|
48
|
+
<ul id="search-results" aria-label="Search Results"
|
49
|
+
aria-busy="false" aria-expanded="false"
|
50
|
+
aria-atomic="false" class="initially-hidden"></ul>
|
51
|
+
</form>
|
52
|
+
</div>
|
53
|
+
|
54
|
+
</div>
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
<div id="class-metadata">
|
59
|
+
|
60
|
+
<div id="parent-class-section" class="nav-section">
|
61
|
+
<h3>Parent</h3>
|
62
|
+
|
63
|
+
|
64
|
+
<p class="link">Operator
|
65
|
+
|
66
|
+
</div>
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
<!-- Method Quickref -->
|
71
|
+
<div id="method-list-section" class="nav-section">
|
72
|
+
<h3>Methods</h3>
|
73
|
+
|
74
|
+
<ul class="link-list" role="directory">
|
75
|
+
|
76
|
+
<li class="calls-super" ><a href="#method-c-new">::new</a>
|
77
|
+
|
78
|
+
<li ><a href="#method-i-evolve">#evolve</a>
|
79
|
+
|
80
|
+
<li ><a href="#method-i-gen_initial_genes-21">#gen_initial_genes!</a>
|
81
|
+
|
82
|
+
<li ><a href="#method-i-mate-21">#mate!</a>
|
83
|
+
|
84
|
+
<li ><a href="#method-i-mutate-21">#mutate!</a>
|
85
|
+
|
86
|
+
<li ><a href="#method-i-mutate_add_genes-21">#mutate_add_genes!</a>
|
87
|
+
|
88
|
+
<li ><a href="#method-i-mutate_add_neurons-21">#mutate_add_neurons!</a>
|
89
|
+
|
90
|
+
<li ><a href="#method-i-mutate_change_gene_weights-21">#mutate_change_gene_weights!</a>
|
91
|
+
|
92
|
+
<li ><a href="#method-i-mutate_change_neurons-21">#mutate_change_neurons!</a>
|
93
|
+
|
94
|
+
<li ><a href="#method-i-mutate_disable_genes-21">#mutate_disable_genes!</a>
|
95
|
+
|
96
|
+
<li ><a href="#method-i-mutate_perturb_gene_weights-21">#mutate_perturb_gene_weights!</a>
|
97
|
+
|
98
|
+
<li ><a href="#method-i-mutate_reenable_genes-21">#mutate_reenable_genes!</a>
|
99
|
+
|
100
|
+
<li ><a href="#method-i-prepare_fitness-21">#prepare_fitness!</a>
|
101
|
+
|
102
|
+
<li ><a href="#method-i-prepare_novelty-21">#prepare_novelty!</a>
|
103
|
+
|
104
|
+
<li ><a href="#method-i-prepare_speciation-21">#prepare_speciation!</a>
|
105
|
+
|
106
|
+
<li ><a href="#method-i-sex">#sex</a>
|
107
|
+
|
108
|
+
</ul>
|
109
|
+
</div>
|
110
|
+
|
111
|
+
</div>
|
112
|
+
</nav>
|
113
|
+
|
114
|
+
<main role="main" aria-labelledby="class-NEAT::Evolver">
|
115
|
+
<h1 id="class-NEAT::Evolver" class="class">
|
116
|
+
class NEAT::Evolver
|
117
|
+
</h1>
|
118
|
+
|
119
|
+
<section class="description">
|
120
|
+
|
121
|
+
<h1 id="class-NEAT::Evolver-label-Evolver+--+Basis+of+all+evolvers."><a href="Evolver.html">Evolver</a> – Basis of all evolvers.<span><a href="#class-NEAT::Evolver-label-Evolver+--+Basis+of+all+evolvers.">¶</a> <a href="#documentation">↑</a></span></h1>
|
122
|
+
|
123
|
+
<pre>All evolvers shall derive from this basic evolver (or this one can be
|
124
|
+
used as is). Here, we'll have many different evolutionary operators
|
125
|
+
that will perform operations on the various critters in the population.</pre>
|
126
|
+
|
127
|
+
</section>
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
<section class="attribute-method-details" class="method-section">
|
141
|
+
<header>
|
142
|
+
<h3>Attributes</h3>
|
143
|
+
</header>
|
144
|
+
|
145
|
+
|
146
|
+
<div id="attribute-i-npop" class="method-detail">
|
147
|
+
<div class="method-heading attribute-method-heading">
|
148
|
+
<span class="method-name">npop</span><span
|
149
|
+
class="attribute-access-type">[R]</span>
|
150
|
+
</div>
|
151
|
+
|
152
|
+
<div class="method-description">
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
</div>
|
157
|
+
</div>
|
158
|
+
|
159
|
+
</section>
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
|
164
|
+
<header>
|
165
|
+
<h3>Public Class Methods</h3>
|
166
|
+
</header>
|
167
|
+
|
168
|
+
|
169
|
+
<div id="method-c-new" class="method-detail ">
|
170
|
+
|
171
|
+
<div class="method-heading">
|
172
|
+
<span class="method-name">new</span><span
|
173
|
+
class="method-args">(c)</span>
|
174
|
+
|
175
|
+
<span class="method-click-advice">click to toggle source</span>
|
176
|
+
|
177
|
+
</div>
|
178
|
+
|
179
|
+
|
180
|
+
<div class="method-description">
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
<div class="method-calls-super">
|
186
|
+
Calls superclass method
|
187
|
+
|
188
|
+
</div>
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
<div class="method-source-code" id="new-source">
|
193
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 13</span>
|
194
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">c</span>)
|
195
|
+
<span class="ruby-keyword">super</span>
|
196
|
+
<span class="ruby-ivar">@critter_op</span> = <span class="ruby-constant">CritterOp</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">self</span>
|
197
|
+
<span class="ruby-keyword">end</span></pre>
|
198
|
+
</div>
|
199
|
+
|
200
|
+
</div>
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
</div>
|
206
|
+
|
207
|
+
|
208
|
+
</section>
|
209
|
+
|
210
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
211
|
+
<header>
|
212
|
+
<h3>Public Instance Methods</h3>
|
213
|
+
</header>
|
214
|
+
|
215
|
+
|
216
|
+
<div id="method-i-evolve" class="method-detail ">
|
217
|
+
|
218
|
+
<div class="method-heading">
|
219
|
+
<span class="method-name">evolve</span><span
|
220
|
+
class="method-args">(population)</span>
|
221
|
+
|
222
|
+
<span class="method-click-advice">click to toggle source</span>
|
223
|
+
|
224
|
+
</div>
|
225
|
+
|
226
|
+
|
227
|
+
<div class="method-description">
|
228
|
+
|
229
|
+
<p>Here we clone the population and then evolve it on the basis of fitness and
|
230
|
+
novelty, etc.</p>
|
231
|
+
|
232
|
+
<p>Returns the newly-evolved population.</p>
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
<div class="method-source-code" id="evolve-source">
|
238
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 53</span>
|
239
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">evolve</span>(<span class="ruby-identifier">population</span>)
|
240
|
+
<span class="ruby-ivar">@npop</span> = <span class="ruby-identifier">population</span>.<span class="ruby-identifier">dclone</span>
|
241
|
+
|
242
|
+
<span class="ruby-comment"># Population sorting and evaluation for breeding, mutations, etc.</span>
|
243
|
+
<span class="ruby-identifier">prepare_speciation!</span>
|
244
|
+
<span class="ruby-identifier">prepare_fitness!</span>
|
245
|
+
<span class="ruby-identifier">prepare_novelty!</span>
|
246
|
+
|
247
|
+
<span class="ruby-identifier">mate!</span>
|
248
|
+
|
249
|
+
<span class="ruby-keyword">return</span> <span class="ruby-ivar">@npop</span>
|
250
|
+
<span class="ruby-keyword">end</span></pre>
|
251
|
+
</div>
|
252
|
+
|
253
|
+
</div>
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
</div>
|
259
|
+
|
260
|
+
|
261
|
+
<div id="method-i-gen_initial_genes-21" class="method-detail ">
|
262
|
+
|
263
|
+
<div class="method-heading">
|
264
|
+
<span class="method-name">gen_initial_genes!</span><span
|
265
|
+
class="method-args">(genotype)</span>
|
266
|
+
|
267
|
+
<span class="method-click-advice">click to toggle source</span>
|
268
|
+
|
269
|
+
</div>
|
270
|
+
|
271
|
+
|
272
|
+
<div class="method-description">
|
273
|
+
|
274
|
+
<p>Generate the initial genes for a given genotype. We key genes off their
|
275
|
+
innovation numbers.</p>
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
<div class="method-source-code" id="gen_initial_genes-21-source">
|
281
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 20</span>
|
282
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">gen_initial_genes!</span>(<span class="ruby-identifier">genotype</span>)
|
283
|
+
<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span> = {}
|
284
|
+
<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">neural_inputs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">s1</span>, <span class="ruby-identifier">input</span><span class="ruby-operator">|</span>
|
285
|
+
<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">neural_outputs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">s2</span>, <span class="ruby-identifier">output</span><span class="ruby-operator">|</span>
|
286
|
+
<span class="ruby-identifier">g</span> = <span class="ruby-constant">Critter</span><span class="ruby-operator">::</span><span class="ruby-constant">Genotype</span><span class="ruby-operator">::</span><span class="ruby-constant">Gene</span>[<span class="ruby-identifier">genotype</span>, <span class="ruby-identifier">input</span>, <span class="ruby-identifier">output</span>, <span class="ruby-constant">NEAT</span><span class="ruby-operator">::</span><span class="ruby-identifier">controller</span>.<span class="ruby-identifier">gaussian</span>]
|
287
|
+
<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span>[<span class="ruby-identifier">g</span>.<span class="ruby-identifier">innovation</span>] = <span class="ruby-identifier">g</span>
|
288
|
+
<span class="ruby-keyword">end</span>
|
289
|
+
<span class="ruby-keyword">end</span>
|
290
|
+
<span class="ruby-keyword">end</span></pre>
|
291
|
+
</div>
|
292
|
+
|
293
|
+
</div>
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
</div>
|
299
|
+
|
300
|
+
|
301
|
+
<div id="method-i-mutate-21" class="method-detail ">
|
302
|
+
|
303
|
+
<div class="method-heading">
|
304
|
+
<span class="method-name">mutate!</span><span
|
305
|
+
class="method-args">(population)</span>
|
306
|
+
|
307
|
+
<span class="method-click-advice">click to toggle source</span>
|
308
|
+
|
309
|
+
</div>
|
310
|
+
|
311
|
+
|
312
|
+
<div class="method-description">
|
313
|
+
|
314
|
+
<p>Here we mutate the population.</p>
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
<div class="method-source-code" id="mutate-21-source">
|
320
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 31</span>
|
321
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mutate!</span>(<span class="ruby-identifier">population</span>)
|
322
|
+
<span class="ruby-ivar">@npop</span> = <span class="ruby-identifier">population</span>
|
323
|
+
|
324
|
+
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mate_only_prob</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">or</span> <span class="ruby-identifier">rand</span> <span class="ruby-operator">></span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mate_only_prob</span>
|
325
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-string">"[[[ Neuron and Gene Giggling!"</span>
|
326
|
+
<span class="ruby-identifier">mutate_perturb_gene_weights!</span>
|
327
|
+
<span class="ruby-identifier">mutate_change_gene_weights!</span>
|
328
|
+
<span class="ruby-identifier">mutate_add_neurons!</span>
|
329
|
+
<span class="ruby-identifier">mutate_change_neurons!</span>
|
330
|
+
<span class="ruby-identifier">mutate_add_genes!</span>
|
331
|
+
<span class="ruby-identifier">mutate_disable_genes!</span>
|
332
|
+
<span class="ruby-identifier">mutate_reenable_genes!</span>
|
333
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-string">"]]] End Neuron and Gene Giggling!\n"</span>
|
334
|
+
<span class="ruby-keyword">else</span>
|
335
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-string">"*** Mating only!"</span>
|
336
|
+
<span class="ruby-keyword">end</span>
|
337
|
+
<span class="ruby-keyword">end</span></pre>
|
338
|
+
</div>
|
339
|
+
|
340
|
+
</div>
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
</div>
|
346
|
+
|
347
|
+
|
348
|
+
</section>
|
349
|
+
|
350
|
+
<section id="protected-instance-5Buntitled-5D-method-details" class="method-section">
|
351
|
+
<header>
|
352
|
+
<h3>Protected Instance Methods</h3>
|
353
|
+
</header>
|
354
|
+
|
355
|
+
|
356
|
+
<div id="method-i-mate-21" class="method-detail ">
|
357
|
+
|
358
|
+
<div class="method-heading">
|
359
|
+
<span class="method-name">mate!</span><span
|
360
|
+
class="method-args">()</span>
|
361
|
+
|
362
|
+
<span class="method-click-advice">click to toggle source</span>
|
363
|
+
|
364
|
+
</div>
|
365
|
+
|
366
|
+
|
367
|
+
<div class="method-description">
|
368
|
+
|
369
|
+
<p>Here we select candidates for mating. We must look at species and fitness
|
370
|
+
to make the selection for mating.</p>
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
<div class="method-source-code" id="mate-21-source">
|
376
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 167</span>
|
377
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mate!</span>
|
378
|
+
<span class="ruby-identifier">parm</span> = <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>
|
379
|
+
<span class="ruby-identifier">popsize</span> = <span class="ruby-identifier">parm</span>.<span class="ruby-identifier">population_size</span>
|
380
|
+
<span class="ruby-identifier">surv</span> = <span class="ruby-identifier">parm</span>.<span class="ruby-identifier">survival_threshold</span>
|
381
|
+
<span class="ruby-identifier">survmin</span> = <span class="ruby-identifier">parm</span>.<span class="ruby-identifier">survival_mininum_per_species</span>
|
382
|
+
<span class="ruby-identifier">mlist</span> = [] <span class="ruby-comment"># list of chosen mating pairs of critters [crit1, crit2], or [:carryover, crit]</span>
|
383
|
+
|
384
|
+
<span class="ruby-comment"># species list already sorted in descending order of fitness.</span>
|
385
|
+
<span class="ruby-comment"># We will generate the approximate number of pairs that correspond</span>
|
386
|
+
<span class="ruby-comment"># to the survivial_threshold percentage of the population,</span>
|
387
|
+
<span class="ruby-comment"># then backfill with the most fit out of the top original population.</span>
|
388
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">species</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">sp</span><span class="ruby-operator">|</span>
|
389
|
+
<span class="ruby-identifier">crem</span> = [(<span class="ruby-identifier">sp</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">surv</span>).<span class="ruby-identifier">ceil</span>, <span class="ruby-identifier">survmin</span>].<span class="ruby-identifier">max</span>
|
390
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">warn</span> <span class="ruby-node">"Minumum per species hit -- #{survmin}"</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">crem</span> <span class="ruby-operator">></span> <span class="ruby-identifier">survmin</span>
|
391
|
+
<span class="ruby-identifier">spsel</span> = <span class="ruby-identifier">sp</span>[<span class="ruby-value">0</span>, <span class="ruby-identifier">crem</span>]
|
392
|
+
<span class="ruby-identifier">spsel</span> = <span class="ruby-identifier">sp</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">spsel</span>.<span class="ruby-identifier">empty?</span>
|
393
|
+
<span class="ruby-identifier">crem</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword">do</span>
|
394
|
+
<span class="ruby-identifier">mlist</span> <span class="ruby-operator"><<</span> [<span class="ruby-identifier">spsel</span>[<span class="ruby-identifier">rand</span> <span class="ruby-identifier">spsel</span>.<span class="ruby-identifier">size</span>], <span class="ruby-identifier">spsel</span>[<span class="ruby-identifier">rand</span> <span class="ruby-identifier">spsel</span>.<span class="ruby-identifier">size</span>]]
|
395
|
+
<span class="ruby-keyword">end</span>
|
396
|
+
<span class="ruby-keyword">end</span>
|
397
|
+
|
398
|
+
<span class="ruby-comment"># And now for the backfilling</span>
|
399
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-identifier">mlist</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">>=</span> <span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span>.<span class="ruby-identifier">size</span>
|
400
|
+
<span class="ruby-identifier">mlist</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span>[<span class="ruby-value">0</span>, <span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">mlist</span>.<span class="ruby-identifier">size</span>].<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">crit</span><span class="ruby-operator">|</span> [<span class="ruby-value">:carryover</span>, <span class="ruby-identifier">crit</span>]}
|
401
|
+
<span class="ruby-keyword">end</span>
|
402
|
+
|
403
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span> = <span class="ruby-identifier">mlist</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">crit1</span>, <span class="ruby-identifier">crit2</span><span class="ruby-operator">|</span>
|
404
|
+
(<span class="ruby-identifier">crit1</span> <span class="ruby-operator">==</span> <span class="ruby-value">:carryover</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">crit2</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">sex</span>(<span class="ruby-identifier">crit1</span>, <span class="ruby-identifier">crit2</span>)
|
405
|
+
<span class="ruby-keyword">end</span>
|
406
|
+
<span class="ruby-keyword">end</span></pre>
|
407
|
+
</div>
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
</div>
|
415
|
+
|
416
|
+
|
417
|
+
<div id="method-i-mutate_add_genes-21" class="method-detail ">
|
418
|
+
|
419
|
+
<div class="method-heading">
|
420
|
+
<span class="method-name">mutate_add_genes!</span><span
|
421
|
+
class="method-args">()</span>
|
422
|
+
|
423
|
+
<span class="method-click-advice">click to toggle source</span>
|
424
|
+
|
425
|
+
</div>
|
426
|
+
|
427
|
+
|
428
|
+
<div class="method-description">
|
429
|
+
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
<div class="method-source-code" id="mutate_add_genes-21-source">
|
436
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 124</span>
|
437
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mutate_add_genes!</span>
|
438
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">critter</span><span class="ruby-operator">|</span>
|
439
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">rand</span> <span class="ruby-operator"><</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mutate_add_gene_prob</span>
|
440
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">"mutate_add_genes! for #{critter}"</span>
|
441
|
+
<span class="ruby-ivar">@critter_op</span>.<span class="ruby-identifier">add_gene!</span> <span class="ruby-identifier">critter</span>
|
442
|
+
<span class="ruby-keyword">end</span>
|
443
|
+
<span class="ruby-keyword">end</span>
|
444
|
+
<span class="ruby-keyword">end</span></pre>
|
445
|
+
</div>
|
446
|
+
|
447
|
+
</div>
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
</div>
|
453
|
+
|
454
|
+
|
455
|
+
<div id="method-i-mutate_add_neurons-21" class="method-detail ">
|
456
|
+
|
457
|
+
<div class="method-heading">
|
458
|
+
<span class="method-name">mutate_add_neurons!</span><span
|
459
|
+
class="method-args">()</span>
|
460
|
+
|
461
|
+
<span class="method-click-advice">click to toggle source</span>
|
462
|
+
|
463
|
+
</div>
|
464
|
+
|
465
|
+
|
466
|
+
<div class="method-description">
|
467
|
+
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
<div class="method-source-code" id="mutate_add_neurons-21-source">
|
474
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 151</span>
|
475
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mutate_add_neurons!</span>
|
476
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">critter</span><span class="ruby-operator">|</span>
|
477
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">rand</span> <span class="ruby-operator"><</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mutate_add_neuron_prob</span>
|
478
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">"mutate_add_neurons! for #{critter}"</span>
|
479
|
+
<span class="ruby-ivar">@critter_op</span>.<span class="ruby-identifier">add_neuron!</span> <span class="ruby-identifier">critter</span>
|
480
|
+
<span class="ruby-keyword">end</span>
|
481
|
+
<span class="ruby-keyword">end</span>
|
482
|
+
<span class="ruby-keyword">end</span></pre>
|
483
|
+
</div>
|
484
|
+
|
485
|
+
</div>
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
|
490
|
+
</div>
|
491
|
+
|
492
|
+
|
493
|
+
<div id="method-i-mutate_change_gene_weights-21" class="method-detail ">
|
494
|
+
|
495
|
+
<div class="method-heading">
|
496
|
+
<span class="method-name">mutate_change_gene_weights!</span><span
|
497
|
+
class="method-args">()</span>
|
498
|
+
|
499
|
+
<span class="method-click-advice">click to toggle source</span>
|
500
|
+
|
501
|
+
</div>
|
502
|
+
|
503
|
+
|
504
|
+
<div class="method-description">
|
505
|
+
|
506
|
+
<p>Totally change weights to something completely different</p>
|
507
|
+
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
<div class="method-source-code" id="mutate_change_gene_weights-21-source">
|
512
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 112</span>
|
513
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mutate_change_gene_weights!</span>
|
514
|
+
<span class="ruby-ivar">@gchange</span> = <span class="ruby-constant">Distribution</span><span class="ruby-operator">::</span><span class="ruby-constant">Normal</span><span class="ruby-operator">::</span><span class="ruby-identifier">rng</span>(<span class="ruby-value">0</span>, <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mutate_change_gene_weights_sd</span>) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@gchange</span>.<span class="ruby-identifier">nil?</span>
|
515
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">critter</span><span class="ruby-operator">|</span>
|
516
|
+
<span class="ruby-identifier">critter</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">innov</span>, <span class="ruby-identifier">gene</span><span class="ruby-operator">|</span>
|
517
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">rand</span> <span class="ruby-operator"><</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mutate_change_gene_weights_prob</span>
|
518
|
+
<span class="ruby-identifier">gene</span>.<span class="ruby-identifier">weight</span> = <span class="ruby-identifier">chg</span> = <span class="ruby-ivar">@gchange</span>.()
|
519
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> { <span class="ruby-node">"Change gene #{gene}.#{innov} by #{chg}"</span> }
|
520
|
+
<span class="ruby-keyword">end</span>
|
521
|
+
}
|
522
|
+
<span class="ruby-keyword">end</span>
|
523
|
+
<span class="ruby-keyword">end</span></pre>
|
524
|
+
</div>
|
525
|
+
|
526
|
+
</div>
|
527
|
+
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
</div>
|
532
|
+
|
533
|
+
|
534
|
+
<div id="method-i-mutate_change_neurons-21" class="method-detail ">
|
535
|
+
|
536
|
+
<div class="method-heading">
|
537
|
+
<span class="method-name">mutate_change_neurons!</span><span
|
538
|
+
class="method-args">()</span>
|
539
|
+
|
540
|
+
<span class="method-click-advice">click to toggle source</span>
|
541
|
+
|
542
|
+
</div>
|
543
|
+
|
544
|
+
|
545
|
+
<div class="method-description">
|
546
|
+
|
547
|
+
<p>TODO Finish mutate_change_neurons!</p>
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
|
552
|
+
<div class="method-source-code" id="mutate_change_neurons-21-source">
|
553
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 161</span>
|
554
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mutate_change_neurons!</span>
|
555
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">error</span> <span class="ruby-string">"mutate_change_neurons! NIY"</span>
|
556
|
+
<span class="ruby-keyword">end</span></pre>
|
557
|
+
</div>
|
558
|
+
|
559
|
+
</div>
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
|
564
|
+
</div>
|
565
|
+
|
566
|
+
|
567
|
+
<div id="method-i-mutate_disable_genes-21" class="method-detail ">
|
568
|
+
|
569
|
+
<div class="method-heading">
|
570
|
+
<span class="method-name">mutate_disable_genes!</span><span
|
571
|
+
class="method-args">()</span>
|
572
|
+
|
573
|
+
<span class="method-click-advice">click to toggle source</span>
|
574
|
+
|
575
|
+
</div>
|
576
|
+
|
577
|
+
|
578
|
+
<div class="method-description">
|
579
|
+
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
<div class="method-source-code" id="mutate_disable_genes-21-source">
|
586
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 133</span>
|
587
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mutate_disable_genes!</span>
|
588
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">critter</span><span class="ruby-operator">|</span>
|
589
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">rand</span> <span class="ruby-operator"><</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mutate_gene_disable_prob</span>
|
590
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">"mutate_disable_genes! for #{critter}"</span>
|
591
|
+
<span class="ruby-ivar">@critter_op</span>.<span class="ruby-identifier">disable_gene!</span> <span class="ruby-identifier">critter</span>
|
592
|
+
<span class="ruby-keyword">end</span>
|
593
|
+
<span class="ruby-keyword">end</span>
|
594
|
+
<span class="ruby-keyword">end</span></pre>
|
595
|
+
</div>
|
596
|
+
|
597
|
+
</div>
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
|
602
|
+
</div>
|
603
|
+
|
604
|
+
|
605
|
+
<div id="method-i-mutate_perturb_gene_weights-21" class="method-detail ">
|
606
|
+
|
607
|
+
<div class="method-heading">
|
608
|
+
<span class="method-name">mutate_perturb_gene_weights!</span><span
|
609
|
+
class="method-args">()</span>
|
610
|
+
|
611
|
+
<span class="method-click-advice">click to toggle source</span>
|
612
|
+
|
613
|
+
</div>
|
614
|
+
|
615
|
+
|
616
|
+
<div class="method-description">
|
617
|
+
|
618
|
+
<p>Perturb existing gene weights by adding a guassian to them.</p>
|
619
|
+
|
620
|
+
|
621
|
+
|
622
|
+
|
623
|
+
<div class="method-source-code" id="mutate_perturb_gene_weights-21-source">
|
624
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 99</span>
|
625
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mutate_perturb_gene_weights!</span>
|
626
|
+
<span class="ruby-ivar">@gperturb</span> = <span class="ruby-constant">Distribution</span><span class="ruby-operator">::</span><span class="ruby-constant">Normal</span><span class="ruby-operator">::</span><span class="ruby-identifier">rng</span>(<span class="ruby-value">0</span>, <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mutate_perturb_gene_weights_sd</span>) <span class="ruby-keyword">if</span> <span class="ruby-ivar">@gperturb</span>.<span class="ruby-identifier">nil?</span>
|
627
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">critter</span><span class="ruby-operator">|</span>
|
628
|
+
<span class="ruby-identifier">critter</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">innov</span>, <span class="ruby-identifier">gene</span><span class="ruby-operator">|</span>
|
629
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">rand</span> <span class="ruby-operator"><</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mutate_perturb_gene_weights_prob</span>
|
630
|
+
<span class="ruby-identifier">gene</span>.<span class="ruby-identifier">weight</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">per</span> = <span class="ruby-ivar">@gperturb</span>.()
|
631
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> { <span class="ruby-node">"Peturbed gene #{gene}.#{innov} by #{per}"</span> }
|
632
|
+
<span class="ruby-keyword">end</span>
|
633
|
+
}
|
634
|
+
<span class="ruby-keyword">end</span>
|
635
|
+
<span class="ruby-keyword">end</span></pre>
|
636
|
+
</div>
|
637
|
+
|
638
|
+
</div>
|
639
|
+
|
640
|
+
|
641
|
+
|
642
|
+
|
643
|
+
</div>
|
644
|
+
|
645
|
+
|
646
|
+
<div id="method-i-mutate_reenable_genes-21" class="method-detail ">
|
647
|
+
|
648
|
+
<div class="method-heading">
|
649
|
+
<span class="method-name">mutate_reenable_genes!</span><span
|
650
|
+
class="method-args">()</span>
|
651
|
+
|
652
|
+
<span class="method-click-advice">click to toggle source</span>
|
653
|
+
|
654
|
+
</div>
|
655
|
+
|
656
|
+
|
657
|
+
<div class="method-description">
|
658
|
+
|
659
|
+
|
660
|
+
|
661
|
+
|
662
|
+
|
663
|
+
|
664
|
+
<div class="method-source-code" id="mutate_reenable_genes-21-source">
|
665
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 142</span>
|
666
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">mutate_reenable_genes!</span>
|
667
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">critters</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">critter</span><span class="ruby-operator">|</span>
|
668
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">rand</span> <span class="ruby-operator"><</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">parms</span>.<span class="ruby-identifier">mutate_gene_reenable_prob</span>
|
669
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">"mutate_reenable_genes! for #{critter}"</span>
|
670
|
+
<span class="ruby-ivar">@critter_op</span>.<span class="ruby-identifier">reenable_gene!</span> <span class="ruby-identifier">critter</span>
|
671
|
+
<span class="ruby-keyword">end</span>
|
672
|
+
<span class="ruby-keyword">end</span>
|
673
|
+
<span class="ruby-keyword">end</span></pre>
|
674
|
+
</div>
|
675
|
+
|
676
|
+
</div>
|
677
|
+
|
678
|
+
|
679
|
+
|
680
|
+
|
681
|
+
</div>
|
682
|
+
|
683
|
+
|
684
|
+
<div id="method-i-prepare_fitness-21" class="method-detail ">
|
685
|
+
|
686
|
+
<div class="method-heading">
|
687
|
+
<span class="method-name">prepare_fitness!</span><span
|
688
|
+
class="method-args">()</span>
|
689
|
+
|
690
|
+
<span class="method-click-advice">click to toggle source</span>
|
691
|
+
|
692
|
+
</div>
|
693
|
+
|
694
|
+
|
695
|
+
<div class="method-description">
|
696
|
+
|
697
|
+
<p>Sort species within the basis of fitness. Think of the fitness as an error
|
698
|
+
/ cost function. The better fit, the closer to zero the fitness parameter
|
699
|
+
will be.</p>
|
700
|
+
|
701
|
+
<p>If a compare block is specified in the <a href="DSL.html">DSL</a>, then
|
702
|
+
that function is called with the *fitness values* from critters c1 and c2.
|
703
|
+
The default valuation is c1.fitness <=> c2.fitness. You may elect to
|
704
|
+
evaluate them differently.</p>
|
705
|
+
|
706
|
+
|
707
|
+
|
708
|
+
|
709
|
+
<div class="method-source-code" id="prepare_fitness-21-source">
|
710
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 82</span>
|
711
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">prepare_fitness!</span>
|
712
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">species</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>, <span class="ruby-identifier">sp</span><span class="ruby-operator">|</span>
|
713
|
+
<span class="ruby-identifier">sp</span>.<span class="ruby-identifier">sort!</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c1</span>, <span class="ruby-identifier">c2</span><span class="ruby-operator">|</span>
|
714
|
+
<span class="ruby-keyword">unless</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">compare_func</span>.<span class="ruby-identifier">nil?</span>
|
715
|
+
<span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">compare_func</span>.(<span class="ruby-identifier">c1</span>.<span class="ruby-identifier">fitness</span>, <span class="ruby-identifier">c2</span>.<span class="ruby-identifier">fitness</span>)
|
716
|
+
<span class="ruby-keyword">else</span>
|
717
|
+
<span class="ruby-identifier">c1</span>.<span class="ruby-identifier">fitness</span> <span class="ruby-operator"><=></span> <span class="ruby-identifier">c2</span>.<span class="ruby-identifier">fitness</span>
|
718
|
+
<span class="ruby-keyword">end</span>
|
719
|
+
}
|
720
|
+
<span class="ruby-keyword">end</span>
|
721
|
+
<span class="ruby-keyword">end</span></pre>
|
722
|
+
</div>
|
723
|
+
|
724
|
+
</div>
|
725
|
+
|
726
|
+
|
727
|
+
|
728
|
+
|
729
|
+
</div>
|
730
|
+
|
731
|
+
|
732
|
+
<div id="method-i-prepare_novelty-21" class="method-detail ">
|
733
|
+
|
734
|
+
<div class="method-heading">
|
735
|
+
<span class="method-name">prepare_novelty!</span><span
|
736
|
+
class="method-args">()</span>
|
737
|
+
|
738
|
+
<span class="method-click-advice">click to toggle source</span>
|
739
|
+
|
740
|
+
</div>
|
741
|
+
|
742
|
+
|
743
|
+
<div class="method-description">
|
744
|
+
|
745
|
+
<p>TODO: write novelty code</p>
|
746
|
+
|
747
|
+
|
748
|
+
|
749
|
+
|
750
|
+
<div class="method-source-code" id="prepare_novelty-21-source">
|
751
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 95</span>
|
752
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">prepare_novelty!</span>
|
753
|
+
<span class="ruby-keyword">end</span></pre>
|
754
|
+
</div>
|
755
|
+
|
756
|
+
</div>
|
757
|
+
|
758
|
+
|
759
|
+
|
760
|
+
|
761
|
+
</div>
|
762
|
+
|
763
|
+
|
764
|
+
<div id="method-i-prepare_speciation-21" class="method-detail ">
|
765
|
+
|
766
|
+
<div class="method-heading">
|
767
|
+
<span class="method-name">prepare_speciation!</span><span
|
768
|
+
class="method-args">()</span>
|
769
|
+
|
770
|
+
<span class="method-click-advice">click to toggle source</span>
|
771
|
+
|
772
|
+
</div>
|
773
|
+
|
774
|
+
|
775
|
+
<div class="method-description">
|
776
|
+
|
777
|
+
<p>Here we specify evolutionary operators.</p>
|
778
|
+
|
779
|
+
|
780
|
+
|
781
|
+
|
782
|
+
<div class="method-source-code" id="prepare_speciation-21-source">
|
783
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 69</span>
|
784
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">prepare_speciation!</span>
|
785
|
+
<span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">speciate!</span>
|
786
|
+
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-string">"SPECIES:"</span>
|
787
|
+
<span class="ruby-constant">NEAT</span><span class="ruby-operator">::</span><span class="ruby-identifier">dpp</span> <span class="ruby-ivar">@npop</span>.<span class="ruby-identifier">species</span>
|
788
|
+
<span class="ruby-keyword">end</span></pre>
|
789
|
+
</div>
|
790
|
+
|
791
|
+
</div>
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
|
796
|
+
</div>
|
797
|
+
|
798
|
+
|
799
|
+
<div id="method-i-sex" class="method-detail ">
|
800
|
+
|
801
|
+
<div class="method-heading">
|
802
|
+
<span class="method-name">sex</span><span
|
803
|
+
class="method-args">(crit1, crit2)</span>
|
804
|
+
|
805
|
+
<span class="method-click-advice">click to toggle source</span>
|
806
|
+
|
807
|
+
</div>
|
808
|
+
|
809
|
+
|
810
|
+
<div class="method-description">
|
811
|
+
|
812
|
+
<p>Mate the given critters and return a baby. This is rather involved, and
|
813
|
+
relies heavily on the Innovation Numbers.</p>
|
814
|
+
|
815
|
+
<p>Some definitions:</p>
|
816
|
+
|
817
|
+
<pre>Matching Gene
|
818
|
+
2 genes with matching innovation numbers.
|
819
|
+
|
820
|
+
Disjoint Gene
|
821
|
+
A gene in one has an innovation number in the range of innovation numbers
|
822
|
+
of the other.
|
823
|
+
|
824
|
+
Excess Gene
|
825
|
+
Gene in one critter that has an innovation number outside of the range
|
826
|
+
of innovation numbers of the other.
|
827
|
+
|
828
|
+
Neurons
|
829
|
+
Distinct Neurons from both crit1 and crit2 must be present in
|
830
|
+
the baby.</pre>
|
831
|
+
|
832
|
+
<p>Excess and Disjoint genes are always included from the more fit parent.
|
833
|
+
Matching genes are randomly chosen. For now, we make it 50/50.</p>
|
834
|
+
|
835
|
+
|
836
|
+
|
837
|
+
|
838
|
+
<div class="method-source-code" id="sex-source">
|
839
|
+
<pre><span class="ruby-comment"># File lib/rubyneat/evolver.rb, line 221</span>
|
840
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">sex</span>(<span class="ruby-identifier">crit1</span>, <span class="ruby-identifier">crit2</span>)
|
841
|
+
<span class="ruby-constant">Critter</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@npop</span>, <span class="ruby-keyword">true</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">baby</span><span class="ruby-operator">|</span>
|
842
|
+
<span class="ruby-identifier">fitcrit</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">crit1</span>.<span class="ruby-identifier">fitness</span> <span class="ruby-operator">></span> <span class="ruby-identifier">crit2</span>.<span class="ruby-identifier">fitness</span>
|
843
|
+
<span class="ruby-identifier">crit1</span>
|
844
|
+
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">crit2</span>.<span class="ruby-identifier">fitness</span> <span class="ruby-operator">></span> <span class="ruby-identifier">crit1</span>.<span class="ruby-identifier">fitness</span>
|
845
|
+
<span class="ruby-identifier">crit2</span>
|
846
|
+
<span class="ruby-keyword">else</span>
|
847
|
+
(<span class="ruby-identifier">rand</span>(<span class="ruby-value">2</span>) <span class="ruby-operator">==</span> <span class="ruby-value">1</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">crit1</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">crit2</span>
|
848
|
+
<span class="ruby-keyword">end</span>
|
849
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">crit1</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">to_set</span>
|
850
|
+
<span class="ruby-identifier">b</span> = <span class="ruby-identifier">crit2</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">to_set</span>
|
851
|
+
<span class="ruby-identifier">disjoint</span> = (<span class="ruby-identifier">a</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">b</span>) <span class="ruby-operator">+</span> (<span class="ruby-identifier">b</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">a</span>)
|
852
|
+
<span class="ruby-identifier">joint</span> = (<span class="ruby-identifier">a</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span>) <span class="ruby-operator">-</span> <span class="ruby-identifier">disjoint</span>
|
853
|
+
<span class="ruby-identifier">baby</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">neucleate</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">gtype</span><span class="ruby-operator">|</span>
|
854
|
+
<span class="ruby-identifier">joint</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">innov</span><span class="ruby-operator">|</span>
|
855
|
+
<span class="ruby-identifier">g1</span> = <span class="ruby-identifier">crit1</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span>[<span class="ruby-identifier">innov</span>]
|
856
|
+
<span class="ruby-identifier">g2</span> = <span class="ruby-identifier">crit2</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span>[<span class="ruby-identifier">innov</span>]
|
857
|
+
<span class="ruby-constant">Critter</span><span class="ruby-operator">::</span><span class="ruby-constant">Genotype</span><span class="ruby-operator">::</span><span class="ruby-constant">Gene</span>[<span class="ruby-identifier">gtype</span>,
|
858
|
+
<span class="ruby-identifier">g1</span>.<span class="ruby-identifier">in_neuron</span>, <span class="ruby-identifier">g1</span>.<span class="ruby-identifier">out_neuron</span>,
|
859
|
+
(<span class="ruby-identifier">rand</span>(<span class="ruby-value">2</span>) <span class="ruby-operator">==</span> <span class="ruby-value">1</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">g1</span>.<span class="ruby-identifier">weight</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">g2</span>.<span class="ruby-identifier">weight</span>,
|
860
|
+
<span class="ruby-identifier">innov</span>]
|
861
|
+
} <span class="ruby-operator">+</span> <span class="ruby-identifier">disjoint</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">innov</span><span class="ruby-operator">|</span>
|
862
|
+
<span class="ruby-identifier">fitcrit</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span>[<span class="ruby-identifier">innov</span>].<span class="ruby-identifier">clone</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">fitcrit</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">genes</span>[<span class="ruby-identifier">innov</span>].<span class="ruby-identifier">nil?</span>
|
863
|
+
}.<span class="ruby-identifier">reject</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">nil?</span> }
|
864
|
+
}
|
865
|
+
<span class="ruby-identifier">baby</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">innervate!</span> <span class="ruby-identifier">crit1</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">neurons</span>, <span class="ruby-identifier">crit2</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">neurons</span>
|
866
|
+
<span class="ruby-identifier">baby</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">prune!</span>
|
867
|
+
<span class="ruby-identifier">baby</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">wire!</span>
|
868
|
+
<span class="ruby-keyword">end</span>
|
869
|
+
<span class="ruby-keyword">end</span></pre>
|
870
|
+
</div>
|
871
|
+
|
872
|
+
</div>
|
873
|
+
|
874
|
+
|
875
|
+
|
876
|
+
|
877
|
+
</div>
|
878
|
+
|
879
|
+
|
880
|
+
</section>
|
881
|
+
|
882
|
+
</section>
|
883
|
+
</main>
|
884
|
+
|
885
|
+
|
886
|
+
<footer id="validator-badges" role="contentinfo">
|
887
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
888
|
+
<p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.1.
|
889
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
890
|
+
</footer>
|
891
|
+
|