Skip to content

Commit

Permalink
update optimize.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Freakwill committed Jan 1, 2025
1 parent e0772cc commit 940e8ec
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 15 deletions.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/source/Release History.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/source/pyrimidine.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/source/pyrimidine.misc.doctree
Binary file not shown.
1 change: 1 addition & 0 deletions docs/build/html/_sources/source/Release History.md.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v1.7
- update the notations of methods/functions
- update the documents
- Allow the GA optimization function to accept an initial solution. see `examples/example-opt.py`

## v1.6

Expand Down
4 changes: 4 additions & 0 deletions docs/build/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ <h2 id="A">A</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="source/pyrimidine.html#pyrimidine.deco.add_cache">add_cache (class in pyrimidine.deco)</a>
</li>
<li><a href="source/pyrimidine.html#pyrimidine.optimize.add_init_ind">add_init_ind() (in module pyrimidine.optimize)</a>
</li>
<li><a href="source/pyrimidine.html#pyrimidine.deco.add_memory">add_memory (class in pyrimidine.deco)</a>
</li>
Expand Down Expand Up @@ -792,6 +794,8 @@ <h2 id="E">E</h2>
</li>
</ul></li>
<li><a href="source/pyrimidine.html#pyrimidine.population.EliminationPopulation">EliminationPopulation (class in pyrimidine.population)</a>
</li>
<li><a href="source/pyrimidine.html#pyrimidine.base.BaseChromosome.encode">encode() (pyrimidine.base.BaseChromosome class method)</a>
</li>
<li><a href="source/pyrimidine.html#pyrimidine.base.BaseChromosome.equal_to">equal_to() (pyrimidine.base.BaseChromosome method)</a>
</li>
Expand Down
Binary file modified docs/build/html/objects.inv
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/build/html/searchindex.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions docs/build/html/source/Release History.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="API Design" href="API%20Design.html" />
<link rel="prev" title="Installation and Getting Started" href="Install.html" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Neuton&amp;subset=latin" type="text/css" media="screen" charset="utf-8" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Nobile:regular,italic,bold,bolditalic&amp;subset=latin" type="text/css" media="screen" charset="utf-8" />
<!--[if lte IE 6]>
Expand All @@ -30,7 +32,14 @@ <h3>Navigation</h3>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="API%20Design.html" title="API Design"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="Install.html" title="Installation and Getting Started"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">pyrimidine 1.7 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Document of <cite>pyrimidine</cite></a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Release History</a></li>
</ul>
</div>
Expand All @@ -47,6 +56,7 @@ <h2>v1.7<a class="headerlink" href="#v1-7" title="Link to this heading">¶</a></
<ul class="simple">
<li><p>update the notations of methods/functions</p></li>
<li><p>update the documents</p></li>
<li><p>Allow the GA optimization function to accept an initial solution. see <code class="docutils literal notranslate"><span class="pre">examples/example-opt.py</span></code></p></li>
</ul>
</section>
<section id="v1-6">
Expand Down Expand Up @@ -95,6 +105,16 @@ <h3><a href="../index.html">Table of Contents</a></h3>
</ul>

</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="Install.html"
title="previous chapter">Installation and Getting Started</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="API%20Design.html"
title="next chapter">API Design</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
Expand Down Expand Up @@ -125,7 +145,14 @@ <h3>Navigation</h3>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="API%20Design.html" title="API Design"
>next</a> |</li>
<li class="right" >
<a href="Install.html" title="Installation and Getting Started"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">pyrimidine 1.7 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" >Document of <cite>pyrimidine</cite></a> &#187;</li>
<li class="nav-item nav-item-this"><a href="">Release History</a></li>
</ul>
</div>
Expand Down
22 changes: 19 additions & 3 deletions docs/build/html/source/pyrimidine.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ <h1>pyrimidine package<a class="headerlink" href="#pyrimidine-package" title="Li
<dd><p>alias of <a class="reference internal" href="#pyrimidine.base.BaseGene" title="pyrimidine.base.BaseGene"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseGene</span></code></a></p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="pyrimidine.base.BaseChromosome.encode">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">encode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">sol</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.base.BaseChromosome.encode" title="Link to this definition">¶</a></dt>
<dd><p>Encoding to the chromesome, as inverse of <cite>decode</cite></p>
<p>Transform the solution (e.g. a number) to the chromesome.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="pyrimidine.base.BaseChromosome.equal_to">
<span class="sig-name descname"><span class="pre">equal_to</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.base.BaseChromosome.equal_to" title="Link to this definition">¶</a></dt>
Expand Down Expand Up @@ -3322,9 +3329,14 @@ <h1>pyrimidine package<a class="headerlink" href="#pyrimidine-package" title="Li

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="pyrimidine.optimize.add_init_ind">
<span class="sig-prename descclassname"><span class="pre">pyrimidine.optimize.</span></span><span class="sig-name descname"><span class="pre">add_init_ind</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">cls</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">init_ind</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.optimize.add_init_ind" title="Link to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="pyrimidine.optimize.de_minimize">
<span class="sig-prename descclassname"><span class="pre">pyrimidine.optimize.</span></span><span class="sig-name descname"><span class="pre">de_minimize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">*xlim</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">decode=&lt;function</span> <span class="pre">_decode&gt;</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">population_size=20</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size=8</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.optimize.de_minimize" title="Link to this definition">¶</a></dt>
<span class="sig-prename descclassname"><span class="pre">pyrimidine.optimize.</span></span><span class="sig-name descname"><span class="pre">de_minimize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">*xlim</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">decode=&lt;function</span> <span class="pre">_decode&gt;</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">population_size=20</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size=8</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">init_x=None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.optimize.de_minimize" title="Link to this definition">¶</a></dt>
<dd><p>DE for minimizing the function <cite>func</cite> defined on <cite>xlim</cite></p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
Expand All @@ -3344,7 +3356,7 @@ <h1>pyrimidine package<a class="headerlink" href="#pyrimidine-package" title="Li

