rubyneat 0.3.5.alpha.3 → 0.3.5.alpha.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.semver +1 -1
- data/Gemfile +19 -19
- data/Gemfile.lock +39 -33
- data/README.md +66 -0
- data/Rakefile +19 -2
- data/bin/neat +4 -60
- data/lib/rubyneat/cli.rb +5 -0
- data/lib/rubyneat/cli/generate.rb +131 -0
- data/lib/rubyneat/cli/main.rb +54 -0
- data/lib/rubyneat/cli/templates/generate/Gemfile.tt +17 -0
- data/lib/rubyneat/cli/templates/generate/README.md.tt +1 -0
- data/lib/rubyneat/cli/templates/generate/bin/neat.tt +14 -0
- data/{neater/xor_neat.rb → lib/rubyneat/cli/templates/generate/neater.tt} +7 -22
- data/rubyneat.gemspec +73 -297
- data/rubyneat.gemspec.orig +384 -0
- metadata +76 -292
- data/.idea/.name +0 -1
- data/.idea/.rakeTasks +0 -7
- data/.idea/dictionaries/trader.xml +0 -3
- data/.idea/encodings.xml +0 -5
- data/.idea/misc.xml +0 -5
- data/.idea/modules.xml +0 -9
- data/.idea/rubyneat.iml +0 -198
- data/.idea/runConfigurations/invpend_neat.xml +0 -26
- data/.idea/runConfigurations/sigdebug_neat.xml +0 -24
- data/.idea/runConfigurations/xor_neat.xml +0 -26
- data/.idea/runConfigurations/xordebug_neat.xml +0 -24
- data/.idea/runConfigurations/xorsin_neat.xml +0 -24
- data/.idea/scopes/scope_settings.xml +0 -5
- data/.idea/vcs.xml +0 -7
- data/.idea/workspace.xml +0 -1151
- data/.yardoc/checksums +0 -11
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +0 -0
- data/Guardfile +0 -8
- data/doc/ControllerPoint.html +0 -125
- data/doc/CuteA.html +0 -286
- data/doc/CuteB.html +0 -297
- data/doc/DSL.html +0 -883
- data/doc/NEAT.html +0 -588
- data/doc/NEAT/BasicNeuronTypes.html +0 -136
- data/doc/NEAT/BasicNeuronTypes/BiasNeuron.html +0 -518
- data/doc/NEAT/BasicNeuronTypes/CosineNeuron.html +0 -274
- data/doc/NEAT/BasicNeuronTypes/InputNeuron.html +0 -366
- data/doc/NEAT/BasicNeuronTypes/SigmoidNeuron.html +0 -275
- data/doc/NEAT/BasicNeuronTypes/SineNeuron.html +0 -274
- data/doc/NEAT/BasicNeuronTypes/TanhNeuron.html +0 -274
- data/doc/NEAT/Controller.html +0 -2490
- data/doc/NEAT/Controller/NeatSettings.html +0 -3985
- data/doc/NEAT/Critter.html +0 -1037
- data/doc/NEAT/Critter/Genotype.html +0 -1601
- data/doc/NEAT/Critter/Genotype/Gene.html +0 -979
- data/doc/NEAT/Critter/Phenotype.html +0 -603
- data/doc/NEAT/DSL.html +0 -1255
- data/doc/NEAT/Evaluator.html +0 -420
- data/doc/NEAT/Evolver.html +0 -602
- data/doc/NEAT/Evolver/CritterOp.html +0 -551
- data/doc/NEAT/Expressor.html +0 -327
- data/doc/NEAT/Graph.html +0 -402
- data/doc/NEAT/Graph/DependencyResolver.html +0 -478
- data/doc/NEAT/Graph/GraphException.html +0 -123
- data/doc/NEAT/NeatException.html +0 -123
- data/doc/NEAT/NeatOb.html +0 -567
- data/doc/NEAT/Neuron.html +0 -1067
- data/doc/NEAT/Operator.html +0 -162
- data/doc/NEAT/Population.html +0 -1961
- data/doc/NEAT/Trait.html +0 -169
- data/doc/_index.html +0 -373
- data/doc/class_list.html +0 -54
- data/doc/css/common.css +0 -1
- data/doc/css/full_list.css +0 -57
- data/doc/css/style.css +0 -339
- data/doc/file_list.html +0 -53
- data/doc/frames.html +0 -26
- data/doc/index.html +0 -373
- data/doc/js/app.js +0 -219
- data/doc/js/full_list.js +0 -178
- data/doc/js/jquery.js +0 -4
- data/doc/method_list.html +0 -1415
- data/doc/top-level-namespace.html +0 -164
- data/foo/foo_aquarium_example.rb +0 -38
- data/foo/foo_gosu.rb +0 -99
- data/foo/foo_rubygoo.rb +0 -104
- data/foo/foo_sdl.rb +0 -34
- data/foo/icon.png +0 -0
- data/neater/invpend_neat.rb +0 -150
- data/neater/rnlib/inverted_pendulum.rb +0 -380
- data/neater/rnlib/xor.rb +0 -10
- data/neater/sigdebug_neat.rb +0 -136
- data/neater/xoranalog_neat.rb +0 -138
- data/neater/xorsin_neat.rb +0 -143
- data/projectFilesBackup/.idea/rubyneat.iml +0 -180
- data/public/.directory +0 -4
- 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 +0 -116
- data/rdoc/CuteA.html +0 -177
- data/rdoc/CuteB.html +0 -178
- data/rdoc/DSLSetup.html +0 -177
- data/rdoc/GameTestWindow.html +0 -242
- data/rdoc/GameWindow.html +0 -292
- data/rdoc/Gemfile.html +0 -215
- data/rdoc/Gemfile_lock.html +0 -327
- data/rdoc/GraphTest.html +0 -210
- data/rdoc/Guardfile.html +0 -198
- data/rdoc/InvertedPendulum.html +0 -198
- data/rdoc/InvertedPendulum/Cart.html +0 -668
- data/rdoc/InvertedPendulum/DSL.html +0 -259
- data/rdoc/InvertedPendulum/InvPendWindow.html +0 -402
- data/rdoc/Logger.html +0 -98
- data/rdoc/NEAT.html +0 -422
- data/rdoc/NEAT/BasicNeuronTypes.html +0 -107
- data/rdoc/NEAT/BasicNeuronTypes/BiasNeuron.html +0 -265
- data/rdoc/NEAT/BasicNeuronTypes/CosineNeuron.html +0 -162
- data/rdoc/NEAT/BasicNeuronTypes/InputNeuron.html +0 -206
- data/rdoc/NEAT/BasicNeuronTypes/SigmoidNeuron.html +0 -162
- data/rdoc/NEAT/BasicNeuronTypes/SineNeuron.html +0 -162
- data/rdoc/NEAT/BasicNeuronTypes/TanhNeuron.html +0 -161
- data/rdoc/NEAT/Controller.html +0 -729
- data/rdoc/NEAT/Controller/NeatSettings.html +0 -880
- data/rdoc/NEAT/Critter.html +0 -489
- data/rdoc/NEAT/Critter/Genotype.html +0 -735
- data/rdoc/NEAT/Critter/Genotype/Gene.html +0 -457
- data/rdoc/NEAT/Critter/Phenotype.html +0 -330
- data/rdoc/NEAT/DSL.html +0 -729
- data/rdoc/NEAT/Evaluator.html +0 -256
- data/rdoc/NEAT/Evolver.html +0 -891
- data/rdoc/NEAT/Evolver/CritterOp.html +0 -349
- data/rdoc/NEAT/Expressor.html +0 -402
- data/rdoc/NEAT/Graph.html +0 -263
- data/rdoc/NEAT/Graph/DependencyResolver.html +0 -291
- data/rdoc/NEAT/Graph/GraphException.html +0 -105
- data/rdoc/NEAT/NeatException.html +0 -105
- data/rdoc/NEAT/NeatOb.html +0 -325
- data/rdoc/NEAT/Neuron.html +0 -481
- data/rdoc/NEAT/Operator.html +0 -109
- data/rdoc/NEAT/Population.html +0 -935
- data/rdoc/NEAT/Trait.html +0 -117
- data/rdoc/Object.html +0 -384
- data/rdoc/Phi.html +0 -98
- data/rdoc/Player.html +0 -383
- data/rdoc/Rakefile.html +0 -254
- data/rdoc/RubyNEAT.html +0 -98
- data/rdoc/RubyNEAT/Application.html +0 -105
- data/rdoc/SDL.html +0 -98
- data/rdoc/SDL/Event2.html +0 -98
- data/rdoc/Vector.html +0 -195
- data/rdoc/created.rid +0 -125
- data/rdoc/doc/ControllerPoint_html.html +0 -299
- data/rdoc/doc/CuteA_html.html +0 -438
- data/rdoc/doc/CuteB_html.html +0 -436
- data/rdoc/doc/DSL_html.html +0 -992
- data/rdoc/doc/NEAT/BasicNeuronTypes/BiasNeuron_html.html +0 -617
- data/rdoc/doc/NEAT/BasicNeuronTypes/CosineNeuron_html.html +0 -413
- data/rdoc/doc/NEAT/BasicNeuronTypes/InputNeuron_html.html +0 -498
- data/rdoc/doc/NEAT/BasicNeuronTypes/SigmoidNeuron_html.html +0 -413
- data/rdoc/doc/NEAT/BasicNeuronTypes/SineNeuron_html.html +0 -413
- data/rdoc/doc/NEAT/BasicNeuronTypes/TanhNeuron_html.html +0 -412
- data/rdoc/doc/NEAT/BasicNeuronTypes_html.html +0 -310
- data/rdoc/doc/NEAT/Controller/NeatSettings_html.html +0 -3324
- data/rdoc/doc/NEAT/Controller_html.html +0 -2212
- data/rdoc/doc/NEAT/Critter/Genotype/Gene_html.html +0 -997
- data/rdoc/doc/NEAT/Critter/Genotype_html.html +0 -1556
- data/rdoc/doc/NEAT/Critter/Phenotype_html.html +0 -687
- data/rdoc/doc/NEAT/Critter_html.html +0 -1037
- data/rdoc/doc/NEAT/DSL_html.html +0 -1349
- data/rdoc/doc/NEAT/Evaluator_html.html +0 -556
- data/rdoc/doc/NEAT/Evolver/CritterOp_html.html +0 -690
- data/rdoc/doc/NEAT/Evolver_html.html +0 -677
- data/rdoc/doc/NEAT/Expressor_html.html +0 -468
- data/rdoc/doc/NEAT/Graph/DependencyResolver_html.html +0 -598
- data/rdoc/doc/NEAT/Graph/GraphException_html.html +0 -299
- data/rdoc/doc/NEAT/Graph_html.html +0 -527
- data/rdoc/doc/NEAT/NeatException_html.html +0 -299
- data/rdoc/doc/NEAT/NeatOb_html.html +0 -671
- data/rdoc/doc/NEAT/Neuron_html.html +0 -1095
- data/rdoc/doc/NEAT/Operator_html.html +0 -337
- data/rdoc/doc/NEAT/Population_html.html +0 -1795
- data/rdoc/doc/NEAT/Trait_html.html +0 -344
- data/rdoc/doc/NEAT_html.html +0 -736
- data/rdoc/doc/_index_html.html +0 -559
- data/rdoc/doc/class_list_html.html +0 -369
- data/rdoc/doc/css/common_css.html +0 -188
- data/rdoc/doc/css/full_list_css.html +0 -243
- data/rdoc/doc/css/style_css.html +0 -530
- data/rdoc/doc/file_list_html.html +0 -240
- data/rdoc/doc/frames_html.html +0 -217
- data/rdoc/doc/index_html.html +0 -559
- data/rdoc/doc/js/app_js.html +0 -423
- data/rdoc/doc/js/full_list_js.html +0 -372
- data/rdoc/doc/js/jquery_js.html +0 -1536
- data/rdoc/doc/method_list_html.html +0 -1375
- data/rdoc/doc/top-level-namespace_html.html +0 -317
- data/rdoc/fonts.css +0 -167
- 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/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 +0 -282
- data/rdoc/js/darkfish.js +0 -140
- data/rdoc/js/jquery.js +0 -18
- data/rdoc/js/navigation.js +0 -142
- data/rdoc/js/search.js +0 -109
- data/rdoc/js/search_index.js +0 -1
- data/rdoc/js/searcher.js +0 -228
- data/rdoc/rdoc.css +0 -580
- data/rdoc/rubyneat_gemspec.html +0 -387
- data/rdoc/table_of_contents.html +0 -2502
- data/rdoc/xordebug_log.html +0 -170598
- data/rdoc/xorsin_log.html +0 -22569
data/rdoc/NEAT/Evaluator.html
DELETED
@@ -1,256 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
|
3
|
-
<html>
|
4
|
-
<head>
|
5
|
-
<meta charset="UTF-8">
|
6
|
-
|
7
|
-
<title>class NEAT::Evaluator - 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 ><a href="#method-i-analyze_for_fitness-21">#analyze_for_fitness!</a>
|
77
|
-
|
78
|
-
<li ><a href="#method-i-evaluate-21">#evaluate!</a>
|
79
|
-
|
80
|
-
<li ><a href="#method-i-ready_for_evaluation">#ready_for_evaluation</a>
|
81
|
-
|
82
|
-
</ul>
|
83
|
-
</div>
|
84
|
-
|
85
|
-
</div>
|
86
|
-
</nav>
|
87
|
-
|
88
|
-
<main role="main" aria-labelledby="class-NEAT::Evaluator">
|
89
|
-
<h1 id="class-NEAT::Evaluator" class="class">
|
90
|
-
class NEAT::Evaluator
|
91
|
-
</h1>
|
92
|
-
|
93
|
-
<section class="description">
|
94
|
-
|
95
|
-
<h1 id="class-NEAT::Evaluator-label-Evaluator+evaluates+phenotype+of+critter+for+fitness%2C+novelty%2C+etc."><a href="Evaluator.html">Evaluator</a> evaluates phenotype of critter for fitness, novelty, etc.<span><a href="#class-NEAT::Evaluator-label-Evaluator+evaluates+phenotype+of+critter+for+fitness%2C+novelty%2C+etc.">¶</a> <a href="#documentation">↑</a></span></h1>
|
96
|
-
|
97
|
-
<pre>We can have a chain of these evaluators whose outputs are summed, etc.</pre>
|
98
|
-
|
99
|
-
</section>
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
<section id="5Buntitled-5D" class="documentation-section">
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
115
|
-
<header>
|
116
|
-
<h3>Public Instance Methods</h3>
|
117
|
-
</header>
|
118
|
-
|
119
|
-
|
120
|
-
<div id="method-i-analyze_for_fitness-21" class="method-detail ">
|
121
|
-
|
122
|
-
<div class="method-heading">
|
123
|
-
<span class="method-name">analyze_for_fitness!</span><span
|
124
|
-
class="method-args">(critter)</span>
|
125
|
-
|
126
|
-
<span class="method-click-advice">click to toggle source</span>
|
127
|
-
|
128
|
-
</div>
|
129
|
-
|
130
|
-
|
131
|
-
<div class="method-description">
|
132
|
-
|
133
|
-
<p>Analyze the evaluation and compute a fitness for the given critter. Note
|
134
|
-
that if cost_func is set, we call that to integrate the cost to the fitness
|
135
|
-
average fitness calculated for the fitness vector.</p>
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
<div class="method-source-code" id="analyze_for_fitness-21-source">
|
141
|
-
<pre><span class="ruby-comment"># File lib/rubyneat/evaluator.rb, line 40</span>
|
142
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">analyze_for_fitness!</span>(<span class="ruby-identifier">critter</span>)
|
143
|
-
<span class="ruby-identifier">fitvec</span> = <span class="ruby-ivar">@crit_hist</span>[<span class="ruby-identifier">critter</span>].<span class="ruby-identifier">map</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">seq</span>, <span class="ruby-identifier">vio</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">fitness_func</span>.(<span class="ruby-identifier">vio</span>[<span class="ruby-value">0</span>], <span class="ruby-identifier">vio</span>[<span class="ruby-value">1</span>], <span class="ruby-identifier">seq</span>) }
|
144
|
-
<span class="ruby-comment"># Average the fitness vector to get a scalar fitness.</span>
|
145
|
-
<span class="ruby-identifier">critter</span>.<span class="ruby-identifier">fitness</span> = <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">cost_func</span>.<span class="ruby-identifier">nil?</span>
|
146
|
-
<span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">cost_func</span>.(<span class="ruby-identifier">fitvec</span>, <span class="ruby-identifier">critter</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">fitness_cost</span>)
|
147
|
-
<span class="ruby-keyword">else</span>
|
148
|
-
<span class="ruby-identifier">fitvec</span>.<span class="ruby-identifier">reduce</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">a</span>,<span class="ruby-identifier">r</span><span class="ruby-operator">|</span> <span class="ruby-identifier">a</span><span class="ruby-operator">+</span><span class="ruby-identifier">r</span>} <span class="ruby-operator">/</span> <span class="ruby-identifier">fitvec</span>.<span class="ruby-identifier">size</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">critter</span>.<span class="ruby-identifier">genotype</span>.<span class="ruby-identifier">fitness_cost</span>
|
149
|
-
<span class="ruby-keyword">end</span>
|
150
|
-
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">"Fitness Vector: #{fitvec}, fitness of #{critter.fitness} assigned to #{critter}"</span>
|
151
|
-
<span class="ruby-keyword">end</span></pre>
|
152
|
-
</div>
|
153
|
-
|
154
|
-
</div>
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
</div>
|
160
|
-
|
161
|
-
|
162
|
-
<div id="method-i-evaluate-21" class="method-detail ">
|
163
|
-
|
164
|
-
<div class="method-heading">
|
165
|
-
<span class="method-name">evaluate!</span><span
|
166
|
-
class="method-args">(critter)</span>
|
167
|
-
|
168
|
-
<span class="method-click-advice">click to toggle source</span>
|
169
|
-
|
170
|
-
</div>
|
171
|
-
|
172
|
-
|
173
|
-
<div class="method-description">
|
174
|
-
|
175
|
-
<p>Evaluate one step of a sequence of evaluations. For time series and
|
176
|
-
realtime ongoing evaluations, @controller.seq_num governs where in the
|
177
|
-
sequence everything is.</p>
|
178
|
-
|
179
|
-
<p>Returns [vin, vout], where vin is the input vector, and vout in the output
|
180
|
-
vector from the critter. FIXME: this should not really have to deal with an
|
181
|
-
error. FIXME: the error should be handled upstream from here.</p>
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
<div class="method-source-code" id="evaluate-21-source">
|
187
|
-
<pre><span class="ruby-comment"># File lib/rubyneat/evaluator.rb, line 24</span>
|
188
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">evaluate!</span>(<span class="ruby-identifier">critter</span>)
|
189
|
-
<span class="ruby-identifier">vin</span> = <span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">query_func</span>.(<span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">seq_num</span>)
|
190
|
-
<span class="ruby-ivar">@crit_hist</span>[<span class="ruby-identifier">critter</span>] = {} <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@crit_hist</span>.<span class="ruby-identifier">member?</span> <span class="ruby-identifier">critter</span>
|
191
|
-
<span class="ruby-keyword">begin</span>
|
192
|
-
<span class="ruby-identifier">vout</span> = <span class="ruby-identifier">critter</span>.<span class="ruby-identifier">phenotype</span>.<span class="ruby-identifier">stimulate</span> <span class="ruby-operator">*</span><span class="ruby-identifier">vin</span>, <span class="ruby-operator">&</span><span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">recurrence_func</span>
|
193
|
-
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">debug</span> <span class="ruby-node">"Critter #{critter.name}: vin=#{vin}. vout=#{vout}"</span>
|
194
|
-
<span class="ruby-ivar">@crit_hist</span>[<span class="ruby-identifier">critter</span>][<span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">seq_num</span>] = [<span class="ruby-identifier">vin</span>, <span class="ruby-identifier">vout</span>]
|
195
|
-
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
196
|
-
<span class="ruby-identifier">log</span>.<span class="ruby-identifier">error</span> <span class="ruby-node">"Exception #{e} on code:\n#{critter.phenotype.code}"</span>
|
197
|
-
<span class="ruby-ivar">@crit_hist</span>[<span class="ruby-identifier">critter</span>][<span class="ruby-ivar">@controller</span>.<span class="ruby-identifier">seq_num</span>] = [<span class="ruby-identifier">vin</span>, <span class="ruby-value">:error</span>]
|
198
|
-
<span class="ruby-keyword">end</span>
|
199
|
-
<span class="ruby-keyword">end</span></pre>
|
200
|
-
</div>
|
201
|
-
|
202
|
-
</div>
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
</div>
|
208
|
-
|
209
|
-
|
210
|
-
<div id="method-i-ready_for_evaluation" class="method-detail ">
|
211
|
-
|
212
|
-
<div class="method-heading">
|
213
|
-
<span class="method-name">ready_for_evaluation</span><span
|
214
|
-
class="method-args">(pop)</span>
|
215
|
-
|
216
|
-
<span class="method-click-advice">click to toggle source</span>
|
217
|
-
|
218
|
-
</div>
|
219
|
-
|
220
|
-
|
221
|
-
<div class="method-description">
|
222
|
-
|
223
|
-
<p>This is call prior to any sequence evaluation. Here, we clean up persistent
|
224
|
-
tracking information, etc.</p>
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
<div class="method-source-code" id="ready_for_evaluation-source">
|
230
|
-
<pre><span class="ruby-comment"># File lib/rubyneat/evaluator.rb, line 10</span>
|
231
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier">ready_for_evaluation</span>(<span class="ruby-identifier">pop</span>)
|
232
|
-
<span class="ruby-ivar">@crit_hist</span> = {}
|
233
|
-
<span class="ruby-identifier">pop</span>.<span class="ruby-identifier">initialize_for_recurrence!</span>
|
234
|
-
<span class="ruby-keyword">end</span></pre>
|
235
|
-
</div>
|
236
|
-
|
237
|
-
</div>
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
</div>
|
243
|
-
|
244
|
-
|
245
|
-
</section>
|
246
|
-
|
247
|
-
</section>
|
248
|
-
</main>
|
249
|
-
|
250
|
-
|
251
|
-
<footer id="validator-badges" role="contentinfo">
|
252
|
-
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
253
|
-
<p>Generated by <a href="http://rdoc.rubyforge.org">RDoc</a> 4.1.1.
|
254
|
-
<p>Based on <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
255
|
-
</footer>
|
256
|
-
|
data/rdoc/NEAT/Evolver.html
DELETED
@@ -1,891 +0,0 @@
|
|
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
|
-
|