Skip to content

Commit 9232f9a

Browse files
authored
Merge pull request #176 from TeaspoonTDA/test_release
Test release
2 parents ccd1327 + 9c87311 commit 9232f9a

File tree

180 files changed

+4981
-16677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

180 files changed

+4981
-16677
lines changed

doc_source/modules/SP/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ The signal processing module include various methods of analyzing a time series.
1313
Information Module <information.rst>
1414
Miscellaneous <misc.rst>
1515
Texture Analysis <texture_analysis.rst>
16-
Stochastic P-Bifurcation Detection <stoch_bif.md>
16+
Stochastic P-Bifurcation Detection <stoch_bif.md>
17+
Parameter Path Optimization <parameter_path_opt.rst>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
3+
Parameter Path Optimization
4+
=========================================================
5+
6+
This page contains the necessary functions for performing dynamical system parameter space optimization and allows for obtaining a path in the parameter space to minimize a defined loss function in terms of functions of persistence.
7+
8+
9+
.. automodule:: teaspoon.SP.parameter_path_opt
10+
:members:
11+
12+
**Example**::
13+
14+
import torch
15+
from torchdiffeq import odeint
16+
from torch.optim.lr_scheduler import LambdaLR
17+
from teaspoon.SP.parameter_path_opt import PathOptimizer
18+
from IPython.display import clear_output
19+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
20+
21+
# Set bounds for the parameters
22+
x_min = 80
23+
x_max = 300
24+
y_min = 4
25+
y_max = 50
26+
27+
# Define the system of ODEs using PyTorch
28+
class LorenzSystem(torch.nn.Module):
29+
def __init__(self, params):
30+
super().__init__()
31+
self.params = torch.nn.Parameter(params)
32+
33+
def forward(self, t, state):
34+
x, y, z = state
35+
rho, sigma = self.params
36+
dxdt = sigma * (y - x)
37+
dydt = x * (rho - z) - y
38+
dzdt = x * y - (8.0/3.0) * z
39+
return torch.stack([dxdt, dydt, dzdt])
40+
41+
# Time settings
42+
t_main = torch.linspace(0, 10, 1000, device=device, dtype=torch.float64) # Main simulation
43+
44+
# Initial conditions
45+
x0 = torch.tensor([1.0, 1.0, 1.0], requires_grad=True, device=device, dtype=torch.float64)
46+
47+
# Combine parameters into a single vector
48+
params = torch.nn.Parameter(torch.tensor([190.0, 20.0], device=device))
49+
50+
# Instantiate the system with the combined parameter vector
51+
lorenz = LorenzSystem(params).to(device)
52+
53+
# Initialize optimizer and learning rate scheduler
54+
optimizer = torch.optim.Adam([lorenz.params], lr=1.0)
55+
scheduler = LambdaLR(optimizer, lr_lambda=lambda epoch: 0.995**epoch)
56+
57+
# Initialize lists for saving the path and losses
58+
path = [[lorenz.params[0].item(), lorenz.params[1].item()]]
59+
losses = []
60+
61+
62+
# Define the forbidden regions for the parameter path
63+
forbidden_regions = [
64+
lambda params, pd1: (params[0] - x_max),
65+
lambda params, pd1: -(params[0] - x_min),
66+
lambda params, pd1: (params[1] - y_max),
67+
lambda params, pd1: -(params[1] - y_min),
68+
lambda params, pd1: -((1/400)*(params[0]-190)**2+(1/25)*(params[1]-10)**2 - 1.0), # Example constraint: unit disk of radius 5 centered at (190, 27)
69+
]
70+
71+
# Initialize the PathOptimizer with the Lorenz system and forbidden regions
72+
p_opt = PathOptimizer({
73+
'maxPers': -1}, forbidden_regions=forbidden_regions)
74+
75+
76+
for epoch in range(5):
77+
# Perform the optimization step
78+
y, pd1, loss, grads = p_opt.optimize(lorenz, x0, t_main, optimizer, scheduler)
79+
80+
# Extract the gradients with resspect to the parameters
81+
d_rho, d_sigma = grads[0], grads[1]
82+
83+
# Print result of optimization step
84+
clear_output(wait=True)
85+
print(f"d(Loss)/d(sigma): {d_sigma.item():.5}")
86+
print(f"d(Loss)/d(rho): {d_rho.item():.5}")
87+
print(f"Loss: {loss.item():.8}")
88+
print(f"Rho: {lorenz.params[0].item():.8} -- Sigma: {lorenz.params[1].item():.8}")
89+
90+
# Save the path and the loss
91+
path.append([lorenz.params[0].item(), lorenz.params[1].item()])
92+
losses.append(loss.item())
93+
94+
Output of example (first step of optimization)
95+
96+
::
97+
98+
d(Loss)/d(sigma): 0.97641
99+
d(Loss)/d(rho): 0.21593
100+
Loss: -1.0
101+
Rho: 189.0 -- Sigma: 19.0
102+
103+
.. note::
104+
Results may vary depending on the operating system for chaotic dynamics. The result shown is for demonstration purposes only.

