Example #1
0
    def test_models_for_pattern_model_cache(self):
        cache = {
            'patternCenter': [4, 12],
            'patternModel': [],
            'confidence': 2,
            'convolveMax': 8,
            'convolveMin': 7,
            'window_size': 2,
            'convDelMin': 0,
            'convDelMax': 0,
        }
        data_val = [
            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, 6.0, 6.0, 6.0, 1.0, 1.0, 1.0, 1.0, 1.0
        ]
        dataframe = create_dataframe(data_val)
        segments = [{
            '_id': 'Esl7uetLhx4lCqHa',
            'analyticUnitId': 'opnICRJwOmwBELK8',
            'from': 1523889000019,
            'to': 1523889000024,
            'labeled': True,
            'deleted': False
        }]
        segments = [Segment.from_json(segment) for segment in segments]

        try:
            model = models.DropModel()
            model_name = model.__class__.__name__
            model.state = model.get_state(cache)
            model.fit(dataframe, segments, 'test')
        except ValueError:
            self.fail('Model {} raised unexpectedly'.format(model_name))
Example #2
0
    def test_drop_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
        }]
        segments = [Segment.from_json(segment) for segment in segments]

        try:
            model = models.DropModel()
            model.state = model.get_state(None)
            model_name = model.__class__.__name__
            model.fit(dataframe, segments, 'test')
        except ValueError:
            self.fail('Model {} raised unexpectedly'.format(model_name))
Example #3
0
    def test_drop_antisegments(self):
        data_val = [9.0, 9.0, 9.0, 9.0, 9.0, 5.0, 5.0, 5.0, 5.0, 9.0, 9.0, 9.0, 9.0, 1.0, 1.0, 1.0, 1.0, 1.0, 9.0, 9.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}]

        try:
            model = models.DropModel()
            model_name = model.__class__.__name__
            model.fit(dataframe, segments, dict())
        except ValueError:
            self.fail('Model {} raised unexpectedly'.format(model_name))
Example #4
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)
Example #5
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))
Example #6
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')
Example #7
0
 def test_models_for_pattern_model_cache(self):
     cache = {
         'pattern_center': [4, 12],
         'pattern_model': [],
         'confidence': 2,
         'convolve_max': 8,
         'convolve_min': 7,
         'WINDOW_SIZE': 2,
         'conv_del_min': 0,
         'conv_del_max': 0,
     }
     data_val = [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, 6.0, 6.0, 6.0, 1.0, 1.0, 1.0, 1.0, 1.0]
     dataframe = create_dataframe(data_val)
     segments = [{'_id': 'Esl7uetLhx4lCqHa', 'analyticUnitId': 'opnICRJwOmwBELK8', 'from': 1523889000019, 'to': 1523889000024, 'labeled': True, 'deleted': False}]
     try:
         model = models.DropModel()
         model_name = model.__class__.__name__
         model.fit(dataframe, segments, cache)
     except ValueError:
         self.fail('Model {} raised unexpectedly'.format(model_name))