Commit b657b05
test(decomposition): add integration tests for 7 matrix decompositions (#674)
* test(decomposition): add integration tests for 7 matrix decompositions (#620)
Add comprehensive integration tests for previously untested decompositions:
- GramSchmidtDecomposition (Classical and Modified variants)
- NmfDecomposition (Non-negative Matrix Factorization)
- IcaDecomposition (Independent Component Analysis)
- CramerDecomposition (Cramer's rule for linear systems)
- NormalDecomposition (Normal equation method)
- ComplexMatrixDecomposition (Complex number wrapper)
- TakagiDecomposition (Takagi factorization with multiple algorithms)
Tests verify: decomposition correctness, Solve/Invert functionality,
algorithm variants, error handling, and numerical properties.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix(decomposition): fix bugs found during integration testing
- CholeskyDecomposition: use tolerance-based symmetry validation instead
of exact floating-point comparison to handle A^T*A numerical errors
- CramerDecomposition: add base case for 0×0 matrix determinant (returns 1
by empty product convention) to fix 1×1 matrix inversion
- TakagiDecomposition: fix singular value calculation to use |eigenvalue|
instead of sqrt(|eigenvalue|), and fix Solve method to use correct
matrix operations x = U * S^(-1) * U^H * b
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* fix: correct takagi decomposition jacobi algorithm
- Fix tau formula: use diff = (app - aqq) instead of (aqq - app)
The correct formula for zeroing A'[p,q] is tan(2θ) = 2*apq / (app - aqq)
- Fix t formula: use t = tau / (sqrt(1 + tau²) + 1) [stable form]
Previous formula t = 1 / (|tau| + sqrt(1 + tau²)) was incorrect
- Add proper handling for equal diagonal elements (45-degree rotation)
- Add detailed comments explaining the Jacobi rotation formulas
- Update V' eigenvector accumulation with correct formulas
- Build U matrix with proper phase handling for negative eigenvalues
- Update test to expect correct singular values (eigenvalue magnitudes,
not square roots)
The Jacobi algorithm now correctly preserves eigenvalues and produces
accurate reconstruction (error ~1e-14 machine precision).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* docs: fix comment in cholesky validation
Correct comment from "relative tolerance" to "absolute tolerance"
to accurately describe the 1e-10 tolerance used for symmetry checking.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* test: improve decomposition integration tests
- Add 1x1 matrix inversion test for Cramer (enabled by 0x0 determinant fix)
- Fix unused parameters in Theory test signatures (NMF, Normal)
- Improve test names for GramSchmidt and ICA to better describe behavior
- Use relative tolerance assertions in NMF convergence tests
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
* test: improve takagi solve and invert tests to verify correctness
- Solve test now verifies A * x ≈ b, not just finite values
- Invert test now verifies A * A^-1 ≈ I, not just finite values
Addresses PR review comments about proper solution verification.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>
---------
Co-authored-by: Claude Opus 4.5 <[email protected]>1 parent 59d3be8 commit b657b05
File tree
10 files changed
+3205
-32
lines changed- src/DecompositionMethods/MatrixDecomposition
- tests/AiDotNet.Tests/IntegrationTests/AdvancedLinearAlgebra
10 files changed
+3205
-32
lines changedLines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
133 | 137 | | |
134 | | - | |
| 138 | + | |
| 139 | + | |
135 | 140 | | |
136 | 141 | | |
137 | 142 | | |
| |||
168 | 173 | | |
169 | 174 | | |
170 | 175 | | |
171 | | - | |
| 176 | + | |
172 | 177 | | |
173 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
174 | 184 | | |
175 | 185 | | |
176 | 186 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
140 | 147 | | |
141 | 148 | | |
142 | 149 | | |
| |||
Lines changed: 167 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
155 | | - | |
| 156 | + | |
156 | 157 | | |
157 | 158 | | |
158 | 159 | | |
159 | | - | |
160 | | - | |
161 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
162 | 165 | | |
163 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
164 | 186 | | |
165 | | - | |
166 | | - | |
167 | 187 | | |
168 | | - | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
169 | 203 | | |
170 | 204 | | |
171 | 205 | | |
| |||
178 | 212 | | |
179 | 213 | | |
180 | 214 | | |
181 | | - | |
182 | | - | |
| 215 | + | |
| 216 | + | |
183 | 217 | | |
184 | 218 | | |
185 | 219 | | |
186 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
187 | 223 | | |
188 | 224 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
195 | 229 | | |
196 | 230 | | |
197 | 231 | | |
198 | | - | |
199 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
200 | 237 | | |
201 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
202 | 258 | | |
203 | 259 | | |
204 | 260 | | |
| |||
358 | 414 | | |
359 | 415 | | |
360 | 416 | | |
361 | | - | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
362 | 420 | | |
363 | 421 | | |
364 | 422 | | |
| |||
521 | 579 | | |
522 | 580 | | |
523 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
524 | 585 | | |
525 | | - | |
526 | 586 | | |
527 | | - | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
528 | 612 | | |
529 | 613 | | |
530 | 614 | | |
| |||
541 | 625 | | |
542 | 626 | | |
543 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
544 | 632 | | |
545 | 633 | | |
546 | 634 | | |
547 | | - | |
548 | | - | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
549 | 669 | | |
550 | | - | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
551 | 690 | | |
552 | | - | |
553 | | - | |
| 691 | + | |
554 | 692 | | |
555 | 693 | | |
0 commit comments