ShanechiLab / PyPSID

Preferential Subspace Identification Algorithm
Other
46 stars 7 forks source link

Error in LSSM --> 'tuple' object cannot be interpreted as an integer #2

Open Fayed-Rsl opened 1 month ago

Fayed-Rsl commented 1 month ago

Hello,

I am currently using the latest version of PSID (1.2.2) installed with pip install PSID and I would like to report the following error that occured several time while I was training a PSID model.

'tuple' object cannot be interpreted as an integer

I believe that this error occur when the model is not stable, and has to do with the following block of code at line 139:

  isStable = np.max(np.abs(A_Eigs)) < 1
  if isStable:
      self.XCov = linalg.solve_discrete_lyapunov(self.A, self.Q)
      self.G = self.A @ self.XCov @ self.C.T + self.S
      self.YCov = self.C @ self.XCov @ self.C.T + self.R
      self.YCov = (self.YCov + self.YCov.T)/2
  else:
      self.XCov = np.eye(self.A.shape); self.XCov[:] = np.nan
      self.YCov = np.eye(self.C.shape); self.YCov[:] = np.nan

Assuming that the isStable condition is False, then it would run this part:

self.XCov = np.eye(self.A.shape); self.XCov[:] = np.nan

Assuming that self.A is of shape (4x4), here is an easy way to reproduce the error:

import numpy as np
# assuming 4 by 4  for A with dummy values
A = np.array( [[0, 0, 0, 0],
               [0, 0, 0, 0],
               [0, 0, 0, 0],
               [0, 0, 0, 0]]) 
XCov = np.eye(A.shape); XCov[:] = np.nan
YCov = np.eye(C.shape); YCov[:] = np.nan

Thanks for your support.

Fayed-Rsl commented 1 month ago

One way of fixing it could be to do:

XCov = np.eye(len(self.A)); XCov[:] = np.nan
YCov = np.eye(len(self.C)); YCov[:] = np.nan
mingdong-li commented 1 month ago

I met the similar problem. I am not sure whether np.eye((N,N)) works in previous version of NumPy. It could be a bug in this package or please claim the package requirement.