Skip to content

Instantly share code, notes, and snippets.

@yaroslavvb
Created October 21, 2019 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaroslavvb/1a258310b266ac7ade35b025c9e6fae3 to your computer and use it in GitHub Desktop.
Save yaroslavvb/1a258310b266ac7ade35b025c9e6fae3 to your computer and use it in GitHub Desktop.
def lyapunov_spectral(A, B, cond=None):
u.check_symmetric(A)
u.check_symmetric(B)
s, U = torch.symeig(A, eigenvectors=True)
if cond is None:
cond = get_condition(s.dtype)
cutoff = cond * max(s)
s = torch.where(s > cutoff, s, torch.tensor(0.).to(s.device))
C = U.t() @ B @ U # TODO(y): throw away eigenvectors corresponding to discarded evals. U=U[:num_eigs]
s = s.unsqueeze(1) + s.unsqueeze(0)
si = torch.where(s > 0, 1 / s, s)
Y = C * si
X = U @ Y @ U.t()
# cancel small asymetries introduces by multiplication by small numbers
X = (X + X.t()) / 2
return X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment