Exemplo n.º 1
0
def test_estimate_anomaly():
    f1 = estimate_anomaly(dummy_features,
            {'spike': dummy_params['spike']})
    f2 = estimate_anomaly(pd.DataFrame(dummy_features),
            {'spike': dummy_params['spike']})

    assert ma.allclose(f1, f2)
    assert ma.allclose(f1,
            ma.masked_values([-999, 0.0, -5.797359001920061,
                -57.564627324851145, -999, -9.626760611162082], -999))
Exemplo n.º 2
0
def test_estimate_anomaly():
    f1 = estimate_anomaly(dummy_features, {'spike': dummy_params['spike']})
    f2 = estimate_anomaly(pd.DataFrame(dummy_features),
                          {'spike': dummy_params['spike']})

    assert ma.allclose(f1, f2)
    assert ma.allclose(
        f1,
        ma.masked_values([
            -999, 0.0, -5.797359001920061, -57.564627324851145, -999,
            -9.626760611162082
        ], -999))
Exemplo n.º 3
0
def test_estimate_anomaly_dict():
    features = {'spike': [0, 1, -.5], 'tukey53H_norm': [-1, 0, 2]}
    output = estimate_anomaly(features, dummy_params)

    assert len(output) == len(features[features.keys()[0]])
    assert type(output) == ma.MaskedArray
    assert ~ma.getmaskarray(output).any()
Exemplo n.º 4
0
def test_estimate_anomaly_dict():
    features = {'spike': [0, 1, -.5],
                'tukey53H_norm': [-1, 0, 2]
                }
    output = estimate_anomaly(features, dummy_params)

    assert len(output) == len(features[features.keys()[0]])
    assert type(output) == ma.MaskedArray
    assert ~ma.getmaskarray(output).any()
Exemplo n.º 5
0
def test_estimate_anomaly_maskedarray():
    features = {'spike': ma.MaskedArray([0, 1, -.5], mask=[False, True, False]),
                'tukey53H_norm': ma.MaskedArray([-1, 0, 2], mask=[False, True, False]),
                }
    output = estimate_anomaly(features, dummy_params)

    assert len(output) == len(features[features.keys()[0]])
    assert type(output) == ma.MaskedArray
    # If all features for one measurement are masked, the estimated probability
    #   will be masked, like in the second position of this example
    assert (output.mask == [False, True, False]).all()

    features['spike'].mask[1] = False
    output = estimate_anomaly(features, dummy_params)

    assert len(output) == len(features[features.keys()[0]])
    assert type(output) == ma.MaskedArray
    # But if is there at least one of features valid, it returns a valid value
    # Compare this example with the previous where spike[1] is not masked
    #   anymore.
    assert ~ma.getmaskarray(output).any()
Exemplo n.º 6
0
def test_estimate_anomaly_maskedarray():
    features = {
        'spike': ma.MaskedArray([0, 1, -.5], mask=[False, True, False]),
        'tukey53H_norm': ma.MaskedArray([-1, 0, 2], mask=[False, True, False]),
    }
    output = estimate_anomaly(features, dummy_params)

    assert len(output) == len(features[features.keys()[0]])
    assert type(output) == ma.MaskedArray
    # If all features for one measurement are masked, the estimated probability
    #   will be masked, like in the second position of this example
    assert (output.mask == [False, True, False]).all()

    features['spike'].mask[1] = False
    output = estimate_anomaly(features, dummy_params)

    assert len(output) == len(features[features.keys()[0]])
    assert type(output) == ma.MaskedArray
    # But if is there at least one of features valid, it returns a valid value
    # Compare this example with the previous where spike[1] is not masked
    #   anymore.
    assert ~ma.getmaskarray(output).any()
Exemplo n.º 7
0
def anomaly_detection(features, cfg):
    """

        Must decide where to set the flags.
    """

    prob = estimate_anomaly(features, params = cfg['features'])
    #flag = np.zeros(self.input[v].shape, dtype='i1')
    flag = np.zeros(features[features.keys()[0]].shape, dtype='i1')

    flag[np.nonzero(prob >= cfg['threshold'])] = 1
    flag[np.nonzero(prob < cfg['threshold'])] = 4

    return flag
Exemplo n.º 8
0
def anomaly_detection(features, cfg):
    """

        Must decide where to set the flags.
    """

    prob = estimate_anomaly(features, params=cfg['features'])
    #flag = np.zeros(self.input[v].shape, dtype='i1')
    flag = np.zeros(prob.shape, dtype='i1')

    flag[np.nonzero(prob >= cfg['threshold'])] = 1
    flag[np.nonzero(prob < cfg['threshold'])] = 4

    return prob, flag