示例#1
0
    def get_S(self, dimensions=2, pub=None):
        similarity = self.get_similarity(self.statistic)
        if pub is not None:
            pub.array_as_image('similarity', similarity,
                               caption='Similarity statistic')
            plot_spectrum(pub, 'similarity', similarity)

        if self.scale_score:
            R = scale_score(similarity).astype('float32')
            R = R / R.max()
            if pub is not None:
                pub.array_as_image('scale_score', R)

        else:
            R = similarity

        D = 1 - R
        D = D * np.pi / D.max()
        np.fill_diagonal(D, 0)

        if pub is not None:
            #            pub.array_as_image('D', D)
            P = D * D
            B = double_center(P)
            #            plot_spectrum(pub, 'D', D)
            #            plot_spectrum(pub, 'P', P)
            plot_spectrum(pub, 'B', B)

        S = mds(D, ndim=dimensions)
#        S = inner_product_embedding(similarity, 3)
#        S = S[1:3, :]
        return S
示例#2
0
def mds_test():
    for n in [10, 100]:
        for k in [3, 4, 5]:
            P = np.random.rand(k, n)
            D = euclidean_distances(P)
            P2 = mds(D, ndim=k)
            error = evaluate_error(P, P2)
            assert_allclose(0, error, atol=1e-7)
示例#3
0
def mds_test():
    for n in [10, 100]:
        for k in [3, 4, 5]:
            P = np.random.rand(k, n)
            D = euclidean_distances(P)
            P2 = mds(D, ndim=k)
            error = evaluate_error(P, P2)
            assert_allclose(0, error, atol=1e-7)
示例#4
0
文件: classic_mds.py 项目: afcarl/cbc
    def _solve(self, R):
        ndim = self.params['ndim']

        D0 = R.max() - R
        np.testing.assert_almost_equal(D0.min(), 0)
        np.testing.assert_allclose(D0[0, 0], 0)

        S = mds(D0, ndim)
        self.iteration(dict(S=S))
示例#5
0
    def get_embedding(self, R, ndim):
        D = 1 - R
        D = D * np.pi / D.max()
        np.fill_diagonal(D, 0)

#        if pub is not None:
#            P = D * D
#            B = double_center(P)
#            plot_spectrum(pub, 'B', B)

        S = mds(D, ndim=ndim)
        return S
def get_embedding_mds(plans, D, ndim):
    """ Returns a dictionary plan -> position """
    plan2index = dict([(p, i) for i, p in enumerate(plans)])
    p2 = mds(D, ndim)
    plan2point = dict([(p, p2[:, plan2index[p]]) for p in plans])
    return plan2point
示例#7
0
def get_embedding_mds(plans, D, ndim):
    """ Returns a dictionary plan -> position """
    plan2index = dict([(p, i) for i, p in enumerate(plans)])
    p2 = mds(D, ndim)
    plan2point = dict([(p, p2[:, plan2index[p]]) for p in plans])
    return plan2point