evolvable 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +2 -0
- data/CHANGELOG.md +31 -1
- data/Gemfile +2 -2
- data/Gemfile.lock +44 -25
- data/README.md +498 -190
- data/README_YARD.md +85 -166
- data/bin/console +10 -19
- data/docs/Evolvable/ClassMethods.html +1233 -0
- data/docs/Evolvable/Community/ClassMethods.html +708 -0
- data/docs/Evolvable/Community.html +1342 -0
- data/docs/Evolvable/CountGene.html +886 -0
- data/docs/Evolvable/EqualizeGoal.html +347 -0
- data/docs/Evolvable/Error.html +134 -0
- data/docs/Evolvable/Evaluation.html +773 -0
- data/docs/Evolvable/Evolution.html +616 -0
- data/docs/Evolvable/Gene/ClassMethods.html +413 -0
- data/docs/Evolvable/Gene.html +522 -0
- data/docs/Evolvable/GeneCluster/ClassMethods.html +431 -0
- data/docs/Evolvable/GeneCluster.html +280 -0
- data/docs/Evolvable/GeneCombination.html +515 -0
- data/docs/Evolvable/GeneSpace.html +619 -0
- data/docs/Evolvable/Genome.html +1070 -0
- data/docs/Evolvable/Goal.html +500 -0
- data/docs/Evolvable/MaximizeGoal.html +348 -0
- data/docs/Evolvable/MinimizeGoal.html +348 -0
- data/docs/Evolvable/Mutation.html +729 -0
- data/docs/Evolvable/PointCrossover.html +444 -0
- data/docs/Evolvable/Population.html +2826 -0
- data/docs/Evolvable/RigidCountGene.html +501 -0
- data/docs/Evolvable/Selection.html +594 -0
- data/docs/Evolvable/Serializer.html +293 -0
- data/docs/Evolvable/UniformCrossover.html +286 -0
- data/docs/Evolvable.html +1619 -0
- data/docs/_index.html +341 -0
- data/docs/class_list.html +54 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +503 -0
- data/docs/file.README.html +750 -0
- data/docs/file_list.html +59 -0
- data/docs/frames.html +22 -0
- data/docs/index.html +750 -0
- data/docs/js/app.js +344 -0
- data/docs/js/full_list.js +242 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +1302 -0
- data/docs/top-level-namespace.html +110 -0
- data/evolvable.gemspec +6 -6
- data/examples/ascii_art.rb +5 -9
- data/examples/stickman.rb +25 -33
- data/{examples/hello_world.rb → exe/hello_evolvable_world} +46 -30
- data/lib/evolvable/community.rb +190 -0
- data/lib/evolvable/count_gene.rb +65 -0
- data/lib/evolvable/equalize_goal.rb +2 -9
- data/lib/evolvable/evaluation.rb +113 -14
- data/lib/evolvable/evolution.rb +38 -15
- data/lib/evolvable/gene.rb +125 -28
- data/lib/evolvable/gene_cluster.rb +106 -0
- data/lib/evolvable/gene_combination.rb +62 -17
- data/lib/evolvable/gene_space.rb +111 -0
- data/lib/evolvable/genome.rb +36 -8
- data/lib/evolvable/goal.rb +19 -24
- data/lib/evolvable/maximize_goal.rb +2 -9
- data/lib/evolvable/minimize_goal.rb +3 -9
- data/lib/evolvable/mutation.rb +87 -41
- data/lib/evolvable/point_crossover.rb +24 -4
- data/lib/evolvable/population.rb +258 -84
- data/lib/evolvable/rigid_count_gene.rb +36 -0
- data/lib/evolvable/selection.rb +68 -14
- data/lib/evolvable/serializer.rb +46 -0
- data/lib/evolvable/uniform_crossover.rb +30 -6
- data/lib/evolvable/version.rb +2 -1
- data/lib/evolvable.rb +276 -107
- metadata +57 -36
- data/examples/images/diagram.png +0 -0
- data/exe/hello +0 -16
- data/lib/evolvable/error/undefined_method.rb +0 -7
- data/lib/evolvable/search_space.rb +0 -181
@@ -0,0 +1,773 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Class: Evolvable::Evaluation
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.37
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "Evolvable::Evaluation";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (E)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">Evaluation</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Class: Evolvable::Evaluation
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
<dl>
|
70
|
+
<dt>Inherits:</dt>
|
71
|
+
<dd>
|
72
|
+
<span class="inheritName">Object</span>
|
73
|
+
|
74
|
+
<ul class="fullTree">
|
75
|
+
<li>Object</li>
|
76
|
+
|
77
|
+
<li class="next">Evolvable::Evaluation</li>
|
78
|
+
|
79
|
+
</ul>
|
80
|
+
<a href="#" class="inheritanceTree">show all</a>
|
81
|
+
|
82
|
+
</dd>
|
83
|
+
</dl>
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
<dl>
|
96
|
+
<dt>Defined in:</dt>
|
97
|
+
<dd>lib/evolvable/evaluation.rb</dd>
|
98
|
+
</dl>
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<h2>Overview</h2><div class="docstring">
|
103
|
+
<div class="discussion">
|
104
|
+
<p>Evaluation sorts evolvables based on their fitness and provides mechanisms to
|
105
|
+
change the goal type and value (fitness goal). Goals define the success criteria
|
106
|
+
for evolution. They allow you to specify what your population is evolving toward,
|
107
|
+
whether it's maximizing a value, minimizing a value, or seeking a specific value.</p>
|
108
|
+
|
109
|
+
<p><strong>How It Works</strong></p>
|
110
|
+
|
111
|
+
<ol>
|
112
|
+
<li><p>Your evolvable class defines a <code>#fitness</code> method that returns a
|
113
|
+
<a href="https://docs.ruby-lang.org/en//3.4/Comparable.html">Comparable</a> object.</p>
|
114
|
+
|
115
|
+
<ul>
|
116
|
+
<li>Preferably a numeric value like an integer or float.</li>
|
117
|
+
</ul></li>
|
118
|
+
<li><p>During evolution, evolvables are sorted by your goal's fitness interpretation</p>
|
119
|
+
|
120
|
+
<ul>
|
121
|
+
<li>The default goal type is <code>:maximize</code>, see goal types below for other options</li>
|
122
|
+
</ul></li>
|
123
|
+
<li><p>If a goal value is specified, evolution will stop when it is met</p></li>
|
124
|
+
</ol>
|
125
|
+
|
126
|
+
<p><strong>Goal Types</strong></p>
|
127
|
+
|
128
|
+
<ul>
|
129
|
+
<li>Maximize (higher is better)</li>
|
130
|
+
</ul>
|
131
|
+
|
132
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_robots'>robots</span> <span class='op'>=</span> <span class='const'>Robot</span><span class='period'>.</span><span class='id identifier rubyid_new_population'>new_population</span><span class='lparen'>(</span><span class='label'>evaluation:</span> <span class='symbol'>:maximize</span><span class='rparen'>)</span> <span class='comment'># Defaults to infinity
|
133
|
+
</span><span class='id identifier rubyid_robots'>robots</span><span class='period'>.</span><span class='id identifier rubyid_evolve_to_goal'>evolve_to_goal</span><span class='lparen'>(</span><span class='int'>100</span><span class='rparen'>)</span> <span class='comment'># Evolve until fitness reaches 100+
|
134
|
+
</span>
|
135
|
+
<span class='comment'># Same as above
|
136
|
+
</span><span class='const'>Robot</span><span class='period'>.</span><span class='id identifier rubyid_new_population'>new_population</span><span class='lparen'>(</span><span class='label'>evaluation:</span> <span class='lbrace'>{</span> <span class='label'>maximize:</span> <span class='int'>100</span> <span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_evolve_to_goal'>evolve_to_goal</span>
|
137
|
+
</code></pre>
|
138
|
+
|
139
|
+
<ul>
|
140
|
+
<li>Minimize (lower is better)</li>
|
141
|
+
</ul>
|
142
|
+
|
143
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_errors'>errors</span> <span class='op'>=</span> <span class='const'>ErrorModel</span><span class='period'>.</span><span class='id identifier rubyid_new_population'>new_population</span><span class='lparen'>(</span><span class='label'>evaluation:</span> <span class='symbol'>:minimize</span><span class='rparen'>)</span> <span class='comment'># Defaults to -infinity
|
144
|
+
</span><span class='id identifier rubyid_errors'>errors</span><span class='period'>.</span><span class='id identifier rubyid_evolve_to_goal'>evolve_to_goal</span><span class='lparen'>(</span><span class='float'>0.01</span><span class='rparen'>)</span> <span class='comment'># Evolve until error rate reaches 0.01 or less
|
145
|
+
</span>
|
146
|
+
<span class='comment'># Same as above
|
147
|
+
</span><span class='const'>ErrorModel</span><span class='period'>.</span><span class='id identifier rubyid_new_population'>new_population</span><span class='lparen'>(</span><span class='label'>evaluation:</span> <span class='lbrace'>{</span> <span class='label'>minimize:</span> <span class='float'>0.01</span> <span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_evolve_to_goal'>evolve_to_goal</span>
|
148
|
+
</code></pre>
|
149
|
+
|
150
|
+
<ul>
|
151
|
+
<li>Equalize (closer to target is better)</li>
|
152
|
+
</ul>
|
153
|
+
|
154
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_targets'>targets</span> <span class='op'>=</span> <span class='const'>TargetMatcher</span><span class='period'>.</span><span class='id identifier rubyid_new_population'>new_population</span><span class='lparen'>(</span><span class='label'>evaluation:</span> <span class='symbol'>:equalize</span><span class='rparen'>)</span> <span class='comment'># Defaults to 0
|
155
|
+
</span><span class='id identifier rubyid_targets'>targets</span><span class='period'>.</span><span class='id identifier rubyid_evolve_to_goal'>evolve_to_goal</span><span class='lparen'>(</span><span class='int'>42</span><span class='rparen'>)</span> <span class='comment'># Evolve until we match the target value
|
156
|
+
</span>
|
157
|
+
<span class='comment'># Same as above
|
158
|
+
</span><span class='const'>TargetMatcher</span><span class='period'>.</span><span class='id identifier rubyid_new_population'>new_population</span><span class='lparen'>(</span><span class='label'>evaluation:</span> <span class='lbrace'>{</span> <span class='label'>equalize:</span> <span class='int'>42</span> <span class='rbrace'>}</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_evolve_to_goal'>evolve_to_goal</span>
|
159
|
+
</code></pre>
|
160
|
+
|
161
|
+
|
162
|
+
</div>
|
163
|
+
</div>
|
164
|
+
<div class="tags">
|
165
|
+
|
166
|
+
|
167
|
+
<p class="tag_title">See Also:</p>
|
168
|
+
<ul class="see">
|
169
|
+
|
170
|
+
<li><span class='object_link'><a href="Population.html" title="Evolvable::Population (class)">Population</a></span></li>
|
171
|
+
|
172
|
+
<li><span class='object_link'><a href="Selection.html" title="Evolvable::Selection (class)">Selection</a></span></li>
|
173
|
+
|
174
|
+
</ul>
|
175
|
+
|
176
|
+
</div>
|
177
|
+
|
178
|
+
<h2>
|
179
|
+
Constant Summary
|
180
|
+
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
|
181
|
+
</h2>
|
182
|
+
|
183
|
+
<dl class="constants">
|
184
|
+
|
185
|
+
<dt id="GOALS-constant" class="">GOALS =
|
186
|
+
<div class="docstring">
|
187
|
+
<div class="discussion">
|
188
|
+
<p>Mapping of goal type symbols to their corresponding goal objects.
|
189
|
+
See the readme section above for details on each goal type.</p>
|
190
|
+
|
191
|
+
|
192
|
+
</div>
|
193
|
+
</div>
|
194
|
+
<div class="tags">
|
195
|
+
|
196
|
+
<p class="tag_title">Returns:</p>
|
197
|
+
<ul class="return">
|
198
|
+
|
199
|
+
<li>
|
200
|
+
|
201
|
+
|
202
|
+
<span class='type'>(<tt>Hash<Symbol, <span class='object_link'><a href="Goal.html" title="Evolvable::Goal (class)">Evolvable::Goal</a></span>></tt>)</span>
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
—
|
207
|
+
<div class='inline'><p>Available goal objects by type</p>
|
208
|
+
</div>
|
209
|
+
|
210
|
+
</li>
|
211
|
+
|
212
|
+
</ul>
|
213
|
+
|
214
|
+
</div>
|
215
|
+
</dt>
|
216
|
+
<dd><pre class="code"><span class='lbrace'>{</span> <span class='label'>maximize:</span> <span class='const'><span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MaximizeGoal.html" title="Evolvable::MaximizeGoal (class)">MaximizeGoal</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Goal.html#initialize-instance_method" title="Evolvable::Goal#initialize (method)">new</a></span></span><span class='comma'>,</span>
|
217
|
+
<span class='label'>minimize:</span> <span class='const'><span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MinimizeGoal.html" title="Evolvable::MinimizeGoal (class)">MinimizeGoal</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Goal.html#initialize-instance_method" title="Evolvable::Goal#initialize (method)">new</a></span></span><span class='comma'>,</span>
|
218
|
+
<span class='label'>equalize:</span> <span class='const'><span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="EqualizeGoal.html" title="Evolvable::EqualizeGoal (class)">EqualizeGoal</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Goal.html#initialize-instance_method" title="Evolvable::Goal#initialize (method)">new</a></span></span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
|
219
|
+
|
220
|
+
<dt id="DEFAULT_GOAL_TYPE-constant" class="">DEFAULT_GOAL_TYPE =
|
221
|
+
<div class="docstring">
|
222
|
+
<div class="discussion">
|
223
|
+
<p>The default goal type used if none is specified.</p>
|
224
|
+
|
225
|
+
|
226
|
+
</div>
|
227
|
+
</div>
|
228
|
+
<div class="tags">
|
229
|
+
|
230
|
+
<p class="tag_title">Returns:</p>
|
231
|
+
<ul class="return">
|
232
|
+
|
233
|
+
<li>
|
234
|
+
|
235
|
+
|
236
|
+
<span class='type'>(<tt>Symbol</tt>)</span>
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
—
|
241
|
+
<div class='inline'><p>The default goal type (maximize)</p>
|
242
|
+
</div>
|
243
|
+
|
244
|
+
</li>
|
245
|
+
|
246
|
+
</ul>
|
247
|
+
|
248
|
+
</div>
|
249
|
+
</dt>
|
250
|
+
<dd><pre class="code"><span class='symbol'>:maximize</span></pre></dd>
|
251
|
+
|
252
|
+
</dl>
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
<h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
|
259
|
+
<ul class="summary">
|
260
|
+
|
261
|
+
<li class="public ">
|
262
|
+
<span class="summary_signature">
|
263
|
+
|
264
|
+
<a href="#goal-instance_method" title="#goal (instance method)">#<strong>goal</strong> ⇒ Evolvable::Goal </a>
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
</span>
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
<span class="summary_desc"><div class='inline'><p>The goal object used for evaluation.</p>
|
282
|
+
</div></span>
|
283
|
+
|
284
|
+
</li>
|
285
|
+
|
286
|
+
|
287
|
+
</ul>
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
<h2>
|
294
|
+
Instance Method Summary
|
295
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
296
|
+
</h2>
|
297
|
+
|
298
|
+
<ul class="summary">
|
299
|
+
|
300
|
+
<li class="public ">
|
301
|
+
<span class="summary_signature">
|
302
|
+
|
303
|
+
<a href="#best_evolvable-instance_method" title="#best_evolvable (instance method)">#<strong>best_evolvable</strong>(population) ⇒ Evolvable </a>
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
</span>
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
<span class="summary_desc"><div class='inline'><p>Returns the best evolvable in the population according to the goal.</p>
|
318
|
+
</div></span>
|
319
|
+
|
320
|
+
</li>
|
321
|
+
|
322
|
+
|
323
|
+
<li class="public ">
|
324
|
+
<span class="summary_signature">
|
325
|
+
|
326
|
+
<a href="#call-instance_method" title="#call (instance method)">#<strong>call</strong>(population) ⇒ Array<Evolvable> </a>
|
327
|
+
|
328
|
+
|
329
|
+
|
330
|
+
</span>
|
331
|
+
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
<span class="summary_desc"><div class='inline'><p>Evaluates and sorts all evolvables in the population according to the goal.</p>
|
341
|
+
</div></span>
|
342
|
+
|
343
|
+
</li>
|
344
|
+
|
345
|
+
|
346
|
+
<li class="public ">
|
347
|
+
<span class="summary_signature">
|
348
|
+
|
349
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(goal = DEFAULT_GOAL_TYPE) ⇒ Evaluation </a>
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
</span>
|
354
|
+
|
355
|
+
|
356
|
+
<span class="note title constructor">constructor</span>
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
<span class="summary_desc"><div class='inline'><p>Initializes a new evaluation object.</p>
|
366
|
+
</div></span>
|
367
|
+
|
368
|
+
</li>
|
369
|
+
|
370
|
+
|
371
|
+
<li class="public ">
|
372
|
+
<span class="summary_signature">
|
373
|
+
|
374
|
+
<a href="#met_goal%3F-instance_method" title="#met_goal? (instance method)">#<strong>met_goal?</strong>(population) ⇒ Boolean </a>
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
</span>
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
<span class="summary_desc"><div class='inline'><p>Checks if the goal has been met by any evolvable in the population.</p>
|
389
|
+
</div></span>
|
390
|
+
|
391
|
+
</li>
|
392
|
+
|
393
|
+
|
394
|
+
</ul>
|
395
|
+
|
396
|
+
|
397
|
+
<div id="constructor_details" class="method_details_list">
|
398
|
+
<h2>Constructor Details</h2>
|
399
|
+
|
400
|
+
<div class="method_details first">
|
401
|
+
<h3 class="signature first" id="initialize-instance_method">
|
402
|
+
|
403
|
+
#<strong>initialize</strong>(goal = DEFAULT_GOAL_TYPE) ⇒ <tt><span class='object_link'><a href="" title="Evolvable::Evaluation (class)">Evaluation</a></span></tt>
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
</h3><div class="docstring">
|
410
|
+
<div class="discussion">
|
411
|
+
<p>Initializes a new evaluation object.</p>
|
412
|
+
|
413
|
+
|
414
|
+
</div>
|
415
|
+
</div>
|
416
|
+
<div class="tags">
|
417
|
+
<p class="tag_title">Parameters:</p>
|
418
|
+
<ul class="param">
|
419
|
+
|
420
|
+
<li>
|
421
|
+
|
422
|
+
<span class='name'>goal</span>
|
423
|
+
|
424
|
+
|
425
|
+
<span class='type'>(<tt>Symbol</tt>, <tt>Hash</tt>, <tt><span class='object_link'><a href="Goal.html" title="Evolvable::Goal (class)">Evolvable::Goal</a></span></tt>)</span>
|
426
|
+
|
427
|
+
|
428
|
+
<em class="default">(defaults to: <tt>DEFAULT_GOAL_TYPE</tt>)</em>
|
429
|
+
|
430
|
+
|
431
|
+
—
|
432
|
+
<div class='inline'><p>The goal type (:maximize, :minimize, :equalize),
|
433
|
+
a hash specifying goal type and value, or a custom goal object</p>
|
434
|
+
</div>
|
435
|
+
|
436
|
+
</li>
|
437
|
+
|
438
|
+
</ul>
|
439
|
+
|
440
|
+
|
441
|
+
</div><table class="source_code">
|
442
|
+
<tr>
|
443
|
+
<td>
|
444
|
+
<pre class="lines">
|
445
|
+
|
446
|
+
|
447
|
+
80
|
448
|
+
81
|
449
|
+
82</pre>
|
450
|
+
</td>
|
451
|
+
<td>
|
452
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/evaluation.rb', line 80</span>
|
453
|
+
|
454
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_goal'>goal</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="#DEFAULT_GOAL_TYPE-constant" title="Evolvable::Evaluation::DEFAULT_GOAL_TYPE (constant)">DEFAULT_GOAL_TYPE</a></span></span><span class='rparen'>)</span>
|
455
|
+
<span class='ivar'>@goal</span> <span class='op'>=</span> <span class='id identifier rubyid_normalize_goal'>normalize_goal</span><span class='lparen'>(</span><span class='id identifier rubyid_goal'>goal</span><span class='rparen'>)</span>
|
456
|
+
<span class='kw'>end</span></pre>
|
457
|
+
</td>
|
458
|
+
</tr>
|
459
|
+
</table>
|
460
|
+
</div>
|
461
|
+
|
462
|
+
</div>
|
463
|
+
|
464
|
+
<div id="instance_attr_details" class="attr_details">
|
465
|
+
<h2>Instance Attribute Details</h2>
|
466
|
+
|
467
|
+
|
468
|
+
<span id="goal=-instance_method"></span>
|
469
|
+
<div class="method_details first">
|
470
|
+
<h3 class="signature first" id="goal-instance_method">
|
471
|
+
|
472
|
+
#<strong>goal</strong> ⇒ <tt><span class='object_link'><a href="Goal.html" title="Evolvable::Goal (class)">Evolvable::Goal</a></span></tt>
|
473
|
+
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
|
478
|
+
</h3><div class="docstring">
|
479
|
+
<div class="discussion">
|
480
|
+
<p>The goal object used for evaluation.</p>
|
481
|
+
|
482
|
+
|
483
|
+
</div>
|
484
|
+
</div>
|
485
|
+
<div class="tags">
|
486
|
+
|
487
|
+
<p class="tag_title">Returns:</p>
|
488
|
+
<ul class="return">
|
489
|
+
|
490
|
+
<li>
|
491
|
+
|
492
|
+
|
493
|
+
<span class='type'>(<tt><span class='object_link'><a href="Goal.html" title="Evolvable::Goal (class)">Evolvable::Goal</a></span></tt>)</span>
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
—
|
498
|
+
<div class='inline'><p>The current goal object</p>
|
499
|
+
</div>
|
500
|
+
|
501
|
+
</li>
|
502
|
+
|
503
|
+
</ul>
|
504
|
+
|
505
|
+
</div><table class="source_code">
|
506
|
+
<tr>
|
507
|
+
<td>
|
508
|
+
<pre class="lines">
|
509
|
+
|
510
|
+
|
511
|
+
88
|
512
|
+
89
|
513
|
+
90</pre>
|
514
|
+
</td>
|
515
|
+
<td>
|
516
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/evaluation.rb', line 88</span>
|
517
|
+
|
518
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_goal'>goal</span>
|
519
|
+
<span class='ivar'>@goal</span>
|
520
|
+
<span class='kw'>end</span></pre>
|
521
|
+
</td>
|
522
|
+
</tr>
|
523
|
+
</table>
|
524
|
+
</div>
|
525
|
+
|
526
|
+
</div>
|
527
|
+
|
528
|
+
|
529
|
+
<div id="instance_method_details" class="method_details_list">
|
530
|
+
<h2>Instance Method Details</h2>
|
531
|
+
|
532
|
+
|
533
|
+
<div class="method_details first">
|
534
|
+
<h3 class="signature first" id="best_evolvable-instance_method">
|
535
|
+
|
536
|
+
#<strong>best_evolvable</strong>(population) ⇒ <tt><span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span></tt>
|
537
|
+
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
|
542
|
+
</h3><div class="docstring">
|
543
|
+
<div class="discussion">
|
544
|
+
<p>Returns the best evolvable in the population according to the goal.</p>
|
545
|
+
|
546
|
+
|
547
|
+
</div>
|
548
|
+
</div>
|
549
|
+
<div class="tags">
|
550
|
+
<p class="tag_title">Parameters:</p>
|
551
|
+
<ul class="param">
|
552
|
+
|
553
|
+
<li>
|
554
|
+
|
555
|
+
<span class='name'>population</span>
|
556
|
+
|
557
|
+
|
558
|
+
<span class='type'>(<tt><span class='object_link'><a href="Population.html" title="Evolvable::Population (class)">Evolvable::Population</a></span></tt>)</span>
|
559
|
+
|
560
|
+
|
561
|
+
|
562
|
+
—
|
563
|
+
<div class='inline'><p>The population to evaluate</p>
|
564
|
+
</div>
|
565
|
+
|
566
|
+
</li>
|
567
|
+
|
568
|
+
</ul>
|
569
|
+
|
570
|
+
<p class="tag_title">Returns:</p>
|
571
|
+
<ul class="return">
|
572
|
+
|
573
|
+
<li>
|
574
|
+
|
575
|
+
|
576
|
+
<span class='type'>(<tt><span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span></tt>)</span>
|
577
|
+
|
578
|
+
|
579
|
+
|
580
|
+
—
|
581
|
+
<div class='inline'><p>The best evolvable based on the current goal</p>
|
582
|
+
</div>
|
583
|
+
|
584
|
+
</li>
|
585
|
+
|
586
|
+
</ul>
|
587
|
+
|
588
|
+
</div><table class="source_code">
|
589
|
+
<tr>
|
590
|
+
<td>
|
591
|
+
<pre class="lines">
|
592
|
+
|
593
|
+
|
594
|
+
106
|
595
|
+
107
|
596
|
+
108</pre>
|
597
|
+
</td>
|
598
|
+
<td>
|
599
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/evaluation.rb', line 106</span>
|
600
|
+
|
601
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_best_evolvable'>best_evolvable</span><span class='lparen'>(</span><span class='id identifier rubyid_population'>population</span><span class='rparen'>)</span>
|
602
|
+
<span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_evolvables'>evolvables</span><span class='period'>.</span><span class='id identifier rubyid_max_by'>max_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_evolvable'>evolvable</span><span class='op'>|</span> <span class='id identifier rubyid_goal'>goal</span><span class='period'>.</span><span class='id identifier rubyid_evaluate'>evaluate</span><span class='lparen'>(</span><span class='id identifier rubyid_evolvable'>evolvable</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
603
|
+
<span class='kw'>end</span></pre>
|
604
|
+
</td>
|
605
|
+
</tr>
|
606
|
+
</table>
|
607
|
+
</div>
|
608
|
+
|
609
|
+
<div class="method_details ">
|
610
|
+
<h3 class="signature " id="call-instance_method">
|
611
|
+
|
612
|
+
#<strong>call</strong>(population) ⇒ <tt>Array<<span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span>></tt>
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
</h3><div class="docstring">
|
619
|
+
<div class="discussion">
|
620
|
+
<p>Evaluates and sorts all evolvables in the population according to the goal.</p>
|
621
|
+
|
622
|
+
|
623
|
+
</div>
|
624
|
+
</div>
|
625
|
+
<div class="tags">
|
626
|
+
<p class="tag_title">Parameters:</p>
|
627
|
+
<ul class="param">
|
628
|
+
|
629
|
+
<li>
|
630
|
+
|
631
|
+
<span class='name'>population</span>
|
632
|
+
|
633
|
+
|
634
|
+
<span class='type'>(<tt><span class='object_link'><a href="Population.html" title="Evolvable::Population (class)">Evolvable::Population</a></span></tt>)</span>
|
635
|
+
|
636
|
+
|
637
|
+
|
638
|
+
—
|
639
|
+
<div class='inline'><p>The population to evaluate</p>
|
640
|
+
</div>
|
641
|
+
|
642
|
+
</li>
|
643
|
+
|
644
|
+
</ul>
|
645
|
+
|
646
|
+
<p class="tag_title">Returns:</p>
|
647
|
+
<ul class="return">
|
648
|
+
|
649
|
+
<li>
|
650
|
+
|
651
|
+
|
652
|
+
<span class='type'>(<tt>Array<<span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span>></tt>)</span>
|
653
|
+
|
654
|
+
|
655
|
+
|
656
|
+
—
|
657
|
+
<div class='inline'><p>The sorted evolvables</p>
|
658
|
+
</div>
|
659
|
+
|
660
|
+
</li>
|
661
|
+
|
662
|
+
</ul>
|
663
|
+
|
664
|
+
</div><table class="source_code">
|
665
|
+
<tr>
|
666
|
+
<td>
|
667
|
+
<pre class="lines">
|
668
|
+
|
669
|
+
|
670
|
+
96
|
671
|
+
97
|
672
|
+
98</pre>
|
673
|
+
</td>
|
674
|
+
<td>
|
675
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/evaluation.rb', line 96</span>
|
676
|
+
|
677
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_population'>population</span><span class='rparen'>)</span>
|
678
|
+
<span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_evolvables'>evolvables</span><span class='period'>.</span><span class='id identifier rubyid_sort_by!'>sort_by!</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_evolvable'>evolvable</span><span class='op'>|</span> <span class='id identifier rubyid_goal'>goal</span><span class='period'>.</span><span class='id identifier rubyid_evaluate'>evaluate</span><span class='lparen'>(</span><span class='id identifier rubyid_evolvable'>evolvable</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
679
|
+
<span class='kw'>end</span></pre>
|
680
|
+
</td>
|
681
|
+
</tr>
|
682
|
+
</table>
|
683
|
+
</div>
|
684
|
+
|
685
|
+
<div class="method_details ">
|
686
|
+
<h3 class="signature " id="met_goal?-instance_method">
|
687
|
+
|
688
|
+
#<strong>met_goal?</strong>(population) ⇒ <tt>Boolean</tt>
|
689
|
+
|
690
|
+
|
691
|
+
|
692
|
+
|
693
|
+
|
694
|
+
</h3><div class="docstring">
|
695
|
+
<div class="discussion">
|
696
|
+
<p>Checks if the goal has been met by any evolvable in the population.</p>
|
697
|
+
|
698
|
+
|
699
|
+
</div>
|
700
|
+
</div>
|
701
|
+
<div class="tags">
|
702
|
+
<p class="tag_title">Parameters:</p>
|
703
|
+
<ul class="param">
|
704
|
+
|
705
|
+
<li>
|
706
|
+
|
707
|
+
<span class='name'>population</span>
|
708
|
+
|
709
|
+
|
710
|
+
<span class='type'>(<tt><span class='object_link'><a href="Population.html" title="Evolvable::Population (class)">Evolvable::Population</a></span></tt>)</span>
|
711
|
+
|
712
|
+
|
713
|
+
|
714
|
+
—
|
715
|
+
<div class='inline'><p>The population to check</p>
|
716
|
+
</div>
|
717
|
+
|
718
|
+
</li>
|
719
|
+
|
720
|
+
</ul>
|
721
|
+
|
722
|
+
<p class="tag_title">Returns:</p>
|
723
|
+
<ul class="return">
|
724
|
+
|
725
|
+
<li>
|
726
|
+
|
727
|
+
|
728
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
729
|
+
|
730
|
+
|
731
|
+
|
732
|
+
—
|
733
|
+
<div class='inline'><p>True if the goal has been met, false otherwise</p>
|
734
|
+
</div>
|
735
|
+
|
736
|
+
</li>
|
737
|
+
|
738
|
+
</ul>
|
739
|
+
|
740
|
+
</div><table class="source_code">
|
741
|
+
<tr>
|
742
|
+
<td>
|
743
|
+
<pre class="lines">
|
744
|
+
|
745
|
+
|
746
|
+
116
|
747
|
+
117
|
748
|
+
118</pre>
|
749
|
+
</td>
|
750
|
+
<td>
|
751
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/evaluation.rb', line 116</span>
|
752
|
+
|
753
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_met_goal?'>met_goal?</span><span class='lparen'>(</span><span class='id identifier rubyid_population'>population</span><span class='rparen'>)</span>
|
754
|
+
<span class='id identifier rubyid_goal'>goal</span><span class='period'>.</span><span class='id identifier rubyid_met?'>met?</span><span class='lparen'>(</span><span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_evolvables'>evolvables</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='rparen'>)</span>
|
755
|
+
<span class='kw'>end</span></pre>
|
756
|
+
</td>
|
757
|
+
</tr>
|
758
|
+
</table>
|
759
|
+
</div>
|
760
|
+
|
761
|
+
</div>
|
762
|
+
|
763
|
+
</div>
|
764
|
+
|
765
|
+
<div id="footer">
|
766
|
+
Generated on Sat May 10 18:39:22 2025 by
|
767
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
768
|
+
0.9.37 (ruby-3.4.2).
|
769
|
+
</div>
|
770
|
+
|
771
|
+
</div>
|
772
|
+
</body>
|
773
|
+
</html>
|