Skip to content

Commit

Permalink
heat and simple text
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingWorkshop committed Jan 3, 2024
1 parent 2243334 commit f750815
Show file tree
Hide file tree
Showing 21 changed files with 629 additions and 32 deletions.
45 changes: 24 additions & 21 deletions demos/hot_dino.ipynb

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file added docs/build/doctrees/heat_example.doctree
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,26 @@ <h1>dynadojo.systems.heat.HeatEquation<a class="headerlink" href="#dynadojo-syst
<p><a class="reference external" href="https://levelup.gitconnected.com/solving-2d-heat-equation-numerically-using-python-3334004aa01a">https://levelup.gitconnected.com/solving-2d-heat-equation-numerically-using-python-3334004aa01a</a></p>
</aside>
</aside>
<p class="rubric">Example</p>
<p>You can download the source image <a class="reference external" href="https://github.com/FlyingWorkshop/dynadojo/blob/main/graphics/dino.png">here</a>.</p>
<img alt="../_images/bw_dino.png" src="../_images/bw_dino.png" />
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">dynadojo.systems.heat</span> <span class="kn">import</span> <span class="n">HeatEquation</span>
<span class="kn">from</span> <span class="nn">dynadojo.wrappers</span> <span class="kn">import</span> <span class="n">SystemChecker</span>
<span class="kn">from</span> <span class="nn">dynadojo.utils.heat</span> <span class="kn">import</span> <span class="n">plot</span>

<span class="c1"># Create the init conds from the image</span>
<span class="n">x0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">expand_dims</span><span class="p">(</span><span class="n">dino</span><span class="o">.</span><span class="n">flatten</span><span class="p">()[::</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">x0</span> <span class="o">*=</span> <span class="mi">2</span>

