예제 #1
0
    anomaly_detectors = []
    ad_config = defaults.DEFAULT_KNN_CONFIG
    for k_value in K_VALUES:
        ad_config['evaluator_config']['k'] = k_value
        if transformation is None:
            if 'representation_config' in ad_config:
                ad_config.pop('representation_config')
        else:
            ad_config['representation_config'] = {'method': transformation}

        anomaly_detectors.append(
            anomaly_detection.create_anomaly_detector(**ad_config))

    # init test
    test = [utils.load_sequence(TEST_FILE)]
    test_suite = utils.TestSuite(anomaly_detectors, K_VALUES, [test], ['test'])

    # execute test
    test_suite.evaluate(display_progress=True)

    # get plots
    results = test_suite.results

    utils.plots.plot_normalized_anomaly_vector_heat_map(results,
                                                        K_VALUES,
                                                        plot=heat_map_plot)
    heat_map_plot.set_title(name)
    heat_map_plot.set_ylabel('k')

    full_support_dists.append(
        results.get_anomaly_detector_averages(K_VALUES,
WINDOW_WIDTHS = range(1, 51, 1)
TEST_FILE = 'sequences/random_walk_added_noise'

# set up anomaly detectors
anomaly_detectors = []
ad_config = defaults.DEFAULT_KNN_CONFIG
for width in WINDOW_WIDTHS:
    filter_config = {'method': 'sliding_window', 'width': width, 'step': 1}
    ad_config['evaluation_filter_config'] = filter_config
    ad_config['reference_filter_config'] = filter_config
    anomaly_detectors.append(
        anomaly_detection.create_anomaly_detector(**ad_config))

# init test
test = [utils.load_sequence(TEST_FILE)]
test_suite = utils.TestSuite(anomaly_detectors, WINDOW_WIDTHS, [test],
                             ['test'])

# execute test
test_suite.evaluate(display_progress=True)

# get plot
results = test_suite.results
fig1, plot1 = utils.plot_normalized_anomaly_vector_heat_map(results,
                                                            WINDOW_WIDTHS,
                                                            ylabel='w')
fig2, plot2 = utils.plot_mean_error_values(results,
                                           WINDOW_WIDTHS,
                                           WINDOW_WIDTHS,
                                           xlabel='w')
fig3, plot3 = utils.plot_execution_times(results,
                                         WINDOW_WIDTHS,
예제 #3
0
ad_label_matrix = []
for k in K_VALUES:
    ad_row = []
    for w in W_VALUES:
        ad_config['evaluator_config']['k'] = k
        ad_config['evaluation_filter_config']['width'] = w
        ad_config['reference_filter_config']['width'] = w
        ad = anomaly_detection.create_anomaly_detector(**ad_config)
        anomaly_detectors.append(ad)
        ad_row.append(str(k) + ',' + str(w))
    ad_label_matrix.append(ad_row)

ad_label_list = sum(ad_label_matrix, [])

test = [utils.load_sequence(TEST_FILE)]
test_suite = utils.TestSuite(anomaly_detectors, ad_label_list, [test], 'test')

#execute
test_suite.evaluate(display_progress=True)

results = test_suite.results

# plot the distances
ERRORS = [
    'equal_support_distance', 'full_support_distance', 'best_support_distance',
    'normalized_euclidean_distance'
]
ERROR_LABELS = [
    'Equal support', 'Full support', 'Best support', 'Normalized Euclidean'
]
예제 #4
0
TEST_FILE = 'sequences/random_walk_added_noise'

# set up anomaly detectors
anomaly_detectors = []
ad_config = defaults.DEFAULT_KNN_CONFIG
for context_width in CONTEXT_WIDTHS:
    ad_config['context_config'] = {
        'method': 'local_symmetric',
        'width': context_width
    }
    anomaly_detectors.append(
        anomaly_detection.create_anomaly_detector(**ad_config))

# init test
test = [utils.load_sequence(TEST_FILE)]
test_suite = utils.TestSuite(anomaly_detectors, CONTEXT_WIDTHS, [test],
                             ['test'])

# execute test
test_suite.evaluate(display_progress=True)

# get plots
results = test_suite.results
fig1, plot1 = utils.plot_normalized_anomaly_vector_heat_map(results,
                                                            CONTEXT_WIDTHS,
                                                            ylabel='m')
fig2, plot2 = utils.plot_mean_error_values(results,
                                           CONTEXT_WIDTHS,
                                           CONTEXT_WIDTHS,
                                           xlabel='m')
fig3, plot3 = utils.plot_execution_times(results,
                                         CONTEXT_WIDTHS,