def __init__(self, kernel_type, projection=False, **params): self.kernel_type = kernel_type self.projection = projection self.params_keys = set(params.keys()) self.__check_args_coherence() # Sampling self.sampling_mode = 'GS' # Gram-Schmidt self.list_of_samples = [] # when using .sample_k_dpp_* self.size_k_dpp = None self.E_poly = None # evaluation of the # Attributes relative to K correlation kernel: # K, K_eig_vals, K_eig_vecs, A_zono self.K = is_symmetric(params.get('K', None)) if self.projection: self.K = is_projection(self.K) e_vals, e_vecs = params.get('K_eig_dec', [None, None]) if self.projection: self.K_eig_vals = is_equal_to_O_or_1(e_vals) else: self.K_eig_vals = is_in_01(e_vals) self.eig_vecs = is_orthonormal(e_vecs) self.A_zono = is_full_row_rank(params.get('A_zono', None)) # Attributes relative to L likelihood kernel: # L, L_eig_vals, L_eig_vecs, L_gram_factor, L_dual, L_dual_eig_vals, L_dual_eig_vecs self.L = is_symmetric(params.get('L', None)) if self.projection: self.L = is_projection(self.L) e_vals, e_vecs = params.get('L_eig_dec', [None, None]) if self.projection: self.L_eig_vals = is_equal_to_O_or_1(e_vals) else: self.L_eig_vals = is_geq_0(e_vals) if self.eig_vecs is None: # K_eig_vecs = L_eig_vecs self.eig_vecs = is_orthonormal(e_vecs) # L' "dual" likelihood kernel, L' = Phi Phi.T, Phi = L_gram_factor self.L_gram_factor = params.get('L_gram_factor', None) self.L_dual = None self.L_dual_eig_vals = None self.L_dual_eig_vecs = None if self.L_gram_factor is not None: Phi = self.L_gram_factor d, N = Phi.shape if d < N: self.L_dual = Phi.dot(Phi.T) print('L_dual = Phi Phi.T was computed: Phi (dxN) with d<N') else: if self.L is None: self.L = Phi.T.dot(Phi) print('L = Phi.T Phi was computed: Phi (dxN) with d>=N')
def test_orthonormal(self): N, rank = 30, 10 X = rndm.randn(N, rank) eig_vecs, _ = qr(X, mode="economic") self.assertTrue(np.allclose(utils.is_orthonormal(eig_vecs), eig_vecs)) with self.assertRaises(ValueError) as context: utils.is_orthonormal(X) self.assertTrue('M.T M != I' in str(context.exception))