Discrete-time state-space identification

Discrete-time models

class torchid.ss.dt.models.NeuralStateUpdate(n_x, n_u, hidden_size=16, init_small=True)[source]

State-update mapping modeled as a feed-forward neural network with one hidden layer.

The model has structure:

\[\begin{aligned} x_{k+1} = x_k + \mathcal{N}(x_k, u_k), \end{aligned}\]

where \(\mathcal{N}(\cdot, \cdot)\) is a feed-forward neural network with one hidden layer.

Parameters:
  • n_x (int) – Number of state variables

  • n_u (int) – Number of input variables

  • hidden_size – (int, optional): Number of input features in the hidden layer. Default: 0

  • init_small – (boolean, optional): If True, initialize to a Gaussian with mean 0 and std 10^-4. Default: True

  • activation – (str): Activation function in the hidden layer. Either ‘relu’, ‘softplus’, ‘tanh’. Default: ‘relu’

Examples:

>>> ss_model = NeuralStateUpdate(n_x=2, n_u=1, hidden_size=64)
class torchid.ss.dt.models.PolynomialStateUpdate(n_x, n_u, d_max, init_small=True)[source]

State-update mapping modeled as a polynomial in x and u.

The model has structure:

\[\begin{aligned} x_{k+1} = x_k + Ax_{k} + Bu_{k} + Ez_{k}, \end{aligned}\]

where z_{k} is a vector containing (non-linear) monomials in x_{k} and u_{k}

Parameters:
  • n_x – (np.array): Number of states.

  • n_u – (np.array): Number of inputs.

  • d_max (int) – Maximum degree of the polynomial model.

class torchid.ss.dt.models.NeuralLinStateUpdate(n_x, n_u, hidden_size=16, init_small=True)[source]

State-update mapping modeled as a feed-forward neural network with one hidden layer.

The model has structure:

\[\begin{aligned} x_{k+1} = x_k + \mathcal{N}(x_k, u_k), \end{aligned}\]

where \(\mathcal{N}(\cdot, \cdot)\) is a feed-forward neural network with one hidden layer.

Parameters:
  • n_x (int) – Number of state variables

  • n_u (int) – Number of input variables

  • hidden_size – (int, optional): Number of input features in the hidden layer. Default: 0

  • init_small – (boolean, optional): If True, initialize to a Gaussian with mean 0 and std 10^-4. Default: True

  • activation – (str): Activation function in the hidden layer. Either ‘relu’, ‘softplus’, ‘tanh’. Default: ‘relu’

Examples:

>>> ss_model = NeuralStateUpdate(n_x=2, n_u=1, hidden_size=64)
class torchid.ss.dt.models.LinearStateUpdate(n_x, n_u, init_small=True)[source]

State-update mapping modeled as a linear function in x and u.

The model has structure:

\[\begin{aligned} x_{k+1} = x_k + Ax_{k} + Bu_{k}. \end{aligned}\]
Parameters:
  • n_x – (np.array): Number of states.

  • n_u – (np.array): Number of inputs.

  • d_max (int) – Maximum degree of the polynomial model.

class torchid.ss.dt.models.CTSNeuralStateSpace(n_x, n_u, hidden_size=64, init_small=True)[source]

A state-space model to represent the cascaded two-tank system.

Parameters:
  • hidden_size – (int, optional): Number of input features in the hidden layer. Default: 0

  • init_small – (boolean, optional): If True, initialize to a Gaussian with mean 0 and std 10^-4. Default: True

class torchid.ss.dt.models.LinearOutput(n_x, n_y, bias=False)[source]

Output mapping modeled as a linear function in x.

The model has structure:

\[\begin{aligned} y_{k} = Cx_k. \end{aligned}\]
class torchid.ss.dt.models.NeuralOutput(n_x, n_y, hidden_size=16)[source]

Output mapping modeled as a feed-forward neural network in x.

The model has structure:

\[\begin{aligned} y_{k} = \mathcal{N}(x_k). \end{aligned}\]
class torchid.ss.dt.models.NeuralLinOutput(n_x, n_y, hidden_size=16)[source]

Output mapping modeled as a feed-forward neural network in x.

The model has structure:

\[\begin{aligned} y_{k} = \mathcal{N}(x_k). \end{aligned}\]
class torchid.ss.dt.models.ChannelsOutput(channels)[source]

Output mapping corresponding to a specific state channel.

Discrete-time simulators

class torchid.ss.dt.simulator.StateSpaceSimulator(f_xu, g_x=None, batch_first=False)[source]

Discrete-time state-space simulator.

Parameters:
  • f_xu (nn.Module) – The neural state-space model.

  • batch_first (bool) – If True, first dimension is batch.

Inputs: x_0, u
  • x_0: tensor of shape \((N, n_{x})\) containing the initial hidden state for each element in the batch. Defaults to zeros if (h_0, c_0) is not provided.

  • input: tensor of shape \((L, N, n_{u})\) when batch_first=False or \((N, L, n_{x})\) when batch_first=True containing the input sequence

Outputs: x
  • x: tensor of shape \((L, N, n_{x})\) corresponding to the simulated state sequence.

Examples:

>>> ss_model = NeuralStateSpaceModel(n_x=3, n_u=2)
>>> nn_solution = StateSpaceSimulator(ss_model)
>>> x0 = torch.randn(64, 3)
>>> u = torch.randn(100, 64, 2)
>>> x = nn_solution(x0, u)
>>> print(x.size())
torch.Size([100, 64, 3])