test_residual_completion.py

Streaming Polyphase Factor Decomposition / SKAT

test_residual_completion.py

Download original file

This is the original source text. Reading it does not run or verify the program.

Read the typeset paper

Skip source text

1 import unittest
2 import numpy as np
3 
4 from residual_completion import residual_rank_bounds, complete_residual_range, stream_complete_residual_range
5 
6 
7 class ResidualCompletionTests(unittest.TestCase):
8     def test_completed_core_matches_full_spectrum(self):
9         rng = np.random.default_rng(31)
10         A = rng.normal(size=(18, 14))
11         U = rng.normal(size=(18, 9))
12         c = complete_residual_range(A, U)
13         sv_true = np.linalg.svd(A, compute_uv=False)
14         self.assertLess(
15             np.linalg.norm(c.completed_singular_values - sv_true) / np.linalg.norm(sv_true),
16             1e-12,
17         )
18 
19     def test_rank_bounds_are_valid(self):
20         rng = np.random.default_rng(32)
21         A = rng.normal(size=(20, 15))
22         U = rng.normal(size=(20, 12))
23         Q, _ = np.linalg.qr(U, mode='reduced')
24         F = A - Q @ (Q.T @ A)
25         rank = np.linalg.matrix_rank(F, tol=1e-10)
26         b = residual_rank_bounds(A, U)
27         self.assertLessEqual(b.integer_lower_bound, rank)
28         self.assertGreaterEqual(b.orthogonal_complement_upper_bound, rank)
29 
30     def test_streamed_completion_matches_full_spectrum(self):
31         rng = np.random.default_rng(33)
32         A = rng.normal(size=(21, 17))
33         U = rng.normal(size=(21, 11))
34         truth = np.linalg.svd(A, compute_uv=False)
35         for bs in (1, 3, 7, 20):
36             c = stream_complete_residual_range(A, U, block_size=bs)
37             rel = np.linalg.norm(c.completed_singular_values-truth)/np.linalg.norm(truth)
38             self.assertLess(rel, 1e-11)
39 
40 
41 if __name__ == '__main__':
42     unittest.main(verbosity=2)

Back to source controls

Other PDFs for this work

Original file and source record

This copy matches the recorded source file. Its publication here does not change the work’s review status.

SHA-256: f2c4a6650840f7574cba61a4a15d7f197b379f8f669d6ba7b27b74102ff1ac32

Original source on GitHub

Back to Streaming Polyphase Factor Decomposition / SKAT