Ejemplo n.º 1
0
 def test_subset_descriptor(self):
     import numpy as np
     from pyrsa.util.descriptor_utils import subset_descriptor
     descriptors = {'foo': ['bar', 'bar2']}
     self.assertEqual(subset_descriptor(descriptors, 0), {'foo': ['bar']})
     self.assertEqual(
         subset_descriptor(descriptors, np.array([True, False])),
         {'foo': ['bar']})
     self.assertEqual(subset_descriptor(descriptors, (0, 1)),
                      {'foo': ['bar', 'bar2']})
Ejemplo n.º 2
0
    def subset_time(self, by, t_from, t_to):
        """ Returns a subsetted TemporalDataset with time between t_from to t_to

        Args:
            by(String): the descriptor by which the subset selection is
                made from channel dimension
            t_from: time-point from which onwards data should be subsetted
            t_to: time-point until which data should be subsetted

        Returns:
            TemporalDataset, with subset defined by the selected time_descriptor
        """

        time = get_unique_unsorted(self.time_descriptors[by])
        sel_time = [t for t in time if t <= t_to and t>=t_from]

        selection = bool_index(self.time_descriptors[by], sel_time)
        measurements = self.measurements[:, :, selection]
        descriptors = self.descriptors
        obs_descriptors = self.obs_descriptors
        channel_descriptors = self.channel_descriptors
        time_descriptors = subset_descriptor(
            self.time_descriptors, selection)
        dataset = TemporalDataset(measurements=measurements,
                              descriptors=descriptors,
                              obs_descriptors=obs_descriptors,
                              channel_descriptors=channel_descriptors,
                              time_descriptors=time_descriptors)
        return dataset
Ejemplo n.º 3
0
    def subset_channel(self, by, value):
        """ Returns a subsetted TemporalDataset defined by certain channel value

        Args:
            by(String): the descriptor by which the subset selection is
                made from channel dimension
            value:      the value by which the subset selection is made
                from channel dimension

        Returns:
            TemporalDataset, with subset defined by the selected channel_descriptor

        """
        selection = bool_index(self.channel_descriptors[by], value)
        measurements = self.measurements[:, selection]
        descriptors = self.descriptors
        obs_descriptors = self.obs_descriptors
        channel_descriptors = subset_descriptor(
            self.channel_descriptors, selection)
        time_descriptors = self.time_descriptors
        dataset = TemporalDataset(measurements=measurements,
                              descriptors=descriptors,
                              obs_descriptors=obs_descriptors,
                              channel_descriptors=channel_descriptors,
                              time_descriptors=time_descriptors)
        return dataset
Ejemplo n.º 4
0
    def split_time(self, by):
        """ Returns a list TemporalDataset splited by time

        Args:
            by(String): the descriptor by which the splitting is made

        Returns:
            list of TemporalDataset,  splitted by the selected time_descriptor
        """

        time = get_unique_unsorted(self.time_descriptors[by])
        dataset_list = []
        for v in time:
            selection = (self.time_descriptors[by] == v)
            measurements = self.measurements[:, :, selection]
            descriptors = self.descriptors
            obs_descriptors = self.obs_descriptors
            channel_descriptors = self.channel_descriptors
            time_descriptors = subset_descriptor(
                self.time_descriptors, selection)
            dataset = TemporalDataset(measurements=measurements,
                                  descriptors=descriptors,
                                  obs_descriptors=obs_descriptors,
                                  channel_descriptors=channel_descriptors,
                                  time_descriptors=time_descriptors)
            dataset_list.append(dataset)
        return dataset_list
Ejemplo n.º 5
0
    def split_channel(self, by):
        """ Returns a list TemporalDataset splited by channels

        Args:
            by(String): the descriptor by which the splitting is made

        Returns:
            list of TemporalDataset,  splitted by the selected channel_descriptor
        """
        unique_values = get_unique_unsorted(self.channel_descriptors[by])
        dataset_list = []
        for v in unique_values:
            selection = (self.channel_descriptors[by] == v)
            measurements = self.measurements[:, selection, :]
            descriptors = self.descriptors.copy()
            descriptors[by] = v
            obs_descriptors = self.obs_descriptors
            channel_descriptors = subset_descriptor(
                self.channel_descriptors, selection)
            time_descriptors = self.time_descriptors
            dataset = TemporalDataset(measurements=measurements,
                                  descriptors=descriptors,
                                  obs_descriptors=obs_descriptors,
                                  channel_descriptors=channel_descriptors,
                                  time_descriptors=time_descriptors)
            dataset_list.append(dataset)
        return dataset_list
Ejemplo n.º 6
0
    def sort_by(self, by):
        """ sorts the dataset by a given observation descriptor

        Args:
            by(String): the descriptor by which the dataset shall be sorted

        Returns:
            ---

        """
        desc = self.obs_descriptors[by]
        order = np.argsort(desc)
        self.measurements = self.measurements[order]
        self.obs_descriptors = subset_descriptor(self.obs_descriptors, order)
Ejemplo n.º 7
0
 def __getitem__(self, idx):
     """
     allows indexing with []
     and iterating over RDMs with `for rdm in rdms:`
     """
     idx = np.array(idx)
     dissimilarities = self.dissimilarities[idx].reshape(
         -1, self.dissimilarities.shape[1])
     rdm_descriptors = subset_descriptor(self.rdm_descriptors, idx)
     rdms = RDMs(dissimilarities,
                 dissimilarity_measure=self.dissimilarity_measure,
                 descriptors=self.descriptors,
                 rdm_descriptors=rdm_descriptors,
                 pattern_descriptors=self.pattern_descriptors)
     return rdms
Ejemplo n.º 8
0
    def subset_obs(self, by, value):
        """ Returns a subsetted Dataset defined by certain obs value

        Args:
            by(String): the descriptor by which the subset selection
                is made from obs dimension
            value:      the value by which the subset selection is made
                from obs dimension

        Returns:
            Dataset, with subset defined by the selected obs_descriptor

        """
        selection = bool_index(self.obs_descriptors[by], value)
        measurements = self.measurements[selection, :]
        descriptors = self.descriptors
        obs_descriptors = subset_descriptor(
            self.obs_descriptors, selection)
        channel_descriptors = self.channel_descriptors
        dataset = Dataset(measurements=measurements,
                          descriptors=descriptors,
                          obs_descriptors=obs_descriptors,
                          channel_descriptors=channel_descriptors)
        return dataset
Ejemplo n.º 9
0
    def split_obs(self, by):
        """ Returns a list Datasets splited by obs

        Args:
            by(String): the descriptor by which the splitting is made

        Returns:
            list of Datasets, splitted by the selected obs_descriptor
        """
        unique_values = get_unique_unsorted(self.obs_descriptors[by])
        dataset_list = []
        for v in unique_values:
            selection = (self.obs_descriptors[by] == v)
            measurements = self.measurements[selection, :]
            descriptors = self.descriptors
            obs_descriptors = subset_descriptor(
                self.obs_descriptors, selection)
            channel_descriptors = self.channel_descriptors
            dataset = Dataset(measurements=measurements,
                              descriptors=descriptors,
                              obs_descriptors=obs_descriptors,
                              channel_descriptors=channel_descriptors)
            dataset_list.append(dataset)
        return dataset_list