def test_add_true_cps(example_detector):

    det = example_detector
    det.run()

    true_cp_index = 50
    true_cp_model_index = 2

    # Add CPs to the EvT before setting it up with the detector:

    # Set up the EvT
    evt = EvaluationTool()
    assert evt.has_true_CPs is False
    evt.add_true_CPs(true_cp_index, true_cp_model_index)
    assert evt.has_true_CPs is True

    # Build the evt using the detector, then check that true CP is stored in results
    evt.build_EvaluationTool_via_run_detector(det)
    assert evt.results[evt.results[0].index("has true CPs")] is True
    assert evt.results[evt.results[0].index(
        "true CP locations")] == true_cp_index
    assert evt.results[evt.results[0].index(
        "true CP model index")] == true_cp_model_index
    assert evt.results[evt.results[0].index("true CP model labels")] is None

    # Add CPs to the EvT after setting it up with the detector:

    # Set up the EvT
    evt2 = EvaluationTool()
    evt2.build_EvaluationTool_via_run_detector(det)
    evt2.add_true_CPs(true_cp_index, true_cp_model_index)

    # Check that CPs are still stored correctly if added after the detector has been run
    assert evt2.has_true_CPs is True
    assert evt2.results[evt.results[0].index("has true CPs")] is True
    assert evt2.results[evt.results[0].index(
        "true CP locations")] == true_cp_index
    assert evt2.results[evt.results[0].index(
        "true CP model index")] == true_cp_model_index
    assert evt2.results[evt.results[0].index("true CP model labels")] is None
示例#2
0
        model_prior = model_prior,
        cp_model = cp_model, S1 = S1, S2 = S2, T = T, 
        store_rl=True, store_mrl=True,
        trim_type="keep_K", threshold = 200,
        notifications = 100,
        save_performance_indicators = True,
        training_period = 250)
detector.run()


"""STEP 7: give some results/pictures/summaries"""

"""Store results + real CPs into EvaluationTool obj"""
EvT = EvaluationTool()
EvT.add_true_CPs(true_CP_location=true_CP_location, 
                 true_CP_model_index=true_CP_location, 
             true_CP_model_label = -1)
EvT.build_EvaluationTool_via_run_detector(detector)

print("convergence diagnostics for on-line hyperparameter opt:")
plt.plot(np.linspace(1,len(detector.model_universe[0].a_list), 
                     len(detector.model_universe[0].a_list)), 
         np.array(detector.model_universe[0].a_list))
plt.plot(np.linspace(1,len(detector.model_universe[0].b_list),
                     len(detector.model_universe[0].b_list)), 
         np.array(detector.model_universe[0].b_list))

fig = EvT.plot_run_length_distr(
    time_range = np.linspace(1,
                             T-max(upper_VAR, upper_AR)-1,
                             T-max(upper_VAR, upper_AR)-1,