pybounds 0.0.14__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.
- pybounds/__init__.py +13 -0
- pybounds/jacobian.py +46 -0
- pybounds/observability.py +764 -0
- pybounds/simulator.py +477 -0
- pybounds/util.py +279 -0
- pybounds-0.0.14.dist-info/METADATA +65 -0
- pybounds-0.0.14.dist-info/RECORD +10 -0
- pybounds-0.0.14.dist-info/WHEEL +5 -0
- pybounds-0.0.14.dist-info/licenses/LICENSE +21 -0
- pybounds-0.0.14.dist-info/top_level.txt +1 -0
pybounds/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
from .simulator import Simulator
|
|
3
|
+
|
|
4
|
+
from .observability import EmpiricalObservabilityMatrix
|
|
5
|
+
from .observability import SlidingEmpiricalObservabilityMatrix
|
|
6
|
+
from .observability import FisherObservability
|
|
7
|
+
from .observability import SlidingFisherObservability
|
|
8
|
+
from .observability import ObservabilityMatrixImage
|
|
9
|
+
from .observability import transform_states
|
|
10
|
+
|
|
11
|
+
from .jacobian import SymbolicJacobian
|
|
12
|
+
|
|
13
|
+
from .util import colorline, plot_heatmap_log_timeseries
|
pybounds/jacobian.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import sympy as sp
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SymbolicJacobian:
|
|
6
|
+
def __init__(self, func, state_vars):
|
|
7
|
+
"""
|
|
8
|
+
Initialize the Jacobian calculator with a function or symbolic expression for f(x).
|
|
9
|
+
|
|
10
|
+
:param func: A Python function or sympy Matrix representing f(x).
|
|
11
|
+
If func is a Python function, it should take in x and u (e.g., f(x))
|
|
12
|
+
and return a sympy Matrix for xdot.
|
|
13
|
+
If func is a sympy Matrix, it directly represents xdot.
|
|
14
|
+
:param state_vars: List of sympy symbols for variables (e.g., [x1, x2]).
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
self.state_vars = sp.Matrix(state_vars) # state variables as sympy Matrix
|
|
18
|
+
|
|
19
|
+
# Detect if func is symbolic (sympy.Matrix) or a Python function
|
|
20
|
+
if isinstance(func, sp.Matrix):
|
|
21
|
+
# If func is a symbolic Matrix, use it directly as xdot
|
|
22
|
+
self.z_sym = func
|
|
23
|
+
else:
|
|
24
|
+
# If func is a Python function, call it with symbolic state and control variables
|
|
25
|
+
x_sym = self.state_vars
|
|
26
|
+
self.z_sym = func(x_sym) # get the symbolic expression from the function
|
|
27
|
+
|
|
28
|
+
# Calculate the Jacobian of xdot_sym with respect to the state variables
|
|
29
|
+
self.jacobian_symbolic = self.z_sym.jacobian(self.state_vars)
|
|
30
|
+
self.jacobian_symbolic = sp.simplify(self.jacobian_symbolic)
|
|
31
|
+
|
|
32
|
+
def get_jacobian_function(self):
|
|
33
|
+
"""
|
|
34
|
+
Returns a numerical function to evaluate the Jacobian at specific values of x and u.
|
|
35
|
+
|
|
36
|
+
:return: A function that calculates the Jacobian matrix given values of x and u.
|
|
37
|
+
The function takes numpy arrays x and u as inputs.
|
|
38
|
+
"""
|
|
39
|
+
# Convert the symbolic Jacobian to a numerical function using lambdify
|
|
40
|
+
jacobian_func = sp.lambdify(self.state_vars, self.jacobian_symbolic, 'numpy')
|
|
41
|
+
|
|
42
|
+
# Return a wrapper function that accepts x as numpy array
|
|
43
|
+
def jacobian_numerical(x):
|
|
44
|
+
return jacobian_func(*np.array(x))
|
|
45
|
+
|
|
46
|
+
return jacobian_numerical
|