Exemple #1
0
    def test_magnitude_empty(self):
        ds = DataStream(None, None, data=[])
        self.assertIsInstance(ds, DataStream)

        m = magnitude(normalize(ds))
        self.assertIsInstance(m, DataStream)
        self.assertEqual(len(m.data), 0)
Exemple #2
0
    def test_magnitude(self):
        self.assertIsInstance(self.ds, DataStream)
        self.assertEqual(len(self.ds.datapoints), self.size)

        m = magnitude(normalize(self.ds))
        self.assertIsInstance(m, DataStream)
        for sample in m.datapoints:
            self.assertAlmostEqual(sample.sample,
                                   0.12295653034492039,
                                   delta=1e-6)
Exemple #3
0
    def test_normalize(self):
        self.assertIsInstance(self.ds, DataStream)
        self.assertEqual(len(self.ds.datapoints), self.size)

        n = normalize(self.ds)
        self.assertIsInstance(n, DataStream)
        for dp in n.datapoints:
            self.assertAlmostEqual(np.linalg.norm(dp.sample),
                                   0.1713970501312247,
                                   delta=1e-6)
def accelerometer_features(accel: DataStream,
                           window_length: float = 10.0,
                           activity_threshold: float = 0.21,
                           percentile_low: int = 1,
                           percentile_high: int = 99):
    """

    References:
        Figure 3: http://www.cs.memphis.edu/~santosh/Papers/Timing-JIT-UbiComp-2014.pdf

    :param percentile_high:
    :param percentile_low:
    :param accel:
    :param window_length:
    :param activity_threshold:
    :return:
    """
    accelerometer_magnitude = magnitude(normalize(accel))

    accelerometer_win_mag_deviations_data = []
    for key, data in window(accelerometer_magnitude.data,
                            window_length).items():
        accelerometer_win_mag_deviations_data.append(
            window_std_dev(data, key[0]))

    accelerometer_win_mag_deviations = DataStream.from_datastream([accel])
    accelerometer_win_mag_deviations.data = accelerometer_win_mag_deviations_data

    am_values = np.array([dp.sample for dp in accelerometer_magnitude.data])
    low_limit = np.percentile(am_values, percentile_low)
    high_limit = np.percentile(am_values, percentile_high)
    range = high_limit - low_limit
    #print (range)
    #print (low_limit + activity_threshold * range)
    #print (accelerometer_win_mag_deviations_data)

    accel_activity_data = []
    for dp in accelerometer_win_mag_deviations_data:
        comparison = dp.sample > (low_limit + activity_threshold * range)
        accel_activity_data.append(
            DataPoint.from_tuple(dp.start_time, comparison))

    accel_activity = DataStream.from_datastream([accel])
    accel_activity.data = accel_activity_data

    return accelerometer_magnitude, accelerometer_win_mag_deviations, accel_activity
Exemple #5
0
    def test_magnitude(self):
        self.assertIsInstance(self.accel, DataStream)

        m = magnitude(normalize(self.accel))
        self.assertIsInstance(m, DataStream)
Exemple #6
0
    def test_normalize(self):
        self.assertIsInstance(self.accel, DataStream)

        n = normalize(self.accel)
        self.assertIsInstance(n, DataStream)