Skip to content

Commit

Permalink
fix: add stabilizer for communalities during rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicrie committed Aug 25, 2022
1 parent 8b75271 commit 462f2fe
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions xeofs/utils/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def varimax(
# Normalize the matrix using square root of the sum of squares (Kaiser)
h = np.sqrt(np.sum(X * X.conjugate(), axis=1))
# A = np.diag(1./h) @ A
X = (1. / h)[:, np.newaxis] * X

# Add a stabilizer to avoid zero communalities
eps = 1e-9
X = (1. / (h + eps))[:, np.newaxis] * X

# Seek for rotation matrix based on varimax criteria
delta = 0.
Expand Down Expand Up @@ -138,7 +141,9 @@ def promax(

# Pre-normalization by communalities (sum of squared rows)
h = np.sqrt(np.sum(X * X.conjugate(), axis=1))
X = (1. / h)[:, np.newaxis] * X
# Add a stabilizer to avoid zero communalities
eps = 1e-9
X = (1. / (h + eps))[:, np.newaxis] * X

# Max-normalisation of columns
Xnorm = X / np.max(abs(X), axis=0)
Expand Down

0 comments on commit 462f2fe

Please sign in to comment.