docs/.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: 57959a0acaf4fa6441a0088b37c57423
3+
config: 14c0d7c06b21106d06dd8ce8198cd514
44
tags: 645f666f9bcd5a90fca523b33c5a78b7

docs/_modules/index.html

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<!DOCTYPE html>
2-
<html class="writer-html5" lang="en" >
2+
<html class="writer-html5" lang="en" data-content_root="../">
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Overview: module code &mdash; teaspoon 1.3.7 documentation</title>
7-
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
8-
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
9-
<link rel="stylesheet" href="../_static/plot_directive.css" type="text/css" />
7+
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
8+
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
9+
<link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
10+
11+
1012
<!--[if lt IE 9]>
1113
<script src="../_static/js/html5shiv.min.js"></script>
1214
<![endif]-->
1315

14-
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
15-
<script src="../_static/jquery.js"></script>
16-
<script src="../_static/underscore.js"></script>
17-
<script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
18-
<script src="../_static/doctools.js"></script>
19-
<script src="../_static/sphinx_highlight.js"></script>
16+
<script src="../_static/jquery.js?v=5d32c60e"></script>
17+
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
18+
<script src="../_static/documentation_options.js?v=d4a0791e"></script>
19+
<script src="../_static/doctools.js?v=9a2dae69"></script>
20+
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
2021
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
2122
<script src="../_static/js/theme.js"></script>
2223
<link rel="index" title="Index" href="../genindex.html" />
@@ -28,12 +29,16 @@
2829
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
2930
<div class="wy-side-scroll">
3031
<div class="wy-side-nav-search" style="background: white" >
31-
<a href="../index.html" class="icon icon-home"> teaspoon
32-
<img src="../_static/teaspoon.png" class="logo" alt="Logo"/>
32+
33+
34+
35+
<a href="../index.html" class="icon icon-home">
36+
teaspoon
37+
<img src="../_static/teaspoon.png" class="logo" alt="Logo"/>
3338
</a>
3439
<div role="search">
3540
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
36-
<input type="text" name="q" placeholder="Search docs" />
41+
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
3742
<input type="hidden" name="check_keywords" value="yes" />
3843
<input type="hidden" name="area" value="default" />
3944
</form>
@@ -68,6 +73,7 @@
6873
<li class="toctree-l3"><a class="reference internal" href="../modules/SP/misc.html">2.3.4. Miscellaneous</a></li>
6974
<li class="toctree-l3"><a class="reference internal" href="../modules/SP/texture_analysis.html">2.3.5. Texture Analysis</a></li>
7075
<li class="toctree-l3"><a class="reference internal" href="../modules/SP/stoch_bif.html">2.3.6. Stochastic P-Bifurcation Detection</a></li>
76+
<li class="toctree-l3"><a class="reference internal" href="../modules/SP/parameter_path_opt.html">2.3.7. Parameter Path Optimization</a></li>
7177
</ul>
7278
</li>
7379
<li class="toctree-l2"><a class="reference internal" href="../modules/TDA/index.html">2.4. Topological Data Analaysis (TDA) Module</a><ul>
@@ -120,7 +126,7 @@
120126
<div class="rst-content style-external-links">
121127
<div role="navigation" aria-label="Page navigation">
122128
<ul class="wy-breadcrumbs">
123-
<li><a href="../index.html" class="icon icon-home"></a></li>
129+
<li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
124130
<li class="breadcrumb-item active">Overview: module code</li>
125131
<li class="wy-breadcrumbs-aside">
126132
</li>
@@ -150,6 +156,7 @@ <h1>All modules for which code is available</h1>
150156
<li><a href="teaspoon/SP/information/entropy.html">teaspoon.SP.information.entropy</a></li>
151157
<li><a href="teaspoon/SP/network.html">teaspoon.SP.network</a></li>
152158
<li><a href="teaspoon/SP/network_tools.html">teaspoon.SP.network_tools</a></li>
159+
<li><a href="teaspoon/SP/parameter_path_opt.html">teaspoon.SP.parameter_path_opt</a></li>
153160
<li><a href="teaspoon/SP/texture_analysis.html">teaspoon.SP.texture_analysis</a></li>
154161
<li><a href="teaspoon/SP/tsa_tools.html">teaspoon.SP.tsa_tools</a></li>
155162
<li><a href="teaspoon/TDA/Distance.html">teaspoon.TDA.Distance</a></li>

