Skip to content

Commit 7a023b9

Browse files
committed
Merge branch 'master' of github.com:neurophysik/jitcdde
2 parents 36296c7 + 7b423a0 commit 7a023b9

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# You can set these variables from the command line.
55
SPHINXOPTS =
6-
SPHINXBUILD = sphinx-build
6+
SPHINXBUILD = python $(shell which sphinx-build)
77
PAPER =
88
BUILDDIR = _build
99

examples/kuramoto_network.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
:linenos:
1616
:start-after: example-st\u0061rt
1717
:dedent: 1
18-
:emphasize-lines: 9, 10, 15, 20, 21, 24
18+
:emphasize-lines: 11, 12, 17, 22, 23, 26
1919
2020
Explanation of selected features and choices:
2121
22-
* Line 9 is just a quick way to generate the network described above. For more complex networks, you will either have to write more complex function or use dedicated modules. (In fact this example was chosen such that the network creation is very simple.)
22+
* Line 11 is just a quick way to generate the network described above. For more complex networks, you will either have to write more complex function or use dedicated modules. (In fact this example was chosen such that the network creation is very simple.)
2323
24-
* The values of :math:`τ` are initialised globally (line 10). We should not just define a function here, because if we were trying to calculate Lyapunov exponents or the Jacobian, the generator function would be called multiple times, and thus the value of the parameter would not be consistent (which would be disastrous).
24+
* The values of :math:`τ` are initialised globally (line 12). We should not just define a function here, because if we were trying to calculate Lyapunov exponents or the Jacobian, the generator function would be called multiple times, and thus the value of the parameter would not be consistent (which would be disastrous).
2525
26-
* In line 15, we use `symengine.sin` – in contrast to `math.sin` or `numpy.sin`.
26+
* In line 17, we use `symengine.sin` – in contrast to `math.sin` or `numpy.sin`.
2727
28-
* In line 20, we explicitly specify the delays to speed things up a little.
28+
* In line 22, we explicitly specify the delays to speed things up a little.
2929
30-
* In line 21, we explicitly use absolute instead of relative errors, as the latter make no sense for Kuramoto oscillators.
30+
* In line 23, we explicitly use absolute instead of relative errors, as the latter make no sense for Kuramoto oscillators.
3131
32-
* In line 24, we integrate blindly with a maximum time step of 0.1 up to the maximal delay to ensure that initial discontinuities have smoothened out.
32+
* In line 26, we integrate blindly with a maximum time step of 0.1 up to the maximal delay to ensure that initial discontinuities have smoothened out.
3333
"""
3434

3535
if __name__ == "__main__":
@@ -39,7 +39,6 @@
3939

4040
from jitcdde import jitcdde, t, y
4141

42-
4342
rng = np.random.default_rng(seed=42)
4443
n = 100
4544
ω = 1

examples/mackey_glass.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
.. literalinclude:: ../examples/mackey_glass.py
1414
:dedent: 1
15-
:lines: 60-66
15+
:lines: 62-67
1616
1717
Amongst our imports were the symbols for the state (`y`) and time (`t`), which have to be used to write down the differential equation such that JiTCDDE can process it.
1818
Using them, we can write down the right-hand side of the differential equation as a list of expressions.
@@ -21,42 +21,43 @@
2121
2222
.. literalinclude:: ../examples/mackey_glass.py
2323
:dedent: 1
24-
:lines: 68-69
24+
:lines: 69-70
2525
2626
We want the initial condition and past to be :math:`y(t<0) = 1`.
2727
Hence we can use `constant_past`.
2828
This automatically results in the integration starting at :math:`t=0`.
2929
3030
.. literalinclude:: ../examples/mackey_glass.py
3131
:dedent: 1
32-
:lines: 71
32+
:lines: 72
3333
3434
If we calculate the derivative from our initial conditions, we obtain :math:`f(t=0) = 0.025`, which does not agree with the :math:`\\dot{y}(t=0) = 0` as explicitly defined in the initial conditions. Practically, this would result in an error if we started integrating without further precautions.
3535
`step_on_discontinuities` makes some tailored integration steps to avoid this problem and to allow for the discontinuity to be smoothed out by temporal evolution.
3636
(See `discontinuities` for alternatives and more details on this).
3737
3838
.. literalinclude:: ../examples/mackey_glass.py
3939
:dedent: 1
40-
:lines: 73
40+
:lines: 74
4141
4242
Finally, we can perform the actual integration.
4343
In our case, we integrate for 10000 time units with a sampling rate of 10 time units. We query the current time of the integrator (`DDE.t`) to start wherever `step_on_discontinuities` ended. `integrate` returns the state after integration, which we collect in the list `data`.
4444
Finally, we use `numpy.savetxt` to store this to the file `timeseries.dat`.
4545
4646
.. literalinclude:: ../examples/mackey_glass.py
4747
:dedent: 1
48-
:lines: 75-78
48+
:lines: 76-79
4949
5050
Taking everything together, our code is:
5151
5252
.. literalinclude:: ../examples/mackey_glass.py
53+
:linenos:
5354
:dedent: 1
54-
:lines: 60-78
55+
:lines: 62-79
5556
"""
5657

