Esempio n. 1
0
    def walking_speed(self, labels, timestamps, timespan, overlap, fs):
        """
        Wrapper to output the average walking speed.

        Parameters
        ----------
        labels
           Vector of labels.
        timestamps
           Vector of timestamps.
        timespan
           Duration of metric calculation. Either 86400 (daily) or 3600 (hourly)
        overlap
           Amount of overlap for the calculation of the transfers.
        fs
           Sampling frequency.

        Returns
        -------
        metr.number_of_label_changes_per_window(labels, timestamps)
           Output the average walking speed.
        """
        metr = Metrics(timestamps, timespan, overlap, fs)
        container = metr.speed(labels, timestamps, self.adjecency)
        # TODO Why do we want the absolute values for speed, and these seem not
        # to be applied to the specified window, instead it is the raw values
        # after the apply metrics is called
        return np.abs(container), np.nanmean(np.abs(container)), np.nanmax(
            np.abs(container))
Esempio n. 2
0
    def number_of_unique_locations(self, labels, timestamps, timespan, overlap,
                                   fs):
        """
        Wrapper to output the number of unique locations per window.

        Parameters
        ----------
        labels
           Vector of labels.
        timestamps
           Vector of timestamps.
        timespan
           Duration of metric calculation. Either 86400 (daily) or 3600 (hourly)
        overlap
           Amount of overlap for the calculation of the transfers.
        fs
           Sampling frequency.

        Returns
        -------
        metr.number_of_label_changes_per_window(labels, timestamps)
           Output the number of unique locations per window.
        """
        metr = Metrics(timestamps, timespan, overlap, fs)
        container = metr.duration_of_labels_per_window(labels, timestamps)
        container = self.label_mappings(container, is_duration=False)
        return container
Esempio n. 3
0
    def duration_in_location(self, labels, timestamps, timespan, overlap, fs,
                             location):
        """
        Wrapper to output the duration studying.

        Parameters
        ----------
        labels
           Vector of labels.
        timestamps
           Vector of timestamps.
        timespan
           Duration of metric calculation. Either 86400 (daily) or 3600 (hourly)
        overlap
           Amount of overlap for the calculation of the transfers.
        fs
           Sampling frequency.
        location
            Location in which the duration is computed

        Returns
        -------
        metr.number_of_label_changes_per_window(labels, timestamps)
           Output the duration studying.
        """
        metr = Metrics(timestamps, timespan, overlap, fs)
        container = metr.duration_of_labels_per_window(labels, timestamps)
        container = self.label_mappings(container,
                                        is_duration=False,
                                        label_to_extract=location)
        return container
Esempio n. 4
0
    def duration_activity(self, labels, timestamps, timespan, overlap, fs,
                          activity):
        """
        Wrapper to output the duration walking.

        Parameters
        ----------
        labels
           Vector of labels.
        timestamps
           Vector of timestamps.
        timespan
           Duration of metric calculation. Either 86400 (daily) or 3600 (hourly)
        overlap
           Amount of overlap for the calculation of the transfers.
        fs
           Sampling frequency.

        Returns
        -------
        metr.number_of_label_changes_per_window(labels, timestamps)
           Output the duration walking.
        """
        metr = Metrics(timestamps, timespan, overlap, fs)
        container = metr.duration_of_labels_per_window(labels, timestamps)
        container = self.label_mappings(container, True, activity)
        return container
Esempio n. 5
0
    def room_transfers(self, labels, timestamps, timespan, overlap, fs):
        """
        Wrapper to output the room transfers.

        Parameters
        ----------
        labels
            Vector of labels.
        timestamps
            Vector of timestamps.
        timespan
            Duration of metric calculation. Either 86400 (daily) or 3600 (hourly)
        overlap
            Amount of overlap for the calculation of the transfers.
        fs
            Sampling frequency.

        Returns
        -------
        metr.number_of_label_changes_per_window(labels, timestamps)
            Output the room transfers.
        """

        metr = Metrics(timestamps, timespan, overlap, fs)
        container = metr.number_of_label_changes_per_window(labels, timestamps)

        return container
Esempio n. 6
0
    def test_average_activities_per_window(self):
        """
        Test average activities per window.
        """

        print('Test average activities per window.')

        winlength = 3

        # two types of label
        labels = [1, 2, 1, 1, 1, 2, 2, 2, 1]

        #monotonically increasing
        timestamp = [1, 2, 3, 4, 5, 6, 7, 8, 9]

        groundtruth = [[[1, 0.67], [2, 0.33]], [[1, 0.67], [2,
                                                            0.33]], [[1, 1.]],
                       [[1, 0.67], [2, 0.33]], [[1, 0.33], [2, 0.67]],
                       [[2, 1.]], [[1, 0.33], [2, 0.67]]]

        indicies = np.arange(len(labels))
        metr = Metrics(timestamp, aggregation_duration=3, window_overlap=1)

        metr.current_position = winlength
        final_result = []

        while True:
            windowed_index = metr.slide(np.array(indicies))
            windowed_labels = []
            windowed_time = []

            for win_idx in windowed_index:
                windowed_labels = np.append(windowed_labels, labels[win_idx])
                windowed_time = np.append(windowed_time, timestamp[win_idx])

            if len(windowed_index) > 0 and len(windowed_index) == winlength:
                result = metr.average_labels_per_window(
                    windowed_labels, windowed_time)
                result = np.round(result, 2)
                final_result.append(result)
            else:
                break

        for x, y in zip(final_result, groundtruth):
            np.testing.assert_almost_equal(x, y)
Esempio n. 7
0
    def test_speed(self):
        """
        Test speed.
        """
        print('Test speed.')

        winlength = 9

        # two types of label
        labels = [1, 2, 1, 1, 1, 2, 2, 2, 1]

        # monotonically increasing
        timestamp = [1, 2, 3, 4, 5, 6, 7, 8, 9]

        adjecency = [[0, 1], [1, 0]]

        groundtruth = np.array([0, 1, 0, 0, 1, 0, 0, 1])

        indicies = np.arange(len(labels))
        metr = Metrics(timestamp, aggregation_duration=9, window_overlap=1)

        metr.current_position = winlength
        final_result = []

        while True:
            windowed_index = metr.slide(np.array(indicies))
            windowed_labels = []
            windowed_time = []

            for win_idx in windowed_index:
                windowed_labels = np.append(windowed_labels, labels[win_idx])
                windowed_time = np.append(windowed_time, timestamp[win_idx])

            if len(windowed_index) > 0 and len(
                    windowed_index) == winlength - 1:
                result = metr.speed(windowed_labels, windowed_time, adjecency)
                result = np.round(result, 2)
                final_result.append(result)
            else:
                break

        for x, y in zip(np.squeeze(final_result), groundtruth):
            np.testing.assert_almost_equal(x, y)