DynamicalSystem
A discrete-time dynamical system (DTDS) is represented as a pair of functions,
(f, h), following the definition in Mangat et al., dynamicalnodes: From
Theory to Python to ROS:
x_{k+1} = f(x_k, u_k, theta)
y_k = h(x_k, u_k, theta)
f is the evolution function that propagates the state forward one step;
h is the measurement (or output) function that computes an observation
from the current state. Either function may be omitted – denoted * in
the paper, None here – giving three cases:
(f, *)– no output function.(*, h)– stateless, e.g. a signal generator.(f, h)– both state evolution and output are defined.
Function signatures are unconstrained in name, type, and number of
parameters. DynamicalSystem.step binds keyword arguments to each
function’s signature by name, so the same keyword argument (e.g. a shared
state or parameter) can be passed to both f and h.
- class dynamicalnodes.dynamical_system.DynamicalSystem(*, f=None, h=None)[source]
Bases:
objectA discrete-time dynamical system with (optional) evolution and (optional) measurement functions.
- Parameters:
f (
Optional[Callable]) – Evolution functionf(x_k, u_k, theta) -> x_{k+1}.Noneif the system has no state transition, i.e.(*, h).h (
Optional[Callable]) – Measurement functionh(x_k, u_k, theta) -> y_k.Noneif the system has no output, i.e.(f, *).
Examples
A stateful system with both an evolution and a measurement function – a car whose state is
(displacement, velocity), measured via its speed:>>> def fcar(xk, uk, theta_car): ... d, v = xk ... m, b, dt = theta_car ... return (d + dt * v, v + dt * (uk - b * v) / m) >>> def hcar(xk): ... _, v = xk ... return abs(v) >>> car = DynamicalSystem(f=fcar, h=hcar) >>> x_next, y = car.step(xk=(20.0, 0.0), uk=4.0, theta_car=(2.0, 0.0, 1.0)) >>> x_next (20.0, 2.0) >>> y 0.0
A stateless system, e.g. a signal generator –
(*, h):>>> def h_ref(tk, A=1.0): ... return A if tk >= 1.0 else 0.0 >>> ref = DynamicalSystem(h=h_ref) >>> ref.step(tk=0.0) (None, 0.0) >>> ref.step(tk=2.0) (None, 1.0)
A system with no output function –
(f, *):>>> def f_counter(xk): ... return xk + 1 >>> counter = DynamicalSystem(f=f_counter) >>> counter.step(xk=5) (6, None)
- property f: Optional[Callable]
Evolution function f(x_k, u_k, theta) -> x_{k+1}, or None if the system is stateless.
- property h: Optional[Callable]
Measurement function h(x_k, u_k, theta) -> y_k, or None if the system has no output.
- step(**kwargs)[source]
Evaluate the system for one discrete time step.
Keyword arguments are lexically bound by name to whichever of
fand/orhdeclare them in their signature (see_bind_and_call), so the same keyword argument can be shared by both functions.- Returns:
(None, y_k)for a stateless system,(*, h).(x_{k+1}, None)for a system with no output,(f, *).(x_{k+1}, y_k)for a fully specified system,(f, h).
- Return type:
Tuple[Optional[Any],Optional[Any]]
Notes
his evaluated on the same (pre-update) state passed in via keyword arguments, not on the value returned byf, so the returned observation is one step behind the returned state. In a simulation loop, use the returnedx_{k+1}directly if you need the post-update state.- Raises:
ValueError – If neither
fnorhis defined.- Return type:
Tuple[Any | None, Any | None]
Examples
See the class docstring for worked examples covering all three cases.
>>> empty = DynamicalSystem() >>> empty.step() Traceback (most recent call last): ... ValueError: Nothing to evaluate; no f or h functions!