<dl class="py function">
<dt class="sig sig-object py" id="pyrimidine.optimize.ga_minimize">
<span class="sig-prename descclassname"><span class="pre">pyrimidine.optimize.</span></span><span class="sig-name descname"><span class="pre">ga_minimize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">*xlim</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">decode=&lt;function</span> <span class="pre">_decode&gt;</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">population_size=20</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size=8</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.optimize.ga_minimize" title="Link to this definition">¶</a></dt>
<span class="sig-prename descclassname"><span class="pre">pyrimidine.optimize.</span></span><span class="sig-name descname"><span class="pre">ga_minimize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">*xlim</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">decode=&lt;function</span> <span class="pre">_decode&gt;</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">population_size=20</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size=8</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">init_x=None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.optimize.ga_minimize" title="Link to this definition">¶</a></dt>
<dd><p>GA(with hall of fame) for minimizing the function <cite>func</cite> defined on <cite>xlim</cite></p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
Expand All @@ -3355,6 +3367,7 @@ <h1>pyrimidine package<a class="headerlink" href="#pyrimidine-package" title="Li
(‘0-1’ sequence, lower_bound, upper_bound) mapsto xi</p></li>
<li><p><strong>{int}</strong> (<em>population_size</em>) – size of the population</p></li>
<li><p><strong>int}</strong> (<em>size {int</em><em> or </em><em>tuple of</em>) – the length of the encoding of xi</p></li>
<li><p><strong>init_x</strong> – the initial solution</p></li>
</ul>
</dd>
</dl>
Expand All @@ -3364,7 +3377,7 @@ <h1>pyrimidine package<a class="headerlink" href="#pyrimidine-package" title="Li

<dl class="py function">
<dt class="sig sig-object py" id="pyrimidine.optimize.ga_minimize_1d">
<span class="sig-prename descclassname"><span class="pre">pyrimidine.optimize.</span></span><span class="sig-name descname"><span class="pre">ga_minimize_1d</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xlim</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">decode=&lt;function</span> <span class="pre">_decode&gt;</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">population_size=20</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size=8</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">*args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.optimize.ga_minimize_1d" title="Link to this definition">¶</a></dt>
<span class="sig-prename descclassname"><span class="pre">pyrimidine.optimize.</span></span><span class="sig-name descname"><span class="pre">ga_minimize_1d</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">xlim</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">decode=&lt;function</span> <span class="pre">_decode&gt;</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">population_size=20</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">size=8</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">init_x=None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">*args</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">**kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.optimize.ga_minimize_1d" title="Link to this definition">¶</a></dt>
<dd><p>GA(with hall of fame) for minimizing 1D function <cite>func</cite> defined on the interval <cite>xlim</cite></p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
Expand Down Expand Up @@ -4346,6 +4359,7 @@ <h1>pyrimidine package<a class="headerlink" href="#pyrimidine-package" title="Li
</section>
<section id="module-pyrimidine.qga">
<span id="pyrimidine-qga-module"></span><h2>pyrimidine.qga module<a class="headerlink" href="#module-pyrimidine.qga" title="Link to this heading">¶</a></h2>
<p>Quantum GA</p>
<dl class="py class">
<dt class="sig sig-object py" id="pyrimidine.qga.QuantumPopulation">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pyrimidine.qga.</span></span><span class="sig-name descname"><span class="pre">QuantumPopulation</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.qga.QuantumPopulation" title="Link to this definition">¶</a></dt>
Expand Down Expand Up @@ -5001,6 +5015,7 @@ <h3><a href="../index.html">Table of Contents</a></h3>
<li><a class="reference internal" href="#pyrimidine.base.BaseChromosome.decode"><code class="docutils literal notranslate"><span class="pre">BaseChromosome.decode()</span></code></a></li>
<li><a class="reference internal" href="#id0"><code class="docutils literal notranslate"><span class="pre">BaseChromosome.default_size</span></code></a></li>
<li><a class="reference internal" href="#id7"><code class="docutils literal notranslate"><span class="pre">BaseChromosome.element_class</span></code></a></li>
<li><a class="reference internal" href="#pyrimidine.base.BaseChromosome.encode"><code class="docutils literal notranslate"><span class="pre">BaseChromosome.encode()</span></code></a></li>
<li><a class="reference internal" href="#pyrimidine.base.BaseChromosome.equal_to"><code class="docutils literal notranslate"><span class="pre">BaseChromosome.equal_to()</span></code></a></li>
<li><a class="reference internal" href="#pyrimidine.base.BaseChromosome.mutate"><code class="docutils literal notranslate"><span class="pre">BaseChromosome.mutate()</span></code></a></li>
<li><a class="reference internal" href="#pyrimidine.base.BaseChromosome.params"><code class="docutils literal notranslate"><span class="pre">BaseChromosome.params</span></code></a></li>
Expand Down Expand Up @@ -5588,6 +5603,7 @@ <h3><a href="../index.html">Table of Contents</a></h3>
<li><a class="reference internal" href="#pyrimidine.optimize.Optimizer.Population"><code class="docutils literal notranslate"><span class="pre">Optimizer.Population</span></code></a></li>
</ul>
</li>
<li><a class="reference internal" href="#pyrimidine.optimize.add_init_ind"><code class="docutils literal notranslate"><span class="pre">add_init_ind()</span></code></a></li>
<li><a class="reference internal" href="#pyrimidine.optimize.de_minimize"><code class="docutils literal notranslate"><span class="pre">de_minimize()</span></code></a></li>
<li><a class="reference internal" href="#pyrimidine.optimize.ga_minimize"><code class="docutils literal notranslate"><span class="pre">ga_minimize()</span></code></a></li>
<li><a class="reference internal" href="#pyrimidine.optimize.ga_minimize_1d"><code class="docutils literal notranslate"><span class="pre">ga_minimize_1d()</span></code></a></li>
Expand Down
2 changes: 2 additions & 0 deletions docs/build/html/source/pyrimidine.misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ <h1>pyrimidine.misc subpackage<a class="headerlink" href="#pyrimidine-misc-subpa
<dt class="sig sig-object py" id="pyrimidine.misc.ba.Bat">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pyrimidine.misc.ba.</span></span><span class="sig-name descname"><span class="pre">Bat</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#pyrimidine.misc.ba.Bat" title="Link to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="pyrimidine.html#pyrimidine.pso.BaseParticle" title="pyrimidine.pso.BaseParticle"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseParticle</span></code></a></p>
<p>a bat is regarded as a particle</p>
<p>see <cite>BaseParticle</cite></p>
<dl class="py attribute">
<dt class="sig sig-object py" id="pyrimidine.misc.ba.Bat.alias">
<span class="sig-name descname"><span class="pre">alias</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">{'chromosomes':</span> <span class="pre">'elements',</span> <span class="pre">'n_chromosomes':</span> <span class="pre">'n_elements'}</span></em><a class="headerlink" href="#pyrimidine.misc.ba.Bat.alias" title="Link to this definition"></a></dt>
Expand Down
3 changes: 2 additions & 1 deletion docs/source/Release History.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Release History

## v1.7
## v1.7+
- update the notations of methods/functions
- update the documents
- Allow the GA optimization function to accept an initial solution. see `examples/example-opt.py`

## v1.6

Expand Down
6 changes: 5 additions & 1 deletion examples/example-opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@
min x1^2 + x2
x1, x2 in [-1, 1]
"""
solution = optimize.ga_min(lambda x:x[0]**2+x[1], (-1,1), (-1,1))
solution = optimize.ga_minimize(lambda x:x[0]**2+x[1], (-1,1), (-1,1))
print(solution)


solution = optimize.ga_minimize(lambda x:x[0]**2+x[1], (-1,1), (-1,1), init_x=[0.5,0])
print(solution)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyrimidine"
version = "1.7"
version = "1.7.1"
description = "A competitive framework for GA, designed by thorough OOP"
authors = ["William Song <[email protected]>"]

Expand Down
2 changes: 1 addition & 1 deletion pyrimidine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .de import *


__version__ = "1.6.1"
__version__ = "1.7.1"

__template__ = """
from pyrimidine.chromosome import BinaryChromosome
Expand Down
Loading

0 comments on commit 940e8ec

Please sign in to comment.