Esempio n. 1
0
 def test_seed_returns_identically(self):
     for A in self.test_matrices:
         for seed in self.seeds:
             sketch1 = clarkson_woodruff_transform(A,
                                                   self.n_sketch_rows,
                                                   seed=seed)
             sketch2 = clarkson_woodruff_transform(A,
                                                   self.n_sketch_rows,
                                                   seed=seed)
             if issparse(sketch1):
                 sketch1 = sketch1.toarray()
             if issparse(sketch2):
                 sketch2 = sketch2.toarray()
             assert_equal(sketch1, sketch2)
Esempio n. 2
0
 def test_seed_returns_identically(self):
     for A in self.test_matrices:
         for seed in self.seeds:
             sketch1 = clarkson_woodruff_transform(
                 A, self.n_sketch_rows, seed=seed
             )
             sketch2 = clarkson_woodruff_transform(
                 A, self.n_sketch_rows, seed=seed
             )
             if issparse(sketch1):
                 sketch1 = sketch1.todense()
             if issparse(sketch2):
                 sketch2 = sketch2.todense()
             assert_equal(sketch1, sketch2)
Esempio n. 3
0
 def test_sketch_dimensions(self):
     for A in self.test_matrices:
         for seed in self.seeds:
             sketch = clarkson_woodruff_transform(A,
                                                  self.n_sketch_rows,
                                                  seed=seed)
             assert_(sketch.shape == (self.n_sketch_rows, self.n_cols))
Esempio n. 4
0
 def test_sketch_dimensions(self):
     for A in self.test_matrices:
         for seed in self.seeds:
             sketch = clarkson_woodruff_transform(
                 A, self.n_sketch_rows, seed=seed
             )
             assert_(sketch.shape == (self.n_sketch_rows, self.n_cols))
Esempio n. 5
0
    def test_sketch_preserves_vector_norm(self):
        n_errors = 0
        n_sketch_rows = int(np.ceil(2. / (0.01 * 0.5**2)))
        true_norm = np.linalg.norm(self.x)
        for seed in self.seeds:
            sketch = clarkson_woodruff_transform(
                self.x, n_sketch_rows, seed=seed,
            )
            sketch_norm = np.linalg.norm(sketch)

            if np.abs(true_norm - sketch_norm) > 0.5 * true_norm:
                n_errors += 1
        assert_(n_errors == 0)
Esempio n. 6
0
    def test_sketch_preserves_vector_norm(self):
        n_errors = 0
        n_sketch_rows = int(np.ceil(2. / (0.01 * 0.5**2)))
        true_norm = np.linalg.norm(self.x)
        for seed in self.seeds:
            sketch = clarkson_woodruff_transform(
                self.x, n_sketch_rows, seed=seed,
            )
            sketch_norm = np.linalg.norm(sketch)

            if np.abs(true_norm - sketch_norm) > 0.5 * true_norm:
                n_errors += 1
        assert_(n_errors == 0)
Esempio n. 7
0
    def test_sketch_rows_norm(self):
        # Given the probabilistic nature of the sketches
        # we run the 'test' multiple times and check that
        # we pass all/almost all the tries
        n_errors = 0

        seeds = [
            1755490010, 934377150, 1391612830, 1752708722, 2008891431,
            1302443994, 1521083269, 1501189312, 1126232505, 1533465685
        ]

        for seed_ in seeds:
            sketch = clarkson_woodruff_transform(self.dense_big_matrix,
                                                 self.n_sketch_rows, seed_)

            # We could use other norms (like L2)
            err = np.linalg.norm(
                self.dense_big_matrix) - np.linalg.norm(sketch)
            if err > self.threshold:
                n_errors += 1

        assert_(n_errors == 0)
Esempio n. 8
0
    def test_sketch_preserves_frobenius_norm(self):
        # Given the probabilistic nature of the sketches
        # we run the test multiple times and check that
        # we pass all/almost all the tries.
        n_errors = 0
        for A in self.test_matrices:
            if issparse(A):
                true_norm = norm(A)
            else:
                true_norm = np.linalg.norm(A)
            for seed in self.seeds:
                sketch = clarkson_woodruff_transform(
                    A, self.n_sketch_rows, seed=seed,
                )
                if issparse(sketch):
                    sketch_norm = norm(sketch)
                else:
                    sketch_norm = np.linalg.norm(sketch)

                if np.abs(true_norm - sketch_norm) > 0.1 * true_norm:
                    n_errors += 1
        assert_(n_errors == 0)
Esempio n. 9
0
    def test_sketch_preserves_frobenius_norm(self):
        # Given the probabilistic nature of the sketches
        # we run the test multiple times and check that
        # we pass all/almost all the tries.
        n_errors = 0
        for A in self.test_matrices:
            if issparse(A):
                true_norm = norm(A)
            else:
                true_norm = np.linalg.norm(A)
            for seed in self.seeds:
                sketch = clarkson_woodruff_transform(
                    A, self.n_sketch_rows, seed=seed,
                )
                if issparse(sketch):
                    sketch_norm = norm(sketch)
                else:
                    sketch_norm = np.linalg.norm(sketch)

                if np.abs(true_norm - sketch_norm) > 0.1 * true_norm:
                    n_errors += 1
        assert_(n_errors == 0)
Esempio n. 10
0
    def test_sketch_dimensions(self):
        sketch = clarkson_woodruff_transform(self.dense_big_matrix,
                                             self.n_sketch_rows)

        assert_(sketch.shape == (self.n_sketch_rows,
                                 self.dense_big_matrix.shape[1]))