pynumerics 2.3.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.
- pynumerics/__init__.py +73 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.LICENSE.txt +27 -0
- pynumerics/_bin/Microsoft.CodeAnalysis.dll +0 -0
- pynumerics/_bin/Numerics.dll +0 -0
- pynumerics/_bin/pynumerics.runtimeconfig.json +15 -0
- pynumerics/_coverage.py +3825 -0
- pynumerics/_util.py +237 -0
- pynumerics/_version.py +40 -0
- pynumerics/bootstrap.py +593 -0
- pynumerics/callbacks.py +791 -0
- pynumerics/copulas.py +910 -0
- pynumerics/data.py +2233 -0
- pynumerics/differentiation.py +348 -0
- pynumerics/distributions.py +4043 -0
- pynumerics/download.py +623 -0
- pynumerics/enums.py +119 -0
- pynumerics/errors.py +245 -0
- pynumerics/functions.py +1142 -0
- pynumerics/goodness_of_fit.py +699 -0
- pynumerics/graphs.py +556 -0
- pynumerics/hypothesis_tests.py +445 -0
- pynumerics/identity.py +144 -0
- pynumerics/integration.py +677 -0
- pynumerics/linalg.py +1408 -0
- pynumerics/machine_learning.py +1335 -0
- pynumerics/marshal.py +733 -0
- pynumerics/mathematics.py +1053 -0
- pynumerics/mcmc.py +1406 -0
- pynumerics/multivariate.py +1539 -0
- pynumerics/ode.py +156 -0
- pynumerics/optimization.py +1736 -0
- pynumerics/probability.py +966 -0
- pynumerics/py.typed +0 -0
- pynumerics/regional.py +522 -0
- pynumerics/roots.py +274 -0
- pynumerics/runtime.py +384 -0
- pynumerics/sampling.py +1758 -0
- pynumerics/special.py +1079 -0
- pynumerics/statistics.py +1958 -0
- pynumerics/timeseries.py +1326 -0
- pynumerics-2.3.0.dist-info/METADATA +142 -0
- pynumerics-2.3.0.dist-info/RECORD +46 -0
- pynumerics-2.3.0.dist-info/WHEEL +5 -0
- pynumerics-2.3.0.dist-info/licenses/LICENSE +10 -0
- pynumerics-2.3.0.dist-info/top_level.txt +1 -0
pynumerics/ode.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""Scalar ODE solvers from ``Numerics.Mathematics.ODESolvers.RungeKutta``.
|
|
2
|
+
|
|
3
|
+
Each solver integrates dy/dt = f(t, y) for one state variable. ``f`` is a Python callable
|
|
4
|
+
``f(t, y)``, C# source or a ``Func<double, double, double>`` (see :mod:`pynumerics.callbacks`).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
from pynumerics import callbacks
|
|
14
|
+
from pynumerics._util import namespace
|
|
15
|
+
from pynumerics.errors import translate_public
|
|
16
|
+
from pynumerics.marshal import to_numpy_doubles
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _runge_kutta() -> Any:
|
|
20
|
+
"""Return ``Numerics.Mathematics.ODESolvers.RungeKutta`` after starting the runtime."""
|
|
21
|
+
return namespace("Numerics.Mathematics.ODESolvers").RungeKutta
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def runge_kutta_second_order(f: Any, initial_value: float, start_time: float, end_time: float,
|
|
25
|
+
time_steps: int) -> np.ndarray:
|
|
26
|
+
"""Solve dy/dt = f(t, y) on an even grid with Heun's second-order method (``RungeKutta.SecondOrder``).
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
f : callable, str or System.Delegate
|
|
31
|
+
The right-hand side ``f(t, y)``.
|
|
32
|
+
initial_value : float
|
|
33
|
+
The value of y at ``start_time``.
|
|
34
|
+
start_time, end_time : float
|
|
35
|
+
The time span.
|
|
36
|
+
time_steps : int
|
|
37
|
+
Number of grid points, ends included.
|
|
38
|
+
|
|
39
|
+
Returns
|
|
40
|
+
-------
|
|
41
|
+
numpy.ndarray
|
|
42
|
+
The value of y at the ``time_steps`` equally spaced times from ``start_time`` to ``end_time``.
|
|
43
|
+
"""
|
|
44
|
+
return to_numpy_doubles(_runge_kutta().SecondOrder(callbacks.bivariate_function(f), float(initial_value),
|
|
45
|
+
float(start_time), float(end_time), int(time_steps)))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def runge_kutta_fourth_order(f: Any, initial_value: float, start_time: float, end_time: float,
|
|
49
|
+
time_steps: int) -> np.ndarray:
|
|
50
|
+
"""Solve dy/dt = f(t, y) on an even grid with the classical fourth-order method (``RungeKutta.FourthOrder``).
|
|
51
|
+
|
|
52
|
+
Parameters
|
|
53
|
+
----------
|
|
54
|
+
f : callable, str or System.Delegate
|
|
55
|
+
The right-hand side ``f(t, y)``.
|
|
56
|
+
initial_value : float
|
|
57
|
+
The value of y at ``start_time``.
|
|
58
|
+
start_time, end_time : float
|
|
59
|
+
The time span.
|
|
60
|
+
time_steps : int
|
|
61
|
+
Number of grid points, ends included.
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
numpy.ndarray
|
|
66
|
+
The value of y at the ``time_steps`` equally spaced times from ``start_time`` to ``end_time``.
|
|
67
|
+
"""
|
|
68
|
+
return to_numpy_doubles(_runge_kutta().FourthOrder(callbacks.bivariate_function(f), float(initial_value),
|
|
69
|
+
float(start_time), float(end_time), int(time_steps)))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def runge_kutta_fourth_order_step(f: Any, initial_value: float, start_time: float, dt: float) -> float:
|
|
73
|
+
"""Advance dy/dt = f(t, y) one classical fourth-order step (``RungeKutta.FourthOrder(f, y0, t0, dt)``).
|
|
74
|
+
|
|
75
|
+
Parameters
|
|
76
|
+
----------
|
|
77
|
+
f : callable, str or System.Delegate
|
|
78
|
+
The right-hand side ``f(t, y)``.
|
|
79
|
+
initial_value : float
|
|
80
|
+
The value of y at ``start_time``.
|
|
81
|
+
start_time : float
|
|
82
|
+
The start time.
|
|
83
|
+
dt : float
|
|
84
|
+
The step.
|
|
85
|
+
|
|
86
|
+
Returns
|
|
87
|
+
-------
|
|
88
|
+
float
|
|
89
|
+
The value of y at ``start_time + dt``.
|
|
90
|
+
"""
|
|
91
|
+
return float(_runge_kutta().FourthOrder(callbacks.bivariate_function(f), float(initial_value),
|
|
92
|
+
float(start_time), float(dt)))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def runge_kutta_fehlberg(f: Any, initial_value: float, start_time: float, dt: float, dt_min: float,
|
|
96
|
+
tolerance: float = 1e-3) -> float:
|
|
97
|
+
"""Advance dy/dt = f(t, y) over ``dt`` with adaptive Runge-Kutta-Fehlberg 4(5) steps (``RungeKutta.Fehlberg``).
|
|
98
|
+
|
|
99
|
+
Parameters
|
|
100
|
+
----------
|
|
101
|
+
f : callable, str or System.Delegate
|
|
102
|
+
The right-hand side ``f(t, y)``.
|
|
103
|
+
initial_value : float
|
|
104
|
+
The value of y at ``start_time``.
|
|
105
|
+
start_time : float
|
|
106
|
+
The start time.
|
|
107
|
+
dt : float
|
|
108
|
+
The span to advance, which is also the largest step.
|
|
109
|
+
dt_min : float
|
|
110
|
+
The smallest step.
|
|
111
|
+
tolerance : float, optional
|
|
112
|
+
Absolute error tolerance per step; default 1e-3.
|
|
113
|
+
|
|
114
|
+
Returns
|
|
115
|
+
-------
|
|
116
|
+
float
|
|
117
|
+
The value of y at ``start_time + dt``.
|
|
118
|
+
"""
|
|
119
|
+
return float(_runge_kutta().Fehlberg(callbacks.bivariate_function(f), float(initial_value), float(start_time),
|
|
120
|
+
float(dt), float(dt_min), float(tolerance)))
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def runge_kutta_cash_karp(f: Any, initial_value: float, start_time: float, dt: float, dt_min: float,
|
|
124
|
+
tolerance: float = 1e-3) -> float:
|
|
125
|
+
"""Advance dy/dt = f(t, y) over ``dt`` with adaptive Cash-Karp 4(5) steps (``RungeKutta.CashKarp``).
|
|
126
|
+
|
|
127
|
+
Parameters
|
|
128
|
+
----------
|
|
129
|
+
f : callable, str or System.Delegate
|
|
130
|
+
The right-hand side ``f(t, y)``.
|
|
131
|
+
initial_value : float
|
|
132
|
+
The value of y at ``start_time``.
|
|
133
|
+
start_time : float
|
|
134
|
+
The start time.
|
|
135
|
+
dt : float
|
|
136
|
+
The span to advance, which is also the largest step.
|
|
137
|
+
dt_min : float
|
|
138
|
+
The smallest step.
|
|
139
|
+
tolerance : float, optional
|
|
140
|
+
Absolute error tolerance per step; default 1e-3.
|
|
141
|
+
|
|
142
|
+
Returns
|
|
143
|
+
-------
|
|
144
|
+
float
|
|
145
|
+
The value of y at ``start_time + dt``.
|
|
146
|
+
"""
|
|
147
|
+
return float(_runge_kutta().CashKarp(callbacks.bivariate_function(f), float(initial_value), float(start_time),
|
|
148
|
+
float(dt), float(dt_min), float(tolerance)))
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
__all__ = [
|
|
152
|
+
"runge_kutta_cash_karp", "runge_kutta_fehlberg", "runge_kutta_fourth_order", "runge_kutta_fourth_order_step",
|
|
153
|
+
"runge_kutta_second_order",
|
|
154
|
+
]
|
|
155
|
+
|
|
156
|
+
translate_public(globals())
|