pymdea 0.1.0__py3-none-any.whl
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.
- pymdea/__init__.py +0 -0
- pymdea/core.py +356 -0
- pymdea/plot.py +126 -0
- pymdea-0.1.0.dist-info/METADATA +88 -0
- pymdea-0.1.0.dist-info/RECORD +7 -0
- pymdea-0.1.0.dist-info/WHEEL +4 -0
- pymdea-0.1.0.dist-info/licenses/LICENSE +21 -0
pymdea/__init__.py
ADDED
|
File without changes
|
pymdea/core.py
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"""Diffusion entropy analysis core methods."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Literal, Self
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import polars as pl
|
|
9
|
+
import stochastic.processes.continuous
|
|
10
|
+
import stochastic.processes.noise
|
|
11
|
+
from scipy import stats
|
|
12
|
+
from scipy.optimize import curve_fit
|
|
13
|
+
from tqdm import tqdm
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _power_log(x: float, a: float, b: float) -> float:
|
|
17
|
+
"""Log power law for curve fit."""
|
|
18
|
+
return (a * np.log(x)) + b
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class DeaLoader:
|
|
22
|
+
"""Load data for a diffusion entropy analysis."""
|
|
23
|
+
|
|
24
|
+
def __init__(self: Self) -> Self:
|
|
25
|
+
"""Load data for a diffusion entropy analysis."""
|
|
26
|
+
|
|
27
|
+
def make_sample_data(self: Self, length: int = 100000, seed: int = 1) -> np.ndarray:
|
|
28
|
+
"""Generate an array of sample data.
|
|
29
|
+
|
|
30
|
+
Parameters
|
|
31
|
+
----------
|
|
32
|
+
length : int, optional, default: 100000
|
|
33
|
+
Number of time-steps to produce in the sample data.
|
|
34
|
+
seed : int, optional, default: 1
|
|
35
|
+
Seed for random number generation.
|
|
36
|
+
|
|
37
|
+
Returns
|
|
38
|
+
-------
|
|
39
|
+
Self @ Loader
|
|
40
|
+
An instance of the Loader object.
|
|
41
|
+
|
|
42
|
+
"""
|
|
43
|
+
rng = np.random.default_rng(seed=seed)
|
|
44
|
+
random_walk = rng.choice([-1, 1], size=length).cumsum()
|
|
45
|
+
random_walk[0] = 0 # always start from 0
|
|
46
|
+
self.seed = seed
|
|
47
|
+
self.data = random_walk
|
|
48
|
+
return self
|
|
49
|
+
|
|
50
|
+
def make_diffusion_process(
|
|
51
|
+
self: Self,
|
|
52
|
+
kind: Literal["cn", "gn", "fgn", "fbm"] = "gn",
|
|
53
|
+
length: int = 10000,
|
|
54
|
+
a: float = 0,
|
|
55
|
+
) -> Self:
|
|
56
|
+
"""Generate diffusion process data.
|
|
57
|
+
|
|
58
|
+
Parameters
|
|
59
|
+
----------
|
|
60
|
+
kind : str {"cn", "gn", "fgn", "fbm"}, optional, default "cn"
|
|
61
|
+
Type of diffusion noise to generate. If "cn", generate a
|
|
62
|
+
colored noise with spectral power `a`. If "gn", generate a
|
|
63
|
+
Gaussian noise. If "fgn", generate a fractional Gaussian
|
|
64
|
+
noise with Hurst index H = `a`. If "fbm", generate a
|
|
65
|
+
fractional Brownian motion with Hurst index H=`a`.
|
|
66
|
+
length : int, optional, default 10000
|
|
67
|
+
Length of time-series to generate.
|
|
68
|
+
a : float, optiona, default 0
|
|
69
|
+
Only used if `kind` is "fgn", "fbm", or "cn". If `kind` is
|
|
70
|
+
"fgn" or "fbm", this sets the Hurst index of the process.
|
|
71
|
+
If `kind` is "cn" this sets the index of the power law
|
|
72
|
+
spectrum for the noise, 1/(f^`a`).
|
|
73
|
+
|
|
74
|
+
Returns
|
|
75
|
+
-------
|
|
76
|
+
Self @ Loader
|
|
77
|
+
An instance of the Loader object.
|
|
78
|
+
|
|
79
|
+
"""
|
|
80
|
+
if kind == "gn":
|
|
81
|
+
process = stochastic.processes.noise.GaussianNoise()
|
|
82
|
+
self.data = process.sample(length)
|
|
83
|
+
if kind == "cn":
|
|
84
|
+
process = stochastic.processes.noise.ColoredNoise(beta=a)
|
|
85
|
+
self.data = process.sample(length)
|
|
86
|
+
if kind == "fgn":
|
|
87
|
+
process = stochastic.processes.noise.FractionalGaussianNoise(hurst=a)
|
|
88
|
+
self.data = process.sample(length)
|
|
89
|
+
if kind == "fbm":
|
|
90
|
+
process = stochastic.processes.continuous.FractionalBrownianMotion(hurst=a)
|
|
91
|
+
self.data = process.sample(length)
|
|
92
|
+
return self
|
|
93
|
+
|
|
94
|
+
def read_data_file(self: Self, filepath: str, column_name: str) -> pl.DataFrame:
|
|
95
|
+
"""Read input data from file.
|
|
96
|
+
|
|
97
|
+
Parameters
|
|
98
|
+
----------
|
|
99
|
+
filepath : str
|
|
100
|
+
System path to a file containing data. Must include the
|
|
101
|
+
full file name, including the extension. Example:
|
|
102
|
+
"/example/path/to/file.csv"
|
|
103
|
+
column_name : str
|
|
104
|
+
Name of the column in the data file which contains the time
|
|
105
|
+
series data values.
|
|
106
|
+
|
|
107
|
+
Returns
|
|
108
|
+
-------
|
|
109
|
+
Self @ Loader
|
|
110
|
+
An instance of the Loader object.
|
|
111
|
+
|
|
112
|
+
Raises
|
|
113
|
+
------
|
|
114
|
+
ValueError
|
|
115
|
+
If filepath points to a file of type other than
|
|
116
|
+
CSV. Support for more types of files is a work in
|
|
117
|
+
progress.
|
|
118
|
+
|
|
119
|
+
"""
|
|
120
|
+
filepath = Path(filepath)
|
|
121
|
+
supported_types = [".csv"]
|
|
122
|
+
if filepath.suffix not in supported_types:
|
|
123
|
+
msg = f"filetype must be one of: {supported_types}."
|
|
124
|
+
raise ValueError(msg)
|
|
125
|
+
if filepath.suffix == ".csv":
|
|
126
|
+
self.data = pl.scan_csv(filepath).select(column_name).to_numpy()
|
|
127
|
+
return self
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class DeaEngine:
|
|
131
|
+
"""Run diffusion entropy analysis."""
|
|
132
|
+
|
|
133
|
+
def __init__(self: Self, loader: DeaLoader) -> Self:
|
|
134
|
+
"""Run diffusion entropy analysis."""
|
|
135
|
+
self.data = loader.data
|
|
136
|
+
|
|
137
|
+
def _apply_stripes(self: Self) -> Self:
|
|
138
|
+
"""Round `data` to `stripes` evenly spaced intervals."""
|
|
139
|
+
if np.min(self.data) <= 0:
|
|
140
|
+
self.data = self.data + np.abs(np.min(self.data))
|
|
141
|
+
elif np.min(self.data) > 0:
|
|
142
|
+
self.data = self.data - np.abs(np.min(self.data))
|
|
143
|
+
data_width = np.abs(self.data.max() - self.data.min())
|
|
144
|
+
stripe_size = data_width / self.number_of_stripes
|
|
145
|
+
self.series = self.data / stripe_size
|
|
146
|
+
return self
|
|
147
|
+
|
|
148
|
+
def _get_events(self: Self) -> Self:
|
|
149
|
+
"""Record an event (1) when `series` changes value."""
|
|
150
|
+
no_upper_crossing = self.series[1:] < np.floor(self.series[:-1]) + 1
|
|
151
|
+
no_lower_crossing = self.series[1:] > np.ceil(self.series[:-1]) - 1
|
|
152
|
+
events = np.where(no_lower_crossing & no_upper_crossing, 0, 1)
|
|
153
|
+
self.events = np.append([0], events) # Event impossible at index 0
|
|
154
|
+
return self
|
|
155
|
+
|
|
156
|
+
def _make_trajectory(self: Self) -> Self:
|
|
157
|
+
"""Construct diffusion trajectory from events."""
|
|
158
|
+
self.trajectory = np.cumsum(self.events)
|
|
159
|
+
return self
|
|
160
|
+
|
|
161
|
+
def _calculate_entropy(self: Self, window_stop: float = 0.25) -> Self:
|
|
162
|
+
"""Calculate the Shannon Entropy of the diffusion trajectory.
|
|
163
|
+
|
|
164
|
+
Parameters
|
|
165
|
+
----------
|
|
166
|
+
window_stop : float, optional, default: 0.25
|
|
167
|
+
Proportion of total data length at which to cap the maximum
|
|
168
|
+
window length. Large window lengths rarely produce
|
|
169
|
+
informative entropy.
|
|
170
|
+
|
|
171
|
+
"""
|
|
172
|
+
entropies = []
|
|
173
|
+
window_lengths = np.unique(
|
|
174
|
+
np.logspace(
|
|
175
|
+
start=0,
|
|
176
|
+
stop=np.log10(window_stop * len(self.trajectory)),
|
|
177
|
+
num=1000,
|
|
178
|
+
dtype=np.int32,
|
|
179
|
+
),
|
|
180
|
+
)
|
|
181
|
+
for window_length in tqdm(window_lengths):
|
|
182
|
+
window_starts = np.arange(0, len(self.trajectory) - window_length, 1)
|
|
183
|
+
window_ends = np.arange(window_length, len(self.trajectory), 1)
|
|
184
|
+
displacements = (
|
|
185
|
+
self.trajectory[window_ends] - self.trajectory[window_starts]
|
|
186
|
+
)
|
|
187
|
+
counts, bin_edge = np.histogram(displacements, bins="doane")
|
|
188
|
+
counts = np.array(counts[counts != 0])
|
|
189
|
+
binsize = bin_edge[1] - bin_edge[0]
|
|
190
|
+
distribution = counts / np.sum(counts)
|
|
191
|
+
entropies.append(
|
|
192
|
+
-np.sum(distribution * np.log(distribution)) + np.log(binsize),
|
|
193
|
+
)
|
|
194
|
+
self.entropies = np.asarray(entropies)
|
|
195
|
+
self.window_lengths = window_lengths
|
|
196
|
+
return self
|
|
197
|
+
|
|
198
|
+
def _calculate_scaling(self: Self) -> Self:
|
|
199
|
+
"""Calculate scaling."""
|
|
200
|
+
start_index = np.floor(self.fit_start * len(self.window_lengths)).astype(int)
|
|
201
|
+
stop_index = np.floor(self.fit_stop * len(self.window_lengths)).astype(int)
|
|
202
|
+
s_slice = self.entropies[start_index:stop_index]
|
|
203
|
+
length_slice = self.window_lengths[start_index:stop_index]
|
|
204
|
+
if self.fit_method == "ls":
|
|
205
|
+
logging.warning(
|
|
206
|
+
"""Least-squares linear fits can introduce systematic error when
|
|
207
|
+
applied to log-scale data. Prefer the more robust 'theilsen' or
|
|
208
|
+
'siegel' methods.""",
|
|
209
|
+
)
|
|
210
|
+
coefficients = curve_fit(
|
|
211
|
+
f=_power_log,
|
|
212
|
+
xdata=length_slice,
|
|
213
|
+
ydata=s_slice,
|
|
214
|
+
)[0] # 0 is coeffs, 1 is uncertainty, uncertainty not yet used
|
|
215
|
+
if self.fit_method == "theilsen":
|
|
216
|
+
coefficients = stats.theilslopes(s_slice, np.log(length_slice))
|
|
217
|
+
if self.fit_method == "siegel":
|
|
218
|
+
coefficients = stats.siegelslopes(s_slice, np.log(length_slice))
|
|
219
|
+
self.length_slice = length_slice
|
|
220
|
+
self.fit_coefficients = coefficients
|
|
221
|
+
self.delta = coefficients[0]
|
|
222
|
+
return self
|
|
223
|
+
|
|
224
|
+
def _calculate_mu(self: Self) -> Self:
|
|
225
|
+
"""Calculate powerlaw index for inter-event time distribution.
|
|
226
|
+
|
|
227
|
+
- mu1 is the index calculated by the rule `1 + delta`.
|
|
228
|
+
- mu2 is the index calculated by the rule `1 + (1 / delta)`.
|
|
229
|
+
|
|
230
|
+
Returns
|
|
231
|
+
-------
|
|
232
|
+
Self @ Engine
|
|
233
|
+
Object containing the results and inputs of the diffusion
|
|
234
|
+
entropy analysis.
|
|
235
|
+
|
|
236
|
+
Notes
|
|
237
|
+
-----
|
|
238
|
+
mu is calculated by both rules. later both are plotted
|
|
239
|
+
against the line relating delta and mu, to hopefully
|
|
240
|
+
let users graphically determine the correct mu.
|
|
241
|
+
|
|
242
|
+
"""
|
|
243
|
+
self.mu1 = 1 + self.delta
|
|
244
|
+
self.mu2 = 1 + (1 / self.delta)
|
|
245
|
+
return self
|
|
246
|
+
|
|
247
|
+
def print_result(self: Self) -> str:
|
|
248
|
+
"""Print out result of analysis."""
|
|
249
|
+
self.result = "--------------------------------- \n"
|
|
250
|
+
self.result = self.result + "result \n"
|
|
251
|
+
self.result = self.result + f" δ: {self.delta} \n"
|
|
252
|
+
self.result = self.result + f" μ (rule 1): {self.mu1} \n"
|
|
253
|
+
self.result = self.result + f" μ (rule 2): {self.mu2} \n"
|
|
254
|
+
self.result = self.result + "---------------------------------"
|
|
255
|
+
print(self.result) # noqa: T201
|
|
256
|
+
return self
|
|
257
|
+
|
|
258
|
+
def analyze_with_stripes(
|
|
259
|
+
self: Self,
|
|
260
|
+
fit_start: int,
|
|
261
|
+
fit_stop: int,
|
|
262
|
+
fit_method: Literal["siegel", "theilsen", "ls"] = "siegel",
|
|
263
|
+
n_stripes: int = 20,
|
|
264
|
+
) -> Self:
|
|
265
|
+
"""Run a modified diffusion entropy analysis.
|
|
266
|
+
|
|
267
|
+
Parameters
|
|
268
|
+
----------
|
|
269
|
+
fit_start : float
|
|
270
|
+
Fraction of maximum window length at which to start linear fit.
|
|
271
|
+
fit_stop : float
|
|
272
|
+
Fraction of maximum window length at which to stop linear fit.
|
|
273
|
+
fit_method : str {"siegel", "theilsen", "ls"}, optional
|
|
274
|
+
Linear fit method to use. By default "siegel"
|
|
275
|
+
n_stripes : int, optional, default: 20
|
|
276
|
+
Number of stripes to apply to input time-series during
|
|
277
|
+
analysis.
|
|
278
|
+
|
|
279
|
+
Returns
|
|
280
|
+
-------
|
|
281
|
+
Self @ Engine
|
|
282
|
+
Object containing the results and inputs of the diffusion
|
|
283
|
+
entropy analysis.
|
|
284
|
+
|
|
285
|
+
Raises
|
|
286
|
+
------
|
|
287
|
+
ValueError
|
|
288
|
+
If n_stripes < 2. At least two stripes must be applied for
|
|
289
|
+
DEA to provide a meaningful result.
|
|
290
|
+
|
|
291
|
+
Notes
|
|
292
|
+
-----
|
|
293
|
+
Prefer the siegel or theilsen methods. Least squares linear
|
|
294
|
+
fits can introduce bias when done over log-scale data, see
|
|
295
|
+
Clauset, A., Shalizi, C.R. and Newman, M.E., 2009. Power-law
|
|
296
|
+
distributions in empirical data. SIAM review, 51(4), pp.661-703.
|
|
297
|
+
https://doi.org/10.1137/070710111.
|
|
298
|
+
https://arxiv.org/pdf/0706.1062.pdf.
|
|
299
|
+
|
|
300
|
+
"""
|
|
301
|
+
if n_stripes < 2: # noqa: PLR2004
|
|
302
|
+
msg = "n_stripes must be greater than 1"
|
|
303
|
+
raise ValueError(msg)
|
|
304
|
+
self.number_of_stripes = n_stripes
|
|
305
|
+
self.fit_start = fit_start
|
|
306
|
+
self.fit_stop = fit_stop
|
|
307
|
+
self.fit_method = fit_method
|
|
308
|
+
self._apply_stripes()
|
|
309
|
+
self._get_events()
|
|
310
|
+
self._make_trajectory()
|
|
311
|
+
self._calculate_entropy()
|
|
312
|
+
self._calculate_scaling()
|
|
313
|
+
self._calculate_mu()
|
|
314
|
+
self.print_result()
|
|
315
|
+
|
|
316
|
+
def analyze_without_stripes(
|
|
317
|
+
self: Self,
|
|
318
|
+
fit_start: int,
|
|
319
|
+
fit_stop: int,
|
|
320
|
+
fit_method: Literal["siegel", "theilsen", "ls"] = "siegel",
|
|
321
|
+
) -> Self:
|
|
322
|
+
"""Run a modified diffusion entropy analysis.
|
|
323
|
+
|
|
324
|
+
Parameters
|
|
325
|
+
----------
|
|
326
|
+
fit_start : float
|
|
327
|
+
Fraction of maximum window length at which to start linear fit.
|
|
328
|
+
fit_stop : float
|
|
329
|
+
Fraction of maximum window length at which to stop linear fit.
|
|
330
|
+
fit_method : str {"siegel", "theilsen", "ls"}, optional
|
|
331
|
+
Linear fit method to use. By default "siegel"
|
|
332
|
+
|
|
333
|
+
Returns
|
|
334
|
+
-------
|
|
335
|
+
Self @ Engine
|
|
336
|
+
Object containing the results and inputs of the diffusion
|
|
337
|
+
entropy analysis.
|
|
338
|
+
|
|
339
|
+
Notes
|
|
340
|
+
-----
|
|
341
|
+
Prefer the siegel or theilsen methods. Least squares linear
|
|
342
|
+
fits can introduce bias when done over log-scale data, see
|
|
343
|
+
Clauset, A., Shalizi, C.R. and Newman, M.E., 2009. Power-law
|
|
344
|
+
distributions in empirical data. SIAM review, 51(4), pp.661-703.
|
|
345
|
+
https://doi.org/10.1137/070710111.
|
|
346
|
+
https://arxiv.org/pdf/0706.1062.pdf.
|
|
347
|
+
|
|
348
|
+
"""
|
|
349
|
+
self.trajectory = self.data
|
|
350
|
+
self.fit_start = fit_start
|
|
351
|
+
self.fit_stop = fit_stop
|
|
352
|
+
self.fit_method = fit_method
|
|
353
|
+
self._calculate_entropy()
|
|
354
|
+
self._calculate_scaling()
|
|
355
|
+
self._calculate_mu()
|
|
356
|
+
self.print_result()
|
pymdea/plot.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""Plotting functions."""
|
|
2
|
+
|
|
3
|
+
from typing import Literal, Self
|
|
4
|
+
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import numpy as np
|
|
7
|
+
import seaborn as sns
|
|
8
|
+
|
|
9
|
+
from pymdea.core import DeaEngine
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DeaPlotter:
|
|
13
|
+
"""Plot DEA results."""
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self: Self,
|
|
17
|
+
model: DeaEngine,
|
|
18
|
+
theme: Literal["ticks", "whitegrid", "darkgrid"] = "ticks",
|
|
19
|
+
colors: Literal["muted", "deep", "Set2", "tab10"] = "muted",
|
|
20
|
+
) -> Self:
|
|
21
|
+
"""Plot DEA results.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
model : Self@DeaEngine
|
|
26
|
+
Object containing the results of a DEA analysis to be plotted.
|
|
27
|
+
theme : str {"ticks", "whitegrid", "darkgrid"}, optional, default: "ticks"
|
|
28
|
+
Name of a seaborn style. Passed through to
|
|
29
|
+
seaborn.set_theme().
|
|
30
|
+
colors : str {"muted", "deep", "Set2", "tab10"}, optional, default: "muted"
|
|
31
|
+
Name of a seaborn or matplotlib color palette. Passed
|
|
32
|
+
through to seaborn.set_theme().
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
sns.set_theme(context="notebook", style=theme, palette=colors)
|
|
36
|
+
self.window_lengths = model.window_lengths
|
|
37
|
+
self.entropies = model.entropies
|
|
38
|
+
self.delta = model.fit_coefficients[0]
|
|
39
|
+
self.y_intercept = model.fit_coefficients[1]
|
|
40
|
+
self.mu1 = model.mu1
|
|
41
|
+
self.mu2 = model.mu2
|
|
42
|
+
|
|
43
|
+
def s_vs_l(self: Self, fig_width: int = 4, fig_height: int = 3) -> None:
|
|
44
|
+
"""Plot the slope of entropy vs window length.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
fig_width : int, optional, default: 4
|
|
49
|
+
Width, in inches, of the figure.
|
|
50
|
+
fig_height : int, optional, default: 3
|
|
51
|
+
Height, in inches, of the figure.
|
|
52
|
+
|
|
53
|
+
"""
|
|
54
|
+
x_line = np.linspace(start=1, stop=np.max(self.window_lengths), num=3)
|
|
55
|
+
fig, ax = plt.subplots(figsize=(fig_width, fig_height))
|
|
56
|
+
ax.plot(
|
|
57
|
+
self.window_lengths,
|
|
58
|
+
self.entropies,
|
|
59
|
+
linestyle="none",
|
|
60
|
+
marker="o",
|
|
61
|
+
markersize=3,
|
|
62
|
+
fillstyle="none",
|
|
63
|
+
)
|
|
64
|
+
ax.plot(
|
|
65
|
+
x_line,
|
|
66
|
+
self.delta * np.log(x_line) + self.y_intercept,
|
|
67
|
+
color="k",
|
|
68
|
+
label=f"$\\delta = {np.round(self.delta, 3)}$",
|
|
69
|
+
)
|
|
70
|
+
ax.set_xscale("log")
|
|
71
|
+
ax.set_xlabel("$\\ln(L)$")
|
|
72
|
+
ax.set_ylabel("$S(L)$")
|
|
73
|
+
ax.legend(loc=0)
|
|
74
|
+
sns.despine(trim=True)
|
|
75
|
+
plt.show(fig)
|
|
76
|
+
|
|
77
|
+
def mu_candidates(self: Self, fig_width: int = 4, fig_height: int = 3) -> None:
|
|
78
|
+
"""Plot the possible values of mu.
|
|
79
|
+
|
|
80
|
+
Parameters
|
|
81
|
+
----------
|
|
82
|
+
fig_width : int, optional, default: 4
|
|
83
|
+
Width, in inches, of the figure.
|
|
84
|
+
fig_height : int, optional, default: 3
|
|
85
|
+
Height, in inches, of the figure.
|
|
86
|
+
|
|
87
|
+
"""
|
|
88
|
+
x1 = np.linspace(1, 2, 100)
|
|
89
|
+
x2 = np.linspace(2, 3, 100)
|
|
90
|
+
x3 = np.linspace(3, 4, 100)
|
|
91
|
+
y1 = x1 - 1
|
|
92
|
+
y2 = 1 / (x2 - 1)
|
|
93
|
+
y3 = np.full(100, 0.5)
|
|
94
|
+
|
|
95
|
+
fig, ax = plt.subplots(figsize=(fig_width, fig_height))
|
|
96
|
+
ax.plot(x1, y1, color="k")
|
|
97
|
+
ax.plot(x2, y2, color="k")
|
|
98
|
+
ax.plot(x3, y3, color="k")
|
|
99
|
+
ax.plot(
|
|
100
|
+
self.mu1,
|
|
101
|
+
self.delta,
|
|
102
|
+
marker="o",
|
|
103
|
+
fillstyle="none",
|
|
104
|
+
markersize=5,
|
|
105
|
+
markeredgewidth=2,
|
|
106
|
+
linestyle="none",
|
|
107
|
+
label=f"$\\mu$ = {np.round(self.mu1, 2)}",
|
|
108
|
+
)
|
|
109
|
+
ax.plot(
|
|
110
|
+
self.mu2,
|
|
111
|
+
self.delta,
|
|
112
|
+
marker="o",
|
|
113
|
+
fillstyle="none",
|
|
114
|
+
markersize=5,
|
|
115
|
+
markeredgewidth=2,
|
|
116
|
+
linestyle="none",
|
|
117
|
+
label=f"$\\mu$ = {np.round(self.mu2, 2)}",
|
|
118
|
+
)
|
|
119
|
+
ax.set_xticks(ticks=np.linspace(1, 4, 7))
|
|
120
|
+
ax.set_yticks(ticks=np.linspace(0, 1, 5))
|
|
121
|
+
ax.set_xlabel("$\\mu$")
|
|
122
|
+
ax.set_ylabel("$\\delta$")
|
|
123
|
+
ax.legend(loc=0)
|
|
124
|
+
ax.grid(visible=True)
|
|
125
|
+
sns.despine(left=True, bottom=True)
|
|
126
|
+
plt.show(fig)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: pymdea
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Modified diffusion entropy analysis; a temporal complexity analysis method
|
|
5
|
+
Project-URL: Documentation, https://garland-culbreth.github.io/pymdea
|
|
6
|
+
Project-URL: Repository, https://github.com/garland-culbreth/pymdea
|
|
7
|
+
Project-URL: Issues, https://github.com/garland-culbreth/pymdea/issues
|
|
8
|
+
Author: Jacob Baxley, David Lambert
|
|
9
|
+
Author-email: Garland Culbreth <culbreth.garland@gmail.com>
|
|
10
|
+
Maintainer-email: Garland Culbreth <culbreth.garland@gmail.com>
|
|
11
|
+
License: MIT License
|
|
12
|
+
|
|
13
|
+
Copyright (c) 2023 Garland Culbreth
|
|
14
|
+
|
|
15
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
17
|
+
in the Software without restriction, including without limitation the rights
|
|
18
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
20
|
+
furnished to do so, subject to the following conditions:
|
|
21
|
+
|
|
22
|
+
The above copyright notice and this permission notice shall be included in all
|
|
23
|
+
copies or substantial portions of the Software.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
+
SOFTWARE.
|
|
32
|
+
License-File: LICENSE
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
38
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
39
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
40
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
41
|
+
Requires-Python: >=3.11
|
|
42
|
+
Requires-Dist: ipykernel>=6.29.5
|
|
43
|
+
Requires-Dist: logging>=0.4.9.6
|
|
44
|
+
Requires-Dist: matplotlib>=3.9.2
|
|
45
|
+
Requires-Dist: mkdocs-jupyter>=0.24.8
|
|
46
|
+
Requires-Dist: mkdocs-material>=9.5.33
|
|
47
|
+
Requires-Dist: mkdocstrings[python]>=0.25.2
|
|
48
|
+
Requires-Dist: numpy>=1.19.0
|
|
49
|
+
Requires-Dist: pathlib>=1.0.1
|
|
50
|
+
Requires-Dist: polars>=1.5.0
|
|
51
|
+
Requires-Dist: pytest>=8.3.2
|
|
52
|
+
Requires-Dist: scipy>=1.14.1
|
|
53
|
+
Requires-Dist: seaborn>=0.13.2
|
|
54
|
+
Requires-Dist: stochastic>=0.6.0
|
|
55
|
+
Requires-Dist: tqdm>=4.66.5
|
|
56
|
+
Requires-Dist: typing>=3.10.0.0
|
|
57
|
+
Description-Content-Type: text/markdown
|
|
58
|
+
|
|
59
|
+
# Diffusion entropy analysis
|
|
60
|
+
|
|
61
|
+
[](https://github.com/garland-culbreth/pymdea/actions/workflows/pytest.yml)
|
|
62
|
+
[](https://github.com/garland-culbreth/pymdea/actions/workflows/mkdocs.yml)
|
|
63
|
+
[](https://github.com/garland-culbreth/pymdea)
|
|
64
|
+
[](https://github.com/astral-sh/ruff)
|
|
65
|
+
[](https://github.com/astral-sh/uv)
|
|
66
|
+
|
|
67
|
+
Diffusion Entropy Analysis is a time-series analysis method for detecting temporal scaling in a data set, such as particle motion, a seismograph, or an electroencephalograph signal. Diffusion Entropy Analysis converts a timeseries into a diffusion trajectory and uses the entropy of this trajectory to measure the temporal scaling in the data. This is accomplished by moving a window along the trajectory, then using the relationship between the natural logarithm of the length of the window and the Shannon entropy to extract the scaling of the time-series process.
|
|
68
|
+
|
|
69
|
+
For further details about the method and how it works, please see [Culbreth, G., Baxley, J. and Lambert, D., 2023. Detecting temporal scaling with modified diffusion entropy analysis. _arXiv preprint arXiv:2311.11453_](https://arxiv.org/abs/2311.11453).
|
|
70
|
+
|
|
71
|
+
## Installation and use
|
|
72
|
+
|
|
73
|
+
You'll need an up to date Python installation, e.g., through [uv](https://docs.astral.sh/uv/#python-management). Once you have one, clone this repository to a location on your file system where you can work with the files.
|
|
74
|
+
|
|
75
|
+
A user guide is available in the [documentation](https://garland-culbreth.github.io/pymdea/).
|
|
76
|
+
|
|
77
|
+
## Built with
|
|
78
|
+
|
|
79
|
+
[](https://numpy.org/)
|
|
80
|
+
[](https://scipy.org/)
|
|
81
|
+
[](https://pola.rs/)
|
|
82
|
+
[](https://matplotlib.org/)
|
|
83
|
+
[](https://seaborn.pydata.org/)
|
|
84
|
+
[](https://tqdm.github.io/)
|
|
85
|
+
[](https://docs.pytest.org/en/stable/)
|
|
86
|
+
[](https://docs.astral.sh/ruff/)
|
|
87
|
+
[](https://squidfunk.github.io/mkdocs-material/)
|
|
88
|
+
[](https://mkdocstrings.github.io/)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
pymdea/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
pymdea/core.py,sha256=mQ69cGTiIfbcCYPQ5e1hDltd1QJ_YPLb1Di0DNzbAEI,13279
|
|
3
|
+
pymdea/plot.py,sha256=7yeTlcDkkkYaJcuthYUMmMwJbBdtr0sVYM2UC_IxcrM,4052
|
|
4
|
+
pymdea-0.1.0.dist-info/METADATA,sha256=3YDfx0HOc-98Nv_Pz7whNMbstO25h4ezWs1EPjpWYI0,6399
|
|
5
|
+
pymdea-0.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
|
6
|
+
pymdea-0.1.0.dist-info/licenses/LICENSE,sha256=7w0mmCK_ik1ZY7gwtUA98mDmrMsV35s4nyIGPA8H9qo,1094
|
|
7
|
+
pymdea-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Garland Culbreth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|