def topk_rbf(X, Y=None, n_neighbors=10, gamma=1e-5): nn = NearestNeighbors(n_neighbors=10, metric='euclidean', n_jobs=-1) nn.fit(X) W = -1 * mt.power(nn.kneighbors_graph(Y, mode='distance'), 2) * gamma W = mt.exp(W) assert W.issparse() return W.T
def test_pca_score(self): # Test that probabilistic PCA scoring yields a reasonable score n, p = 1000, 3 rng = np.random.RandomState(0) X = mt.tensor(rng.randn(n, p) * .1) + mt.array([3, 4, 5]) for solver in self.solver_list: pca = PCA(n_components=2, svd_solver=solver) pca.fit(X) ll1 = pca.score(X) h = -0.5 * mt.log(2 * mt.pi * mt.exp(1) * 0.1**2) * p np.testing.assert_almost_equal((ll1 / h).to_numpy(), 1, 0)