Continuous-time state-space identification

Continuous-time models

class torchid.ss.ct.models.NeuralStateSpaceModel(n_x, n_u, n_feat=64, scale_dx=1.0, init_small=True, activation='relu')[source]

A state-space continuous-time model.

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

  • n_u (int) – Number of input variables

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

  • 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 = NeuralStateSpaceModel(n_x=2, n_u=1, n_feat=64)
class torchid.ss.ct.models.MechanicalStateSpaceSystem(n_feat=64, init_small=True, typical_ts=1.0)[source]

A state-space continuous-time model for a 1-DoF mechanical system. The state-space model has two states (nx=2) and one input (nu=1). The states x0 and x1 correspond to position and velocity, respectively. The input u correspond to an input force. The derivative of position x0 is velocity x2, while the derivative of velocity is the output of a neural network with features u, x0, x1.

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

  • 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’

class torchid.ss.ct.models.StateSpaceModelLin(A, B)[source]

A state-space continuous-time model corresponding to the sum of a linear state-space model plus a non-linear part modeled as a neural network

Parameters:
  • A – (np.array): A matrix of the linear part of the model

  • B – (np.array): B matrix of the linear part of the model

class torchid.ss.ct.models.CascadedTanksNeuralStateSpaceModel(n_feat=64, scale_dx=1.0, init_small=True)[source]

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

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

  • scale_dx – (str): Scaling factor for the neural network output. Default: 1.0

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

class torchid.ss.ct.models.CascadedTanksOverflowNeuralStateSpaceModel(n_feat=64, scale_dx=1.0, init_small=True)[source]

A state-space model to represent the cascaded two-tank system, with possible overflow from the lower tank.

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

  • scale_dx – (str): Scaling factor for the neural network output. Default: 1.0

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

Continuous-time simulators

class torchid.ss.ct.simulators.ForwardEulerSimulator(ss_model, ts=1.0, batch_first=False)[source]

Forward Euler integration of a continuous-time neural state space model.

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

  • ts (np.float) – Sampling time for simulation.

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

Inputs: x_0, input
  • 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: states
  • states: 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 = ForwardEulerSimulator(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])
class torchid.ss.ct.simulators.RK4Simulator(ss_model, ts=1.0)[source]

This class implements prediction/simulation methods for a continuous SS model structure

ss_model

The neural SS model to be fitted

Type:

nn.Module

ts

model sampling time (when it is fixed)

Type:

float

scheme

Runge-Kutta scheme to be used

Type:

string