docs/_modules/teaspoon/DAF/data_assimilation.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/misc.html">2.3.4. Miscellaneous</a></li>
7474
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/texture_analysis.html">2.3.5. Texture Analysis</a></li>
7575
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/stoch_bif.html">2.3.6. Stochastic P-Bifurcation Detection</a></li>
76+
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/parameter_path_opt.html">2.3.7. Parameter Path Optimization</a></li>
7677
</ul>
7778
</li>
7879
<li class="toctree-l2"><a class="reference internal" href="../../../modules/TDA/index.html">2.4. Topological Data Analaysis (TDA) Module</a><ul>

docs/_modules/teaspoon/DAF/forecasting.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/misc.html">2.3.4. Miscellaneous</a></li>
7474
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/texture_analysis.html">2.3.5. Texture Analysis</a></li>
7575
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/stoch_bif.html">2.3.6. Stochastic P-Bifurcation Detection</a></li>
76+
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/parameter_path_opt.html">2.3.7. Parameter Path Optimization</a></li>
7677
</ul>
7778
</li>
7879
<li class="toctree-l2"><a class="reference internal" href="../../../modules/TDA/index.html">2.4. Topological Data Analaysis (TDA) Module</a><ul>

docs/_modules/teaspoon/ML/PD_Classification.html

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
<!DOCTYPE html>
2-
<html class="writer-html5" lang="en" >
2+
<html class="writer-html5" lang="en" data-content_root="../../../">
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>teaspoon.ML.PD_Classification &mdash; teaspoon 1.3.7 documentation</title>
7-
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
8-
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
9-
<link rel="stylesheet" href="../../../_static/plot_directive.css" type="text/css" />
7+
<link rel="stylesheet" type="text/css" href="../../../_static/pygments.css?v=80d5e7a1" />
8+
<link rel="stylesheet" type="text/css" href="../../../_static/css/theme.css?v=19f00094" />
9+
<link rel="stylesheet" type="text/css" href="../../../_static/plot_directive.css" />
10+
11+
1012
<!--[if lt IE 9]>
1113
<script src="../../../_static/js/html5shiv.min.js"></script>
1214
<![endif]-->
1315

