示例#1
0
    def _stack_list(data, data_labels, w):
        """Construct a numpy array by stacking arrays in a list

        Parameter
        ----------

        data : list of 2D arrays, element i has shape=[voxels_i, samples_i]
            Each element in the list contains the fMRI data of one subject for
            the classification task.

        data_labels : list of arrays of int, element i has shape=[samples_i]
            Each element in the list contains the labels for the samples in
            data.

        w : list of array, element i has shape=[voxels_i, features]
            The orthogonal transforms (mappings) :math:`W_i` for each subject.


        Returns
        -------

        data_stacked : 2D array, shape=[samples, features]
            The data samples from all subjects are stacked into a single
            2D array, where "samples" is the sum of samples_i.

        labels_stacked : array, shape=[samples,]
            The labels from all subjects are stacked into a single
            array, where "samples" is the sum of samples_i.

        weights : array, shape=[samples,]
            The number of samples of the subject that are related to that
            sample. They become a weight per sample in the MLR loss.
        """
        labels_stacked = utils.concatenate_list(data_labels)

        weights = np.empty((labels_stacked.size, ))
        data_shared = [None] * len(data)
        curr_samples = 0
        for s in range(len(data)):
            if data[s] is not None:
                subject_samples = data[s].shape[1]
                curr_samples_end = curr_samples + subject_samples
                weights[curr_samples:curr_samples_end] = subject_samples
                data_shared[s] = w[s].T.dot(data[s])
                curr_samples += data[s].shape[1]

        data_stacked = utils.concatenate_list(data_shared, axis=1).T
        return data_stacked, labels_stacked, weights
示例#2
0
    def _stack_list(data, data_labels, w):
        """Construct a numpy array by stacking arrays in a list

        Parameter
        ----------

        data : list of 2D arrays, element i has shape=[voxels_i, samples_i]
            Each element in the list contains the fMRI data of one subject for
            the classification task.

        data_labels : list of arrays of int, element i has shape=[samples_i]
            Each element in the list contains the labels for the samples in
            data.

        w : list of array, element i has shape=[voxels_i, features]
            The orthogonal transforms (mappings) :math:`W_i` for each subject.


        Returns
        -------

        data_stacked : 2D array, shape=[samples, features]
            The data samples from all subjects are stacked into a single
            2D array, where "samples" is the sum of samples_i.

        labels_stacked : array, shape=[samples,]
            The labels from all subjects are stacked into a single
            array, where "samples" is the sum of samples_i.

        weights : array, shape=[samples,]
            The number of samples of the subject that are related to that
            sample. They become a weight per sample in the MLR loss.
        """
        labels_stacked = utils.concatenate_list(data_labels)

        weights = np.empty((labels_stacked.size,))
        data_shared = [None] * len(data)
        curr_samples = 0
        for s in range(len(data)):
            if data[s] is not None:
                subject_samples = data[s].shape[1]
                curr_samples_end = curr_samples + subject_samples
                weights[curr_samples:curr_samples_end] = subject_samples
                data_shared[s] = w[s].T.dot(data[s])
                curr_samples += data[s].shape[1]

        data_stacked = utils.concatenate_list(data_shared, axis=1).T
        return data_stacked, labels_stacked, weights
示例#3
0
def test_concatenate_list():
    from brainiak.utils.utils import concatenate_list
    import numpy as np
    l = [None] * 5

    l[1] = np.array([0, 1, 2])
    l[3] = np.array([3, 4])

    r = concatenate_list(l, axis=0)

    assert np.all(np.arange(5) == r), "Invalid concatenation of a list of arrays"
示例#4
0
def test_concatenate_list():
    from brainiak.utils.utils import concatenate_list
    import numpy as np
    l = [None] * 5

    l[1] = np.array([0, 1, 2])
    l[3] = np.array([3, 4])

    r = concatenate_list(l, axis=0)

    assert np.all(
        np.arange(5) == r), "Invalid concatenation of a list of arrays"
示例#5
0
文件: sssrm.py 项目: GRSEB9S/brainiak
    def _init_classes(self, y):
        """Map all possible classes to the range [0,..,C-1]

        Parameters
        ----------

        y : list of arrays of int, each element has shape=[samples_i,]
            Labels of the samples for each subject


        Returns
        -------
        new_y : list of arrays of int, each element has shape=[samples_i,]
            Mapped labels of the samples for each subject

        ..note::
        The mapping of the classes is saved in the attribute classes_.
        """
        self.classes_ = unique_labels(utils.concatenate_list(y))
        new_y = [None] * len(y)
        for s in range(len(y)):
            new_y[s] = np.digitize(y[s], self.classes_) - 1
        return new_y
示例#6
0
    def _init_classes(self, y):
        """Map all possible classes to the range [0,..,C-1]

        Parameters
        ----------

        y : list of arrays of int, each element has shape=[samples_i,]
            Labels of the samples for each subject


        Returns
        -------
        new_y : list of arrays of int, each element has shape=[samples_i,]
            Mapped labels of the samples for each subject

        Note
        ----
            The mapping of the classes is saved in the attribute classes_.
        """
        self.classes_ = unique_labels(utils.concatenate_list(y))
        new_y = [None] * len(y)
        for s in range(len(y)):
            new_y[s] = np.digitize(y[s], self.classes_) - 1
        return new_y