Disambiguate the sign (phase) of the mSSA PCs #110
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Signs of SVD left and right singular values have ambiguous signs. Subsequent SVD invocations in
expMSSA
can result in PCs with different signs (i.e. pi radians out of phase).Fix
Choose signs of the vectors in the eigen triple based on their squared-norm-weight projection on the original data matrix (either the trajectory or covariance matrix, in our case).
Comments
The algorithm is implemented in a helper function called
SvdSignChoice
. This routine has been checked by decomposing a run of random matrices and confirming that the algorithm reconstructs the input data to machine precision after the sign choice is applied.There is one big down side: this literal algorithm is slow since it's passing through the entire trajectory matrix. I have tried to speed this up by striding the sampling the trajectory so that the number of samples equals the rank rather than a full computation. But the resulting inefficiency was large, so it wasn't helpful.
The addition to
expMSSA
is then trivial. I have included a config flag,Sign
to turn this algorithm on and off, if need be. It is nowon
by default. Code has been tested on thepyEXP-examples/Tutorials/mSSA
notebooks.