Exemple #1
0
def test_mvtsne_error():
    # Data and is_distane do not have the same length.
    one = np.arange(25, dtype=float).reshape((5, 5))
    two = np.arange(25, 50, dtype=float).reshape((5, 5))
    data = [one, two]
    is_distance = [False, False, False]

    mvtsne_est = mvtsne.MvtSNE(k=2)
    assert_raises(ValueError, mvtsne_est.fit, data, is_distance)

    # Sample data matrices do not have the same number of rows
    one = np.arange(25, dtype=float).reshape((5, 5))
    two = np.arange(25, 49, dtype=float).reshape((4, 6))
    data = [one, two]
    is_distance = [False, False]

    mvtsne_est = mvtsne.MvtSNE(k=2)
    assert_raises(ValueError, mvtsne_est.fit, data, is_distance)

    # k value cannot be negative
    one = np.arange(25, dtype=float).reshape((5, 5))
    two = np.arange(25, 50, dtype=float).reshape((5, 5))
    data = [one, two]
    is_distance = [False, False]

    mvtsne_est = mvtsne.MvtSNE(k=-2)
    assert_raises(ValueError, mvtsne_est.fit, data, is_distance)
Exemple #2
0
def test_mvtsne():
    one = np.arange(25, dtype=float).reshape((5, 5))
    two = np.arange(25, 50, dtype=float).reshape((5, 5))
    data = [one, two]
    is_distance = [False, False]

    mvtsne_est = mvtsne.MvtSNE(k=2)
    mvtsne_est.fit(data, is_distance)
Exemple #3
0
    def getEmbedding(self, rd_state=3):
        """
		use multiview tsne to embed the components to 2d plane
		type rd_state: int: random state
		"""
        self.rd_state = rd_state
        is_distance = [False] * len(self.data)
        mvtsne_est = mvtsne.MvtSNE(k=2,
                                   perplexity=10,
                                   random_state=self.rd_state,
                                   epoch=3000)
        mvtsne_est.fit(self.data, is_distance)
        self.X_embedded = np.asarray(mvtsne_est.embedding_)
Exemple #4
0
    def savePatternEmbedding(self):
        self.loadFactors()

        self.data = [
            np.array([
                self.factors[i][j].tolist() for i in range(len(self.factors))
            ]) for j in range(self.column_cnt)
        ]
        is_distance = [False] * len(self.data)
        mvmds_est = mvmds.MVMDS(k=2)
        self.factor_embeddings = {}
        mvmds_est.fit(self.data, is_distance)
        self.factor_embeddings['mds'] = mvmds_est.components_.tolist()

        self.rd_state = 5
        is_distance = [False] * len(self.data)
        mvtsne_est = mvtsne.MvtSNE(k=2,
                                   perplexity=10,
                                   random_state=self.rd_state,
                                   epoch=3000)
        mvtsne_est.fit(self.data, is_distance)
        self.factor_embeddings['tsne'] = np.asarray(
            mvtsne_est.embedding_).tolist()

        mvsc_est = mvsc.MVSC(k=2)
        mvsc_est.fit(self.data, is_distance)
        self.factor_embeddings['sc'] = np.asarray(mvsc_est.evectors_).tolist()

        # cpc_est = cpcmv.MVCPC(k=2)
        # self.factor_embeddings['sc'] = cpc_est.fit(self.data)[1].tolist()

        with open(
                '/home/xidao/project/thesis/iFac/src/src/data/' + self.domain +
                '/factors_' + str(self.column_cnt) + '_' + str(self.cur_base) +
                '_sample_pattern_embedding.json', 'w') as fp:
            json.dump(self.factor_embeddings, fp)