Skip to content

Commit 9fca978

Browse files
committed
Updated docs.
1 parent 68cc425 commit 9fca978

23 files changed

+252
-161
lines changed
1.69 KB
Binary file not shown.
0 Bytes
Binary file not shown.
-871 Bytes
Binary file not shown.
-101 Bytes
Binary file not shown.
-3 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
239 Bytes
Binary file not shown.

docs/_build/html/_modules/pygenalgo/engines/island_model_ga.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ <h1>Source code for pygenalgo.engines.island_model_ga</h1><div class="highlight"
230230
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">epochs</span><span class="p">):</span>
231231

232232
<span class="c1"># Update current iteration in the selection operator.</span>
233-
<span class="c1"># Currently this is used only from Boltzmann Selector.</span>
233+
<span class="c1"># Currently, this is used only from Boltzmann Selector.</span>
234234
<span class="n">sel_op</span><span class="o">.</span><span class="n">iter</span> <span class="o">=</span> <span class="n">i</span>
235235

236236
<span class="c1"># SELECT the parents.</span>
@@ -259,16 +259,16 @@ <h1>Source code for pygenalgo.engines.island_model_ga</h1><div class="highlight"
259259
<span class="c1"># Check if &#39;elitism&#39; is enabled.</span>
260260
<span class="k">if</span> <span class="n">elitism</span><span class="p">:</span>
261261