<span class="n">n</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">timesteps</span> <span class="o">=</span> <span class="mi">20</span>
<span class="n">embed_dim</span> <span class="o">=</span> <span class="n">latent_dim</span>
<span class="n">system</span> <span class="o">=</span> <span class="n">SystemChecker</span><span class="p">(</span><span class="n">HeatEquation</span><span class="p">(</span><span class="n">latent_dim</span><span class="p">,</span> <span class="n">embed_dim</span><span class="p">,</span> <span class="n">noise_scale</span><span class="o">=</span><span class="mi">0</span><span class="p">))</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">system</span><span class="o">.</span><span class="n">make_data</span><span class="p">(</span><span class="n">x0</span><span class="p">,</span> <span class="n">timesteps</span><span class="o">=</span><span class="n">timesteps</span><span class="p">)</span>
<span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">timesteps</span><span class="p">,</span> <span class="n">system</span><span class="o">.</span><span class="n">_system</span><span class="o">.</span><span class="n">dt</span><span class="p">,</span> <span class="n">savefile</span><span class="o">=</span><span class="s2">&quot;../graphics/hot_dino.gif&quot;</span><span class="p">)</span>
</pre></div>
</div>
<img alt="../_images/hot_dino.gif" src="../_images/hot_dino.gif" />
<p class="rubric">Methods</p>
<div class="table-wrapper autosummary longtable docutils container">
<table class="autosummary longtable docutils align-default">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,18 @@ <h1>dynadojo.systems.utils.simple.SimpleSystem<a class="headerlink" href="#dynad
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>latent_dim</strong> (<em>int</em>) – Dimension of the latent space.</p></li>
<li><p><strong>embed_dim</strong> (<em>int</em>) – Embedded dimension of the system.</p></li>
<li><p><strong>latent_dim</strong> (<em>int</em><em>, </em><em>optional</em>) – Dimension of the latent space.</p></li>
<li><p><strong>embed_dim</strong> (<em>int</em><em>, </em><em>optional</em>) – Embedded dimension of the system.</p></li>
<li><p><strong>seed</strong> (<em>int</em><em> or </em><em>None</em><em>, </em><em>optional</em>) – Seed for random number generation.</p></li>
<li><p><strong>embedder_sv_range</strong> (<em>tuple</em>) – The singular value range for the embedder matrix. Singular values are non-negative by convention.
<li><p><strong>embedder_sv_range</strong> (<em>tuple</em><em>, </em><em>optional</em>) – The singular value range for the embedder matrix. Singular values are non-negative by convention.
The singular values should exclude 0 to ensure the embedder is invertible.</p></li>
<li><p><strong>controller_sv_range</strong> (<em>tuple</em>) – The singular value range for the controller matrix.</p></li>
<li><p><strong>IND_range</strong> (<em>tuple</em>) – The in-distribution initial condition range.</p></li>
<li><p><strong>controller_sv_range</strong> (<em>tuple</em><em>, </em><em>optional</em>) – The singular value range for the controller matrix.</p></li>
<li><p><strong>IND_range</strong> (<em>tuple</em><em>, </em><em>optional</em>) – The in-distribution initial condition range.</p></li>
<li><p><strong>OOD_Range</strong> (<em>tuple</em>) – The out-of-distribution initial condition range.</p></li>
<li><p><strong>t_range</strong> (<em>tuple</em><em>, </em><em>optional</em>) – The interval over which to generate the solution trajectories. For example, if <a href="#id1"><span class="problematic" id="id2">:py:`t_range = (0, 1)`</span></a> and <a class="reference internal" href="#dynadojo.systems.utils.simple.SimpleSystem.make_data" title="dynadojo.systems.utils.simple.SimpleSystem.make_data"><code class="xref py py-func docutils literal notranslate"><span class="pre">make_data()</span></code></a>
were called with <a href="#id3"><span class="problematic" id="id4">:py:`timesteps = 10`</span></a>, then the trajectory would be generated with 10 timesteps between 0 and 1.</p></li>
<li><p><strong>noise_scale</strong> (<em>float</em><em>, </em><em>optional</em>) – Normal noise is added per timestep to a solution. Standard deviation (spread or “width”) of the distribution.
Must be non-negative.</p></li>
<li><p><strong>**kwargs</strong> – Additional keyword arguments.</p></li>
</ul>
</dd>
Expand Down
Binary file added docs/build/html/_images/bw_dino.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/build/html/_images/hot_dino.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/build/html/_images/santi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions docs/build/html/_sources/heat_example.rst.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
You can download the source image `here <https://github.com/FlyingWorkshop/dynadojo/blob/main/graphics/dino.png>`_.

.. code:: python
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
def grayscale(png_path, basewidth=30):
image = Image.open(png_path)
wpercent = (basewidth / float(image.size[0]))
hsize = int((float(image.size[1]) * float(wpercent)))
image = image.resize((basewidth,hsize), Image.Resampling.LANCZOS)
grayscale_image = image.convert("L")
grey = np.array(grayscale_image)
return grey
dino = grayscale("../graphics/dino.png")
print(dino.shape)
latent_dim = dino.shape[0] ** 2
plt.imshow(dino, cmap='gray')
plt.axis('off') # Turn off axis labels and ticks
plt.show()
.. image:: ../_images/bw_dino.png

.. code:: python
from dynadojo.systems.heat import HeatEquation
from dynadojo.wrappers import SystemChecker
from dynadojo.utils.heat import plot
# Create the init conds from the image
x0 = np.expand_dims(dino.flatten()[::-1], axis=0)
x0 *= 2
n = 1
timesteps = 20
embed_dim = latent_dim
system = SystemChecker(HeatEquation(latent_dim, embed_dim, noise_scale=0))
x = system.make_data(x0, timesteps=timesteps)
plot(x[0], timesteps, system._system.dt, savefile="../graphics/hot_dino.gif")
.. image:: ../_images/hot_dino.gif
Loading

0 comments on commit f750815

Please sign in to comment.