5758

5859
if __name__ == "__main__":
59-
import numpy
60+
import numpy as np
6061

6162
from jitcdde import jitcdde, t, y
6263

@@ -73,6 +74,6 @@
7374
DDE.step_on_discontinuities()
7475

7576
data = []
76-
for time in numpy.arange(DDE.t, DDE.t+10000, 10):
77+
for time in np.arange(DDE.t, DDE.t+10000, 10):
7778
data.append( DDE.integrate(time) )
78-
numpy.savetxt("timeseries.dat", data)
79+
np.savetxt("timeseries.dat", data)

examples/mackey_glass_lyap.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
66
.. literalinclude:: ../examples/mackey_glass_lyap.py
77
:dedent: 1
8-
:lines: 17-49
9-
:emphasize-lines: 11-12, 19-20, 22, 28, 30-33
8+
:lines: 19-49
9+
:emphasize-lines: 9-10, 17-18, 20, 26, 28-31
1010
:linenos:
1111
12-
Note that `integrate` does not only return local Lyapunov exponents but also the length of the time interval to which they apply (which differs from the time spanned by the `integrate` command and may even be zero). This length should be used to weigh the local Lyapunov exponents for statistical processing, like in line 31.
12+
Note that `integrate` does not only return local Lyapunov exponents but also the length of the time interval to which they apply (which differs from the time spanned by the `integrate` command and may even be zero). This length should be used to weigh the local Lyapunov exponents for statistical processing, like in line 29.
1313
"""
1414

1515
if __name__ == "__main__":
16-
import numpy
16+
import numpy as np
1717
from scipy.stats import sem
1818

1919
from jitcdde import jitcdde_lyap, t, y
@@ -34,16 +34,16 @@
3434
data = []
3535
lyaps = []
3636
weights = []
37-
for time in numpy.arange(DDE.t, DDE.t+10000, 10):
37+
for time in np.arange(DDE.t, DDE.t+10000, 10):
3838
state, lyap, weight = DDE.integrate(time)
3939
data.append(state)
4040
lyaps.append(lyap)
4141
weights.append(weight)
4242

43-
numpy.savetxt("timeseries.dat", data)
44-
lyaps = numpy.vstack(lyaps)
43+
np.savetxt("timeseries.dat", data)
44+
lyaps = np.vstack(lyaps)
4545

4646
for i in range(n_lyap):
47-
Lyap = numpy.average(lyaps[400:,i], weights=weights[400:])
47+
Lyap = np.average(lyaps[400:,i], weights=weights[400:])
4848
stderr = sem(lyaps[400:,i]) # Note that this only an estimate
4949
print(f"{i+1}. Lyapunov exponent: {Lyap:.4f} +/- {stderr:.4f}")

0 commit comments

Comments
 (0)