Esempio n. 1
0
    def test_jump_antisegments(self):
        data_val = [
            1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0, 1.0, 1.0, 1.0, 1.0,
            9.0, 9.0, 9.0, 9.0, 9.0, 1.0, 1.0
        ]
        dataframe = create_dataframe(data_val)
        segments = [{
            '_id': 'Esl7uetLhx4lCqHa',
            'analyticUnitId': 'opnICRJwOmwBELK8',
            'from': 1523889000010,
            'to': 1523889000016,
            'labeled': True,
            'deleted': False
        }, {
            '_id': 'Esl7uetLhx4lCqHa',
            'analyticUnitId': 'opnICRJwOmwBELK8',
            'from': 1523889000002,
            'to': 1523889000008,
            'labeled': False,
            'deleted': True
        }]
        segments = [Segment.from_json(segment) for segment in segments]

        try:
            model = models.JumpModel()
            model_name = model.__class__.__name__
            model.state = model.get_state(None)
            model.fit(dataframe, segments, 'test')
        except ValueError:
            self.fail('Model {} raised unexpectedly'.format(model_name))
Esempio n. 2
0
    def test_jump_model_for_cache(self):
        cache = {
            'patternCenter': [2, 6],
            'patternModel': [5, 0.5, 4],
            'confidence': 2,
            'convolveMax': 8,
            'convolveMin': 7,
            'window_size': 1,
            'convDelMin': 0,
            'convDelMax': 0,
        }
        data_val = [
            1.0, 1.0, 1.0, 4.0, 4.0, 0.0, 0.0, 5.0, 5.0, 0.0, 0.0, 4.0, 4.0,
            4.0, 4.0
        ]
        dataframe = create_dataframe(data_val)
        segments = [{
            '_id': 'Esl7uetLhx4lCqHa',
            'analyticUnitId': 'opnICRJwOmwBELK8',
            'from': 152388900009,
            'to': 1523889000013,
            'labeled': True,
            'deleted': False
        }]
        segments = [Segment.from_json(segment) for segment in segments]

        model = models.JumpModel()
        model.state = model.get_state(cache)
        result = model.fit(dataframe, segments, 'test')
        self.assertEqual(len(result.pattern_center), 3)
Esempio n. 3
0
    def test_value_error_dataset_input_should_have_multiple_elements(self):
        data_val = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 5.0, 4.0, 5.0, 5.0, 6.0, 5.0, 1.0, 2.0, 3.0, 4.0, 5.0,3.0,3.0,2.0,7.0,8.0,9.0,8.0,7.0,6.0]
        dataframe = create_dataframe(data_val)
        segments = [{'_id': 'Esl7uetLhx4lCqHa', 'analyticUnitId': 'opnICRJwOmwBELK8', 'from': 1523889000007, 'to': 1523889000011, 'labeled': True, 'deleted': False}]

        try:
            model = models.JumpModel()
            model_name = model.__class__.__name__
            model.fit(dataframe, segments, dict())
        except ValueError:
            self.fail('Model {} raised unexpectedly'.format(model_name))
Esempio n. 4
0
    def test_jump_empty_segment(self):
        data_val = [1.0, 1.0, 1.0, 1.0, 1.0, 5.0, 5.0, 5.0, 5.0, 1.0, 1.0, 1.0, 1.0, 9.0, 9.0, 9.0, 9.0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        dataframe = create_dataframe(data_val)
        segments = [{'_id': 'Esl7uetLhx4lCqHa', 'analyticUnitId': 'opnICRJwOmwBELK8', 'from': 1523889000019, 'to': 1523889000025, 'labeled': True, 'deleted': False},
                    {'_id': 'Esl7uetLhx4lCqHa', 'analyticUnitId': 'opnICRJwOmwBELK8', 'from': 1523889000002, 'to': 1523889000008, 'labeled': True, 'deleted': False}]

        try:
            model = models.JumpModel()
            model_name = model.__class__.__name__
            model.fit(dataframe, segments, dict())
        except ValueError:
            self.fail('Model {} raised unexpectedly'.format(model_name))
Esempio n. 5
0
def resolve_model_by_pattern(pattern: str) -> models.Model:
    if pattern == 'GENERAL':
        return models.GeneralModel()
    if pattern == 'PEAK':
        return models.PeakModel()
    if pattern == 'TROUGH':
        return models.TroughModel()
    if pattern == 'DROP':
        return models.DropModel()
    if pattern == 'JUMP':
        return models.JumpModel()
    if pattern == 'CUSTOM':
        return models.CustomModel()
    raise ValueError('Unknown pattern "%s"' % pattern)
Esempio n. 6
0
 def test_jump_model_for_cache(self):
     cache = {
         'pattern_center': [2, 6],
         'pattern_model': [5, 0.5, 4],
         'confidence': 2,
         'convolve_max': 8,
         'convolve_min': 7,
         'WINDOW_SIZE': 1,
         'conv_del_min': 0,
         'conv_del_max': 0,
     }
     data_val = [1.0, 1.0, 1.0, 4.0, 4.0, 0.0, 0.0, 5.0, 5.0, 0.0, 0.0, 4.0, 4.0, 4.0, 4.0]
     dataframe = create_dataframe(data_val)
     segments = [{'_id': 'Esl7uetLhx4lCqHa', 'analyticUnitId': 'opnICRJwOmwBELK8', 'from': 152388900009, 'to': 1523889000013, 'labeled': True, 'deleted': False}]
     model = models.JumpModel()
     result = model.fit(dataframe, segments, cache)
     self.assertEqual(len(result['pattern_center']), 3)
Esempio n. 7
0
    def test_models_with_corrupted_dataframe(self):
        data = [[1523889000000 + i, float('nan')] for i in range(10)]
        dataframe = pd.DataFrame(data, columns=['timestamp', 'value'])
        segments = []

        model_instances = [
            models.JumpModel(),
            models.DropModel(),
            models.GeneralModel(),
            models.PeakModel(),
            models.TroughModel()
        ]
        try:
            for model in model_instances:
                model_name = model.__class__.__name__
                model.fit(dataframe, segments, dict())
        except ValueError:
            self.fail('Model {} raised unexpectedly'.format(model_name))
Esempio n. 8
0
    def test_models_with_corrupted_dataframe(self):
        data = [[1523889000000 + i, float('nan')] for i in range(10)]
        dataframe = pd.DataFrame(data, columns=['timestamp', 'value'])
        segments = []

        model_instances = [
            models.JumpModel(),
            models.DropModel(),
            models.GeneralModel(),
            models.PeakModel(),
            models.TroughModel()
        ]

        for model in model_instances:
            model_name = model.__class__.__name__
            model.state = model.get_state(None)
            with self.assertRaises(AssertionError):
                model.fit(dataframe, segments, 'test')