evolvable 1.2.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 +24 -0
- 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 +124 -25
- data/lib/evolvable/gene_cluster.rb +106 -0
- data/lib/evolvable/gene_combination.rb +57 -16
- data/lib/evolvable/gene_space.rb +111 -0
- data/lib/evolvable/genome.rb +32 -4
- 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 +268 -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,729 @@
|
|
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::Mutation
|
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::Mutation";
|
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 (M)</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">Mutation</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::Mutation
|
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::Mutation</li>
|
78
|
+
|
79
|
+
</ul>
|
80
|
+
<a href="#" class="inheritanceTree">show all</a>
|
81
|
+
|
82
|
+
</dd>
|
83
|
+
</dl>
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
<dl>
|
89
|
+
<dt>Extended by:</dt>
|
90
|
+
<dd>Forwardable</dd>
|
91
|
+
</dl>
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
<dl>
|
101
|
+
<dt>Defined in:</dt>
|
102
|
+
<dd>lib/evolvable/mutation.rb</dd>
|
103
|
+
</dl>
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
<h2>Overview</h2><div class="docstring">
|
108
|
+
<div class="discussion">
|
109
|
+
<p>Mutation introduces genetic variation by randomly replacing genes with new
|
110
|
+
ones. This helps the population explore new areas of the solution space
|
111
|
+
and prevents premature convergence on suboptimal solutions.</p>
|
112
|
+
|
113
|
+
<p>Mutation is controlled by two key parameters:</p>
|
114
|
+
|
115
|
+
<ul>
|
116
|
+
<li><strong>probability</strong>: Likelihood that an individual will undergo mutation (range: 0.0–1.0)</li>
|
117
|
+
<li><strong>rate</strong>: Fraction of genes to mutate within those individuals (range: 0.0–1.0)</li>
|
118
|
+
</ul>
|
119
|
+
|
120
|
+
<p>A typical strategy is to start with higher mutation to encourage exploration:</p>
|
121
|
+
|
122
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_population'>population</span> <span class='op'>=</span> <span class='const'>MyEvolvable</span><span class='period'>.</span><span class='id identifier rubyid_new_population'>new_population</span><span class='lparen'>(</span>
|
123
|
+
<span class='label'>mutation:</span> <span class='lbrace'>{</span> <span class='label'>probability:</span> <span class='float'>0.4</span><span class='comma'>,</span> <span class='label'>rate:</span> <span class='float'>0.2</span> <span class='rbrace'>}</span>
|
124
|
+
<span class='rparen'>)</span>
|
125
|
+
</code></pre>
|
126
|
+
|
127
|
+
<p>Then later reduce the mutation rate to focus on refinement and convergence:</p>
|
128
|
+
|
129
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_mutation_probability'>mutation_probability</span> <span class='op'>=</span> <span class='float'>0.1</span>
|
130
|
+
<span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_mutation_rate'>mutation_rate</span> <span class='op'>=</span> <span class='float'>0.05</span>
|
131
|
+
</code></pre>
|
132
|
+
|
133
|
+
|
134
|
+
</div>
|
135
|
+
</div>
|
136
|
+
<div class="tags">
|
137
|
+
|
138
|
+
|
139
|
+
</div>
|
140
|
+
|
141
|
+
<h2>
|
142
|
+
Constant Summary
|
143
|
+
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
|
144
|
+
</h2>
|
145
|
+
|
146
|
+
<dl class="constants">
|
147
|
+
|
148
|
+
<dt id="DEFAULT_PROBABILITY-constant" class="">DEFAULT_PROBABILITY =
|
149
|
+
<div class="docstring">
|
150
|
+
<div class="discussion">
|
151
|
+
<p>The default probability of mutation (3%).
|
152
|
+
This is used when no probability is specified.</p>
|
153
|
+
|
154
|
+
|
155
|
+
</div>
|
156
|
+
</div>
|
157
|
+
<div class="tags">
|
158
|
+
|
159
|
+
|
160
|
+
</div>
|
161
|
+
</dt>
|
162
|
+
<dd><pre class="code"><span class='float'>0.03</span></pre></dd>
|
163
|
+
|
164
|
+
</dl>
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
<h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
|
171
|
+
<ul class="summary">
|
172
|
+
|
173
|
+
<li class="public ">
|
174
|
+
<span class="summary_signature">
|
175
|
+
|
176
|
+
<a href="#probability-instance_method" title="#probability (instance method)">#<strong>probability</strong> ⇒ Float </a>
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
</span>
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
<span class="summary_desc"><div class='inline'><p>The probability that an evolvable instance will undergo mutation.</p>
|
194
|
+
</div></span>
|
195
|
+
|
196
|
+
</li>
|
197
|
+
|
198
|
+
|
199
|
+
<li class="public ">
|
200
|
+
<span class="summary_signature">
|
201
|
+
|
202
|
+
<a href="#rate-instance_method" title="#rate (instance method)">#<strong>rate</strong> ⇒ Float<sup>?</sup> </a>
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
</span>
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
<span class="summary_desc"><div class='inline'><p>The rate at which genes mutate within an instance.</p>
|
220
|
+
</div></span>
|
221
|
+
|
222
|
+
</li>
|
223
|
+
|
224
|
+
|
225
|
+
</ul>
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
<h2>
|
232
|
+
Instance Method Summary
|
233
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
234
|
+
</h2>
|
235
|
+
|
236
|
+
<ul class="summary">
|
237
|
+
|
238
|
+
<li class="public ">
|
239
|
+
<span class="summary_signature">
|
240
|
+
|
241
|
+
<a href="#call-instance_method" title="#call (instance method)">#<strong>call</strong>(population) ⇒ Evolvable::Population </a>
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
</span>
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
<span class="summary_desc"><div class='inline'><p>Applies mutations to the population's evolvables based on the configured probability and rate.</p>
|
256
|
+
</div></span>
|
257
|
+
|
258
|
+
</li>
|
259
|
+
|
260
|
+
|
261
|
+
<li class="public ">
|
262
|
+
<span class="summary_signature">
|
263
|
+
|
264
|
+
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(probability: nil, rate: nil) ⇒ Mutation </a>
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
</span>
|
269
|
+
|
270
|
+
|
271
|
+
<span class="note title constructor">constructor</span>
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
<span class="summary_desc"><div class='inline'><p>Initializes a new mutation object.</p>
|
281
|
+
</div></span>
|
282
|
+
|
283
|
+
</li>
|
284
|
+
|
285
|
+
|
286
|
+
<li class="public ">
|
287
|
+
<span class="summary_signature">
|
288
|
+
|
289
|
+
<a href="#mutate_evolvables-instance_method" title="#mutate_evolvables (instance method)">#<strong>mutate_evolvables</strong>(evolvables) ⇒ Array<Evolvable> </a>
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
</span>
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
<span class="summary_desc"><div class='inline'><p>Mutates a collection of evolvable instances based on the mutation probability and rate.</p>
|
304
|
+
</div></span>
|
305
|
+
|
306
|
+
</li>
|
307
|
+
|
308
|
+
|
309
|
+
</ul>
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
<div id="constructor_details" class="method_details_list">
|
314
|
+
<h2>Constructor Details</h2>
|
315
|
+
|
316
|
+
<div class="method_details first">
|
317
|
+
<h3 class="signature first" id="initialize-instance_method">
|
318
|
+
|
319
|
+
#<strong>initialize</strong>(probability: nil, rate: nil) ⇒ <tt><span class='object_link'><a href="" title="Evolvable::Mutation (class)">Mutation</a></span></tt>
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
</h3><div class="docstring">
|
326
|
+
<div class="discussion">
|
327
|
+
<p>Initializes a new mutation object.</p>
|
328
|
+
|
329
|
+
<p>When rate is specified but probability isn't, probability defaults to 1.0.
|
330
|
+
When rate is 0 or not specified, only one gene is mutated per affected instance.</p>
|
331
|
+
|
332
|
+
|
333
|
+
</div>
|
334
|
+
</div>
|
335
|
+
<div class="tags">
|
336
|
+
|
337
|
+
<div class="examples">
|
338
|
+
<h4 class="tag_title">Examples:</h4>
|
339
|
+
|
340
|
+
|
341
|
+
<h5 class="example_title"><div class='inline'><p>Basic initialization patterns</p>
|
342
|
+
</div></h5>
|
343
|
+
|
344
|
+
<pre class="example code"><code><span class='comment'># Default: 3% of instances get one mutated gene
|
345
|
+
</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="" title="Evolvable::Mutation (class)">Mutation</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
346
|
+
|
347
|
+
<span class='comment'># 50% of instances get one mutated gene
|
348
|
+
</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="" title="Evolvable::Mutation (class)">Mutation</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>probability:</span> <span class='float'>0.5</span><span class='rparen'>)</span>
|
349
|
+
|
350
|
+
<span class='comment'># All instances are considered, with 3% of genes mutating in each
|
351
|
+
</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="" title="Evolvable::Mutation (class)">Mutation</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>rate:</span> <span class='float'>0.03</span><span class='rparen'>)</span>
|
352
|
+
|
353
|
+
<span class='comment'># 30% of instances have 3% of their genes mutated
|
354
|
+
</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="" title="Evolvable::Mutation (class)">Mutation</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='label'>probability:</span> <span class='float'>0.3</span><span class='comma'>,</span> <span class='label'>rate:</span> <span class='float'>0.03</span><span class='rparen'>)</span></code></pre>
|
355
|
+
|
356
|
+
</div>
|
357
|
+
<p class="tag_title">Parameters:</p>
|
358
|
+
<ul class="param">
|
359
|
+
|
360
|
+
<li>
|
361
|
+
|
362
|
+
<span class='name'>probability</span>
|
363
|
+
|
364
|
+
|
365
|
+
<span class='type'>(<tt>Float</tt>, <tt>nil</tt>)</span>
|
366
|
+
|
367
|
+
|
368
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
369
|
+
|
370
|
+
|
371
|
+
—
|
372
|
+
<div class='inline'><p>Chance of an instance being mutated (0.0-1.0)</p>
|
373
|
+
</div>
|
374
|
+
|
375
|
+
</li>
|
376
|
+
|
377
|
+
<li>
|
378
|
+
|
379
|
+
<span class='name'>rate</span>
|
380
|
+
|
381
|
+
|
382
|
+
<span class='type'>(<tt>Float</tt>, <tt>nil</tt>)</span>
|
383
|
+
|
384
|
+
|
385
|
+
<em class="default">(defaults to: <tt>nil</tt>)</em>
|
386
|
+
|
387
|
+
|
388
|
+
—
|
389
|
+
<div class='inline'><p>Chance of each gene mutating when an instance is selected (0.0-1.0)</p>
|
390
|
+
</div>
|
391
|
+
|
392
|
+
</li>
|
393
|
+
|
394
|
+
</ul>
|
395
|
+
|
396
|
+
|
397
|
+
</div><table class="source_code">
|
398
|
+
<tr>
|
399
|
+
<td>
|
400
|
+
<pre class="lines">
|
401
|
+
|
402
|
+
|
403
|
+
60
|
404
|
+
61
|
405
|
+
62
|
406
|
+
63</pre>
|
407
|
+
</td>
|
408
|
+
<td>
|
409
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/mutation.rb', line 60</span>
|
410
|
+
|
411
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='label'>probability:</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='label'>rate:</span> <span class='kw'>nil</span><span class='rparen'>)</span>
|
412
|
+
<span class='ivar'>@probability</span> <span class='op'>=</span> <span class='id identifier rubyid_probability'>probability</span> <span class='op'>||</span> <span class='lparen'>(</span><span class='id identifier rubyid_rate'>rate</span> <span class='op'>?</span> <span class='int'>1</span> <span class='op'>:</span> <span class='const'><span class='object_link'><a href="#DEFAULT_PROBABILITY-constant" title="Evolvable::Mutation::DEFAULT_PROBABILITY (constant)">DEFAULT_PROBABILITY</a></span></span><span class='rparen'>)</span>
|
413
|
+
<span class='ivar'>@rate</span> <span class='op'>=</span> <span class='id identifier rubyid_rate'>rate</span>
|
414
|
+
<span class='kw'>end</span></pre>
|
415
|
+
</td>
|
416
|
+
</tr>
|
417
|
+
</table>
|
418
|
+
</div>
|
419
|
+
|
420
|
+
</div>
|
421
|
+
|
422
|
+
<div id="instance_attr_details" class="attr_details">
|
423
|
+
<h2>Instance Attribute Details</h2>
|
424
|
+
|
425
|
+
|
426
|
+
<span id="probability=-instance_method"></span>
|
427
|
+
<div class="method_details first">
|
428
|
+
<h3 class="signature first" id="probability-instance_method">
|
429
|
+
|
430
|
+
#<strong>probability</strong> ⇒ <tt>Float</tt>
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
</h3><div class="docstring">
|
437
|
+
<div class="discussion">
|
438
|
+
<p>The probability that an evolvable instance will undergo mutation.
|
439
|
+
Value between 0.0 (never) and 1.0 (always).</p>
|
440
|
+
|
441
|
+
|
442
|
+
</div>
|
443
|
+
</div>
|
444
|
+
<div class="tags">
|
445
|
+
|
446
|
+
<p class="tag_title">Returns:</p>
|
447
|
+
<ul class="return">
|
448
|
+
|
449
|
+
<li>
|
450
|
+
|
451
|
+
|
452
|
+
<span class='type'>(<tt>Float</tt>)</span>
|
453
|
+
|
454
|
+
|
455
|
+
|
456
|
+
—
|
457
|
+
<div class='inline'><p>The mutation probability</p>
|
458
|
+
</div>
|
459
|
+
|
460
|
+
</li>
|
461
|
+
|
462
|
+
</ul>
|
463
|
+
|
464
|
+
</div><table class="source_code">
|
465
|
+
<tr>
|
466
|
+
<td>
|
467
|
+
<pre class="lines">
|
468
|
+
|
469
|
+
|
470
|
+
71
|
471
|
+
72
|
472
|
+
73</pre>
|
473
|
+
</td>
|
474
|
+
<td>
|
475
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/mutation.rb', line 71</span>
|
476
|
+
|
477
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_probability'>probability</span>
|
478
|
+
<span class='ivar'>@probability</span>
|
479
|
+
<span class='kw'>end</span></pre>
|
480
|
+
</td>
|
481
|
+
</tr>
|
482
|
+
</table>
|
483
|
+
</div>
|
484
|
+
|
485
|
+
|
486
|
+
<span id="rate=-instance_method"></span>
|
487
|
+
<div class="method_details ">
|
488
|
+
<h3 class="signature " id="rate-instance_method">
|
489
|
+
|
490
|
+
#<strong>rate</strong> ⇒ <tt>Float</tt><sup>?</sup>
|
491
|
+
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
</h3><div class="docstring">
|
497
|
+
<div class="discussion">
|
498
|
+
<p>The rate at which genes mutate within an instance.
|
499
|
+
Value between 0.0 (no genes mutate) and 1.0 (all genes likely to mutate).
|
500
|
+
When nil, exactly one random gene is mutated per instance.</p>
|
501
|
+
|
502
|
+
|
503
|
+
</div>
|
504
|
+
</div>
|
505
|
+
<div class="tags">
|
506
|
+
|
507
|
+
<p class="tag_title">Returns:</p>
|
508
|
+
<ul class="return">
|
509
|
+
|
510
|
+
<li>
|
511
|
+
|
512
|
+
|
513
|
+
<span class='type'>(<tt>Float</tt>, <tt>nil</tt>)</span>
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
—
|
518
|
+
<div class='inline'><p>The mutation rate</p>
|
519
|
+
</div>
|
520
|
+
|
521
|
+
</li>
|
522
|
+
|
523
|
+
</ul>
|
524
|
+
|
525
|
+
</div><table class="source_code">
|
526
|
+
<tr>
|
527
|
+
<td>
|
528
|
+
<pre class="lines">
|
529
|
+
|
530
|
+
|
531
|
+
80
|
532
|
+
81
|
533
|
+
82</pre>
|
534
|
+
</td>
|
535
|
+
<td>
|
536
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/mutation.rb', line 80</span>
|
537
|
+
|
538
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_rate'>rate</span>
|
539
|
+
<span class='ivar'>@rate</span>
|
540
|
+
<span class='kw'>end</span></pre>
|
541
|
+
</td>
|
542
|
+
</tr>
|
543
|
+
</table>
|
544
|
+
</div>
|
545
|
+
|
546
|
+
</div>
|
547
|
+
|
548
|
+
|
549
|
+
<div id="instance_method_details" class="method_details_list">
|
550
|
+
<h2>Instance Method Details</h2>
|
551
|
+
|
552
|
+
|
553
|
+
<div class="method_details first">
|
554
|
+
<h3 class="signature first" id="call-instance_method">
|
555
|
+
|
556
|
+
#<strong>call</strong>(population) ⇒ <tt><span class='object_link'><a href="Population.html" title="Evolvable::Population (class)">Evolvable::Population</a></span></tt>
|
557
|
+
|
558
|
+
|
559
|
+
|
560
|
+
|
561
|
+
|
562
|
+
</h3><div class="docstring">
|
563
|
+
<div class="discussion">
|
564
|
+
<p>Applies mutations to the population's evolvables based on the
|
565
|
+
configured probability and rate.</p>
|
566
|
+
|
567
|
+
|
568
|
+
</div>
|
569
|
+
</div>
|
570
|
+
<div class="tags">
|
571
|
+
<p class="tag_title">Parameters:</p>
|
572
|
+
<ul class="param">
|
573
|
+
|
574
|
+
<li>
|
575
|
+
|
576
|
+
<span class='name'>population</span>
|
577
|
+
|
578
|
+
|
579
|
+
<span class='type'>(<tt><span class='object_link'><a href="Population.html" title="Evolvable::Population (class)">Evolvable::Population</a></span></tt>)</span>
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
—
|
584
|
+
<div class='inline'><p>The population to mutate</p>
|
585
|
+
</div>
|
586
|
+
|
587
|
+
</li>
|
588
|
+
|
589
|
+
</ul>
|
590
|
+
|
591
|
+
<p class="tag_title">Returns:</p>
|
592
|
+
<ul class="return">
|
593
|
+
|
594
|
+
<li>
|
595
|
+
|
596
|
+
|
597
|
+
<span class='type'>(<tt><span class='object_link'><a href="Population.html" title="Evolvable::Population (class)">Evolvable::Population</a></span></tt>)</span>
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
—
|
602
|
+
<div class='inline'><p>The mutated population</p>
|
603
|
+
</div>
|
604
|
+
|
605
|
+
</li>
|
606
|
+
|
607
|
+
</ul>
|
608
|
+
|
609
|
+
</div><table class="source_code">
|
610
|
+
<tr>
|
611
|
+
<td>
|
612
|
+
<pre class="lines">
|
613
|
+
|
614
|
+
|
615
|
+
89
|
616
|
+
90
|
617
|
+
91
|
618
|
+
92</pre>
|
619
|
+
</td>
|
620
|
+
<td>
|
621
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/mutation.rb', line 89</span>
|
622
|
+
|
623
|
+
<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>
|
624
|
+
<span class='id identifier rubyid_mutate_evolvables'>mutate_evolvables</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='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_probability'>probability</span><span class='period'>.</span><span class='id identifier rubyid_zero?'>zero?</span>
|
625
|
+
<span class='id identifier rubyid_population'>population</span>
|
626
|
+
<span class='kw'>end</span></pre>
|
627
|
+
</td>
|
628
|
+
</tr>
|
629
|
+
</table>
|
630
|
+
</div>
|
631
|
+
|
632
|
+
<div class="method_details ">
|
633
|
+
<h3 class="signature " id="mutate_evolvables-instance_method">
|
634
|
+
|
635
|
+
#<strong>mutate_evolvables</strong>(evolvables) ⇒ <tt>Array<<span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span>></tt>
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
|
640
|
+
|
641
|
+
</h3><div class="docstring">
|
642
|
+
<div class="discussion">
|
643
|
+
<p>Mutates a collection of evolvable instances based on the mutation
|
644
|
+
probability and rate.</p>
|
645
|
+
|
646
|
+
|
647
|
+
</div>
|
648
|
+
</div>
|
649
|
+
<div class="tags">
|
650
|
+
<p class="tag_title">Parameters:</p>
|
651
|
+
<ul class="param">
|
652
|
+
|
653
|
+
<li>
|
654
|
+
|
655
|
+
<span class='name'>evolvables</span>
|
656
|
+
|
657
|
+
|
658
|
+
<span class='type'>(<tt>Array<<span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span>></tt>)</span>
|
659
|
+
|
660
|
+
|
661
|
+
|
662
|
+
—
|
663
|
+
<div class='inline'><p>The collection of evolvable instances to potentially mutate</p>
|
664
|
+
</div>
|
665
|
+
|
666
|
+
</li>
|
667
|
+
|
668
|
+
</ul>
|
669
|
+
|
670
|
+
<p class="tag_title">Returns:</p>
|
671
|
+
<ul class="return">
|
672
|
+
|
673
|
+
<li>
|
674
|
+
|
675
|
+
|
676
|
+
<span class='type'>(<tt>Array<<span class='object_link'><a href="../Evolvable.html" title="Evolvable (module)">Evolvable</a></span>></tt>)</span>
|
677
|
+
|
678
|
+
|
679
|
+
|
680
|
+
—
|
681
|
+
<div class='inline'><p>The potentially mutated evolvables</p>
|
682
|
+
</div>
|
683
|
+
|
684
|
+
</li>
|
685
|
+
|
686
|
+
</ul>
|
687
|
+
|
688
|
+
</div><table class="source_code">
|
689
|
+
<tr>
|
690
|
+
<td>
|
691
|
+
<pre class="lines">
|
692
|
+
|
693
|
+
|
694
|
+
101
|
695
|
+
102
|
696
|
+
103
|
697
|
+
104
|
698
|
+
105
|
699
|
+
106
|
700
|
+
107</pre>
|
701
|
+
</td>
|
702
|
+
<td>
|
703
|
+
<pre class="code"><span class="info file"># File 'lib/evolvable/mutation.rb', line 101</span>
|
704
|
+
|
705
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_mutate_evolvables'>mutate_evolvables</span><span class='lparen'>(</span><span class='id identifier rubyid_evolvables'>evolvables</span><span class='rparen'>)</span>
|
706
|
+
<span class='id identifier rubyid_evolvables'>evolvables</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_evolvable'>evolvable</span><span class='op'>|</span>
|
707
|
+
<span class='kw'>next</span> <span class='kw'>unless</span> <span class='id identifier rubyid_rand'>rand</span> <span class='op'><=</span> <span class='id identifier rubyid_probability'>probability</span>
|
708
|
+
|
709
|
+
<span class='id identifier rubyid_evolvable'>evolvable</span><span class='period'>.</span><span class='id identifier rubyid_genome'>genome</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid__key'>_key</span><span class='comma'>,</span> <span class='id identifier rubyid_config'>config</span><span class='op'>|</span> <span class='id identifier rubyid_mutate_genes'>mutate_genes</span><span class='lparen'>(</span><span class='id identifier rubyid_config'>config</span><span class='lbracket'>[</span><span class='symbol'>:genes</span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
710
|
+
<span class='kw'>end</span>
|
711
|
+
<span class='kw'>end</span></pre>
|
712
|
+
</td>
|
713
|
+
</tr>
|
714
|
+
</table>
|
715
|
+
</div>
|
716
|
+
|
717
|
+
</div>
|
718
|
+
|
719
|
+
</div>
|
720
|
+
|
721
|
+
<div id="footer">
|
722
|
+
Generated on Sat May 10 18:39:22 2025 by
|
723
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
724
|
+
0.9.37 (ruby-3.4.2).
|
725
|
+
</div>
|
726
|
+
|
727
|
+
</div>
|
728
|
+
</body>
|
729
|
+
</html>
|