Esempio n. 1
0
 def _post_train_calls(self):
     """ Function calls to perform after training, such as computing eigenvectors """
     if self.components > 0:
         self.svd_res = compute_principal_components(
             self.sv.vectors, components=self.components)
         remove_principal_components(self.sv.vectors,
                                     svd_res=self.svd_res,
                                     inplace=True)
     else:
         self.svd_res = 0
         logger.info(f"no removal of principal components")
Esempio n. 2
0
 def _post_train_calls(self):
     """ Function calls to perform after training, such as computing eigenvectors """
     if self.components > 0:
         self.svd_res = compute_principal_components(
             self.sv.vectors,
             components=self.components,
             cache_size_gb=self.cache_size_gb,
         )
         self.svd_weights = (self.svd_res[0]**2) / (self.svd_res[0]**
                                                    2).sum().astype(REAL)
         remove_principal_components(
             self.sv.vectors,
             svd_res=self.svd_res,
             weights=self.svd_weights,
             inplace=True,
         )
     else:
         self.svd_res = 0
         logger.info(f"no removal of principal components")
Esempio n. 3
0
 def test_remove_weighted_components(self):
     m = np.ones((500,10), dtype=np.float32)
     out = compute_principal_components(vectors = m)
     remove_principal_components(m, svd_res=out, weights=np.array([0.5]))
     self.assertTrue(np.allclose(0.75, m))
Esempio n. 4
0
 def test_remove_components(self):
     m = np.ones((500,10), dtype=np.float32)
     out = compute_principal_components(vectors = m)
     res = remove_principal_components(m, svd_res=out, inplace=False)
     self.assertTrue(np.allclose(1., res, atol=1e-5))
 def test_compute_large_components(self):
     m = np.random.uniform(size=(int(2e6), 100)).astype(np.float32)
     out = compute_principal_components(vectors=m, cache_size_gb=0.2)
     self.assertEqual(2, len(out))
     self.assertEqual(1, len(out[1]))
     self.assertEqual(np.float32, out[1].dtype)