262-
<span class="c1"># Find the individual chromosome with the highest fitness value</span>
263-
<span class="c1"># (from the old population).</span>
262+
<span class="c1"># Find the individual chromosome with the highest fitness</span>
263+
<span class="c1"># value (from the old subpopulation of the current island).</span>
264264
<span class="n">best_chromosome</span> <span class="o">=</span> <span class="nb">max</span><span class="p">((</span><span class="n">p</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">island</span><span class="o">.</span><span class="n">population</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">isnan</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">fitness</span><span class="p">)),</span>
265265
<span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">c</span><span class="p">:</span> <span class="n">c</span><span class="o">.</span><span class="n">fitness</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
266266

267267
<span class="c1"># Select randomly a position.</span>
268268
<span class="n">locus</span> <span class="o">=</span> <span class="n">rnd_gen</span><span class="o">.</span><span class="n">integers</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
269269

270270
<span class="c1"># Replace the chromosome with the previous best.</span>
271-
<span class="n">population_i</span><span class="p">[</span><span class="n">locus</span><span class="p">]</span> <span class="o">=</span> <span class="n">best_chromosome</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span>
271+
<span class="n">population_i</span><span class="p">[</span><span class="n">locus</span><span class="p">]</span> <span class="o">=</span> <span class="n">best_chromosome</span>
272272
<span class="c1"># _end_if_</span>
273273

274274
<span class="c1"># EVALUATE the i-th population.</span>

docs/_build/html/_modules/pygenalgo/engines/standard_ga.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ <h1>Source code for pygenalgo.engines.standard_ga</h1><div class="highlight"><pr
243243
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">epochs</span><span class="p">):</span>
244244

245245
<span class="c1"># Update current iteration in the selection operator.</span>
246-
<span class="c1"># Currently this is used only from Boltzmann Selector.</span>
246+
<span class="c1"># Currently, this is used only from Boltzmann Selector.</span>
247247
<span class="bp">self</span><span class="o">.</span><span class="n">_select_op</span><span class="o">.</span><span class="n">iter</span> <span class="o">=</span> <span class="n">i</span>
248248

249249
<span class="c1"># SELECT the parents.</span>
@@ -271,22 +271,18 @@ <h1>Source code for pygenalgo.engines.standard_ga</h1><div class="highlight"><pr
271271

272272
<span class="c1"># Print only if there were corrections,</span>
273273
<span class="c1"># to avoid cluttering the screen.</span>
274-
<span class="k">if</span> <span class="n">total_corrections</span><span class="p">:</span>
274+
<span class="k">if</span> <span class="n">verbose</span> <span class="ow">and</span> <span class="n">total_corrections</span><span class="p">:</span>
275275
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;&gt; </span><span class="si">{</span><span class="n">total_corrections</span><span class="si">}</span><span class="s2"> correction(s) took place at epoch: </span><span class="si">{</span><span class="n">i</span><span class="si">}</span><span class="s2">.&quot;</span><span class="p">)</span>
276276
<span class="c1"># _end_if_</span>
277277
<span class="c1"># _end_if_</span>
278278

279279
<span class="c1"># Check if &#39;elitism&#39; is enabled.</span>
280280
<span class="k">if</span> <span class="n">elitism</span><span class="p">:</span>
281-
<span class="c1"># Find the individual chromosome with the highest</span>
282-
<span class="c1"># fitness value (from the previous population).</span>
283-
<span class="n">best_chromosome</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">best_chromosome</span><span class="p">()</span>
284-
285281
<span class="c1"># Select randomly a position.</span>
286282
<span class="n">locus</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rng_GA</span><span class="o">.</span><span class="n">integers</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">N</span><span class="p">)</span>
287283

288284
<span class="c1"># Replace the chromosome with the previous best.</span>
289-
<span class="n">population_i</span><span class="p">[</span><span class="n">locus</span><span class="p">]</span> <span class="o">=</span> <span class="n">best_chromosome</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span>
285+
<span class="n">population_i</span><span class="p">[</span><span class="n">locus</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">best_chromosome</span><span class="p">()</span>
290286
<span class="c1"># _end_if_</span>
291287

292288
<span class="c1"># Calculate the new fitness values.</span>

docs/_build/html/_modules/pygenalgo/genome/chromosome.html

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,55 @@ <h1>Source code for pygenalgo.genome.chromosome</h1><div class="highlight"><pre>
253253
<span class="c1"># _end_if_</span>
254254

255255
<span class="c1"># Compute the dissimilarities in their genomes.</span>
256-
<span class="k">return</span> <span class="nb">sum</span><span class="p">([</span><span class="n">k</span> <span class="o">!=</span> <span class="n">l</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">l</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_genome</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">_genome</span><span class="p">,</span> <span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">)])</span>
256+
<span class="k">return</span> <span class="p">[</span><span class="n">k</span> <span class="o">!=</span> <span class="n">l</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">l</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_genome</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">_genome</span><span class="p">,</span>
257+
<span class="n">strict</span><span class="o">=</span><span class="kc">True</span><span class="p">)]</span><span class="o">.</span><span class="n">count</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
257258
<span class="k">else</span><span class="p">:</span>
258259
<span class="k">raise</span> <span class="bp">NotImplemented</span></div>
259260

260261
<span class="c1"># _end_if_</span>
261262

262263
<span class="c1"># _end_def_</span>
263264

265+
<span class="k">def</span> <span class="nf">__deepcopy__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">memo</span><span class="p">):</span>
266+
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
267+
<span class="sd"> This custom method overrides the default deepcopy method</span>
268+
<span class="sd"> and is used when we call the &quot;clone&quot; method of the class.</span>
269+
270+
<span class="sd"> :param memo: dictionary of objects already copied during</span>
271+
<span class="sd"> the current copying pass.</span>
272+
273+
<span class="sd"> :return: a new identical &quot;clone&quot; of the self object.</span>
274+
<span class="sd"> &quot;&quot;&quot;</span>
275+
<span class="c1"># Get the class of the object.</span>
276+
<span class="bp">cls</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__class__</span>
277+
278+
<span class="c1"># Create a new instance.</span>
279+
<span class="n">new_object</span> <span class="o">=</span> <span class="bp">cls</span><span class="o">.</span><span class="fm">__new__</span><span class="p">(</span><span class="bp">cls</span><span class="p">)</span>
280+
281+
<span class="c1"># Don&#39;t copy self reference.</span>
282+
<span class="n">memo</span><span class="p">[</span><span class="nb">id</span><span class="p">(</span><span class="bp">self</span><span class="p">)]</span> <span class="o">=</span> <span class="n">new_object</span>
283+
284+
<span class="c1"># Don&#39;t copy the cache.</span>
285+
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s2">&quot;_cache&quot;</span><span class="p">):</span>
286+
<span class="n">memo</span><span class="p">[</span><span class="nb">id</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">)]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="fm">__new__</span><span class="p">(</span><span class="nb">dict</span><span class="p">)</span>
287+
<span class="c1"># _end_if_</span>
288+
289+
<span class="c1"># Deep copy all other attributes.</span>
290+
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
291+
<span class="nb">setattr</span><span class="p">(</span><span class="n">new_object</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">deepcopy</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">memo</span><span class="p">))</span>
292+
<span class="c1"># _end_for_</span>
293+
294+
<span class="c1"># Return identical instance.</span>
295+
<span class="k">return</span> <span class="n">new_object</span>
296+
<span class="c1"># _end_def_</span>
297+
264298
<div class="viewcode-block" id="Chromosome.clone">
265299
<a class="viewcode-back" href="../../../pygenalgo.genome.html#pygenalgo.genome.chromosome.Chromosome.clone">[docs]</a>
266300
<span class="k">def</span> <span class="nf">clone</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
267301
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
268302
<span class="sd"> Makes a duplicate of the self object.</span>
269303

270-
<span class="sd"> :return: a &#39;deep-copy&#39; of the object.</span>
304+
<span class="sd"> :return: a &quot;deep-copy&quot; of the object.</span>
271305
<span class="sd"> &quot;&quot;&quot;</span>
272306
<span class="k">return</span> <span class="n">deepcopy</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>
273307
</div>

0 commit comments

Comments
 (0)