Skip to content

Fix SVD dimension mismatch and optimize matrix computations. Added detailed documentation and backward compatibility for redundant delta to alpha conversion.#3

Open
ruose1314 wants to merge 4 commits into
mainfrom
explicit_import
Open

Fix SVD dimension mismatch and optimize matrix computations. Added detailed documentation and backward compatibility for redundant delta to alpha conversion.#3
ruose1314 wants to merge 4 commits into
mainfrom
explicit_import

Conversation

@ruose1314

Copy link
Copy Markdown

Summary
Fix SVD dimension mismatch and optimize matrix computations. Added detailed documentation and backward compatibility for redundant delta_to_alpha conversion.

Main Changes:

  1. Added dimension-aware matrix handling for SVD operations:
    • For wide matrices (samples < features): slice Vt.T
    • For tall matrices (samples > features): slice U.T
  2. Maintained backward compatibility with full_matrices=True
  3. Added optimized path using full_matrices=False that avoids computing unused matrix components
  4. Added detailed documentation for copterr.py file.
  5. Ensured backward compatibility for the deltas parameter.
  6. Added explicit imports in the __init__.py file.

Technical Details:

  • Previous code assumed wide matrices (common in fMRI).
  • New code handles both wide and tall matrices correctly.
  • Setting full_matrices=False is computationally optimal but optional.

Demonstration:
See copterr/copterr_commit_demo.py for a demonstration of the behavior with different matrix shapes.

@ruose1314

Copy link
Copy Markdown
Author

It's possible in the copterr.py I could've made line 125 full_matrices = False and make all codes 172-177 deleted and only keep line 178 and make all simpler.

Problem:
- Previous implementation incorrectly grouped alpha values by feature groups rather than by voxel patterns.
- This caused dimension mismatches when indexing into the voxel space during weight computation.

Changes:
1. Modified the prepare() method in PermuteWeightsGrouped:
   - Transposed the alpha matrix (using alphas.T) to group by voxel patterns.
   - Converted the alpha values to hashable tuples to correctly compute unique values.
   - Ensured that alpha masks have a length equal to the number of voxels.

Impact:
+ Fixes dimension mismatch errors in fit_permutation.
+ Correctly groups voxels based on their regularization settings across feature spaces.
- May increase computation time and memory usage if there are many unique alpha patterns.

Note:
For large-scale applications with many unique alpha patterns, users may want to:
- Consider quantizing alpha values to reduce the number of unique groups.
- Monitor GPU memory usage.
- Explore memory management strategies if needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant