Ejemplo n.º 1
0
class DSMMeasure(Measure):
    """DSMMeasure creates a Measure object
       where metric can be one of 'euclidean', 'spearman', 'pearson'
       or 'confusion'"""
    def __init__(self, dsmatrix, dset_metric, output_metric='spearman'):
        Measure.__init__(self)

        self.dsmatrix = dsmatrix
        self.dset_metric = dset_metric
        self.output_metric = output_metric
        self.dset_dsm = []

    def __call__(self, dataset):
        # create the dissimilarity matrix for the data in the input dataset
        self.dset_dsm = DSMatrix(dataset.samples, self.dset_metric)

        in_vec = self.dsmatrix.get_vector_form()
        dset_vec = self.dset_dsm.get_vector_form()

        # concatenate the two vectors, send to dissimlarity function
        test_mat = np.asarray([in_vec, dset_vec])

        test_dsmatrix = DSMatrix(test_mat, self.output_metric)

        # return correct dissimilarity value
        return test_dsmatrix.get_full_matrix()[0, 1]
Ejemplo n.º 2
0
class DSMMeasure(Measure):
    """DSMMeasure creates     a Measure object
       where metric can be one of 'euclidean', 'spearman', 'pearson'
       or 'confusion'"""

    def __init__(self, dsmatrix, dset_metric, output_metric="spearman"):
        Measure.__init__(self)

        self.dsmatrix = dsmatrix
        self.dset_metric = dset_metric
        self.output_metric = output_metric
        self.dset_dsm = []

    def __call__(self, dataset):
        # create the dissimilarity matrix for the data in the input dataset
        self.dset_dsm = DSMatrix(dataset.samples, self.dset_metric)

        in_vec = self.dsmatrix.get_vector_form()
        dset_vec = self.dset_dsm.get_vector_form()

        # concatenate the two vectors, send to dissimlarity function
        test_mat = np.asarray([in_vec, dset_vec])

        test_dsmatrix = DSMatrix(test_mat, self.output_metric)

        # return correct dissimilarity value
        return test_dsmatrix.get_full_matrix()[0, 1]
Ejemplo n.º 3
0
    def _call(self, dataset):
        # compute rsm
        dsm = DSMatrix(dataset.samples, metric=self.metric)
        vec_form = samples = dsm.get_vector_form()

        n = dsm.full_matrix.shape[0]

        # mask for upper diagonal
        msk = np.asarray([[i > j for i in xrange(n)] for j in xrange(n)])

        # compute z scores
        arr = np.reshape(np.asarray(dsm.full_matrix[msk]), (-1, ))
        arr_z = (arr - np.mean(arr)) / np.std(arr)

        # set the space
        ds = Dataset(samples=arr_z)
        if not self.space is None:
            space_vals = dataset.sa[self.space].value
            labels = [
                '%s-%s' % (space_vals[i], space_vals[j]) for i in xrange(n)
                for j in xrange(n) if msk[i, j]
            ]
            ds.sa[self.space] = labels

        return ds
Ejemplo n.º 4
0
    def _call(self, dataset):
        # compute rsm 
        dsm = DSMatrix(dataset.samples, metric=self.metric)
        vec_form = samples = dsm.get_vector_form()

        n = dsm.full_matrix.shape[0]

        # mask for upper diagonal
        msk = np.asarray([[i > j for i in xrange(n)] for j in xrange(n)])

        # compute z scores        
        arr = np.reshape(np.asarray(dsm.full_matrix[msk]), (-1,))
        arr_z = (arr - np.mean(arr)) / np.std(arr)

        # set the space
        ds = Dataset(samples=arr_z)
        if not self.space is None:
            space_vals = dataset.sa[self.space].value
            labels = ['%s-%s' % (space_vals[i], space_vals[j])
                        for i in xrange(n) for j in xrange(n) if msk[i, j]]
            ds.sa[self.space] = labels

        return ds