コード例 #1
0
 def gram(self, X, Y=None, diag=False, logsp=False):
     assert (len(np.shape(X)) == 2)
     if diag:
         assert ()
     else:
         dists = eucldist(X, Y, power=2.)
     assert (not logsp)
     return np.where(dists <= self.threshold_sq_eucl_distance, self.spike,
                     self.non_spike)
コード例 #2
0
def test_eucldist():
    a, b = randn(100, 3), randn(200, 3)
    variants = ("simple", "extension")
    truth_est = []
    for (name, pow) in [("sqeuclidean", 2), ("euclidean", 1)]:
        for dist_args in [(a, b), (a, a)]:
            ground_truth = cdist(*dist_args, name)
            for v in variants:
                d = eucldist(*dist_args, power=pow, variant=v)
                assert (allclose(ground_truth, d, atol=1e-05))
コード例 #3
0
    def gram(self, X, Y=None, diag=False, logsp=False):
        assert (len(np.shape(X)) == 2)

        # if X=Y, use more efficient pdist call which exploits symmetry

        if diag:
            assert ()
        else:
            dists = eucldist(X, Y, power=1.)
        assert (not logsp)
        return exp(-2 * np.sin(np.pi * dists / self.period)**2 / self.ls**2)
コード例 #4
0
def test_eucldist():
    a, b = randn(100, 3), randn(200, 3)

    ab_cd = cdist(a, b, "sqeuclidean")
    ab_v1, ab_v2 = eucldist(a, b, power=2,
                            variant="simple"), eucldist(a,
                                                        b,
                                                        power=2,
                                                        variant="extension")

    aa_cd = cdist(a, a, "sqeuclidean")
    aa_v1, aa_v2 = eucldist(a, power=2,
                            variant="simple"), eucldist(a,
                                                        power=2,
                                                        variant="extension")

    for (ground_truth, est) in [(ab_cd, [ab_v1, ab_v2]),
                                (aa_cd, [aa_v1, aa_v2])]:
        for variant in est:
            assert (allclose(ground_truth, variant, atol=1e-05))
コード例 #5
0
    def gram(self, X, Y=None, diag=False, logsp=False):
        assert (len(np.shape(X)) == 2)
        X = X / self.period
        if Y is not None:
            Y = Y / self.period

        if diag:
            assert ()
        else:
            dists = eucldist(X, Y, power=1.)
        assert (not logsp)
        return exp(-2 * np.sin(np.pi * dists)**2 / self.ls**2)
コード例 #6
0
ファイル: rbf.py プロジェクト: ingmarschuster/JaxRK
 def gram(self, X, Y=None, diag=False, logsp=False):
     assert (len(np.shape(X)) == 2)
     inp_dim = np.shape(X)[1]
     if diag:
         if Y is None:
             sq_dists = np.zeros(X.shape[0])
         else:
             assert (X.shape == Y.shape)
             sq_dists = np.sum((X - Y)**2, 1)
     else:
         sq_dists = eucldist(X, Y, power=2.)
     return self.gram_sqdist(sq_dists, inp_dim, logsp=logsp)
コード例 #7
0
    def gram(self, X, Y=None, diag=False, logsp=False):
        assert (len(np.shape(X)) == 2)

        # if X=Y, use more efficient pdist call which exploits symmetry

        if diag:
            if Y is None:
                dists = np.zeros(X.shape[0])
            else:
                assert (X.shape == Y.shape)
                dists = np.sum((X - Y)**2, 1)
        else:
            dists = sq_dists = eucldist(X, Y, power=1.)

        rval = self._const_factor * dists - self._log_norm * np.shape(X)[1]
        if not logsp:
            return exp(rval)
        return rval