14-
<script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
15-
<script src="../../../_static/jquery.js"></script>
16-
<script src="../../../_static/underscore.js"></script>
17-
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
18-
<script src="../../../_static/doctools.js"></script>
19-
<script src="../../../_static/sphinx_highlight.js"></script>
16+
<script src="../../../_static/jquery.js?v=5d32c60e"></script>
17+
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
18+
<script src="../../../_static/documentation_options.js?v=d4a0791e"></script>
19+
<script src="../../../_static/doctools.js?v=9a2dae69"></script>
20+
<script src="../../../_static/sphinx_highlight.js?v=dc90522c"></script>
2021
<script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
2122
<script src="../../../_static/js/theme.js"></script>
2223
<link rel="index" title="Index" href="../../../genindex.html" />
@@ -28,12 +29,16 @@
2829
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
2930
<div class="wy-side-scroll">
3031
<div class="wy-side-nav-search" style="background: white" >
31-
<a href="../../../index.html" class="icon icon-home"> teaspoon
32-
<img src="../../../_static/teaspoon.png" class="logo" alt="Logo"/>
32+
33+
34+
35+
<a href="../../../index.html" class="icon icon-home">
36+
teaspoon
37+
<img src="../../../_static/teaspoon.png" class="logo" alt="Logo"/>
3338
</a>
3439
<div role="search">
3540
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
36-
<input type="text" name="q" placeholder="Search docs" />
41+
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
3742
<input type="hidden" name="check_keywords" value="yes" />
3843
<input type="hidden" name="area" value="default" />
3944
</form>
@@ -68,6 +73,7 @@
6873
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/misc.html">2.3.4. Miscellaneous</a></li>
6974
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/texture_analysis.html">2.3.5. Texture Analysis</a></li>
7075
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/stoch_bif.html">2.3.6. Stochastic P-Bifurcation Detection</a></li>
76+
<li class="toctree-l3"><a class="reference internal" href="../../../modules/SP/parameter_path_opt.html">2.3.7. Parameter Path Optimization</a></li>
7177
</ul>
7278
</li>
7379
<li class="toctree-l2"><a class="reference internal" href="../../../modules/TDA/index.html">2.4. Topological Data Analaysis (TDA) Module</a><ul>
@@ -120,7 +126,7 @@
120126
<div class="rst-content style-external-links">
121127
<div role="navigation" aria-label="Page navigation">
122128
<ul class="wy-breadcrumbs">
123-
<li><a href="../../../index.html" class="icon icon-home"></a></li>
129+
<li><a href="../../../index.html" class="icon icon-home" aria-label="Home"></a></li>
124130
<li class="breadcrumb-item"><a href="../../index.html">Module code</a></li>
125131
<li class="breadcrumb-item active">teaspoon.ML.PD_Classification</li>
126132
<li class="wy-breadcrumbs-aside">
@@ -337,7 +343,9 @@ <h1>Source code for teaspoon.ML.PD_Classification</h1><div class="highlight"><pr
337343
<span class="k">return</span> <span class="n">training_dgms</span><span class="o">.</span><span class="n">reset_index</span><span class="p">(),</span> <span class="n">testing_dgms</span><span class="o">.</span><span class="n">reset_index</span><span class="p">()</span>
338344

339345

340-
<div class="viewcode-block" id="getPercentScore"><a class="viewcode-back" href="../../../modules/ML/CL.html#teaspoon.ML.PD_Classification.getPercentScore">[docs]</a><span class="k">def</span> <span class="nf">getPercentScore</span><span class="p">(</span><span class="n">DgmsDF</span><span class="p">,</span>
346+
<div class="viewcode-block" id="getPercentScore">
347+
<a class="viewcode-back" href="../../../modules/ML/CL.html#teaspoon.ML.PD_Classification.getPercentScore">[docs]</a>
348+
<span class="k">def</span> <span class="nf">getPercentScore</span><span class="p">(</span><span class="n">DgmsDF</span><span class="p">,</span>
341349
<span class="n">labels_col</span><span class="o">=</span><span class="s1">&#39;trainingLabel&#39;</span><span class="p">,</span>
342350
<span class="n">dgm_col</span><span class="o">=</span><span class="s1">&#39;Dgm1&#39;</span><span class="p">,</span>
343351
<span class="n">params</span><span class="o">=</span><span class="n">Base</span><span class="o">.</span><span class="n">ParameterBucket</span><span class="p">(),</span>
@@ -784,6 +792,7 @@ <h1>Source code for teaspoon.ML.PD_Classification</h1><div class="highlight"><pr
784792
<span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
785793

786794
<span class="k">return</span> <span class="n">c_report_train</span><span class="p">,</span> <span class="n">c_report_test</span></div>
795+
787796
</pre></div>
788797

789798
</div>

0 commit comments

Comments
 (0)