Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@aarmey
Copy link
Contributor

@aarmey aarmey commented Aug 1, 2024

This adds a function for deriving an approximate joint diagonalization for a set of matrices. This function is the basis of solvers that derive PARAFAC factorization by diagonalizing the Tucker decomposition. By using only a few iterations, this can also be used to improve the starting estimate for initializing PARAFAC.

@aarmey aarmey self-assigned this Aug 1, 2024
@aarmey aarmey changed the title [WIP] Approximate joint diagonalization Approximate joint diagonalization Aug 1, 2024
@JeanKossaifi
Copy link
Member

Really excited to have this in TensorLy @aarmey, it's a neat method!
We could almost have a separate PR for the backend cleanup (though fine to have it here too!).

Copy link
Member

@JeanKossaifi JeanKossaifi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Just left some notes in the code.



def jointdiag(
X,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd name this matrices or matrices_tensor - X makes me think it's a single matrix at first glance (though granted should read the docstring).

print(f"Sweep # 0: e = {e:.3e}")

# Additional output parameters
Q_total = tl.eye(D)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for these intermediate variables: it would be helpful to give them intuitive names

for k in range(max_iter):
# loop over all pairs of slices
for p, q in combinations(range(D), 2):
# Finds matrix slice with greatest variability among diagonal elements
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just refer to them as matrices rather than matrix slice everywhere when we talk of an element X[:, :, j] ?

+ tl.norm(Xh[all_but_pq, p]) ** 2
+ tl.norm(Xh[all_but_pq, q]) ** 2
)
xih = Xh[p, q] - Xh[q, p]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, the name isn't super helpful


T. Fu and X. Gao, “Simultaneous diagonalization with similarity transformation for
non-defective matrices”, in Proc. IEEE International Conference on Acoustics, Speech
and Signal Processing (ICASSP 2006), vol. IV, pp. 1137-1140, Toulouse, France, May 2006.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it as a proper reference [1]_ and add it a reference section of the doctoring (see e.g.

.. [3] Casey Battaglino, Grey Ballard and Tamara G. Kolda,
)

for i in range(k):
temp_diag = np.diag(rng.randn(d))
diags[:, :, i] = temp_diag
synthetic[:, :, i] = np.linalg.inv(mixing) @ temp_diag @ mixing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually quite useful to understand the type of mixing allowed: might be useful to have a short Notes section in the doctoring to explain what kind of scrambling the algorithm supports and roughly what it does?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants