Skip to content

Commit

Permalink
Check that true CPs are stored correctly whether added to EvT before …
Browse files Browse the repository at this point in the history
…or after the detector.
  • Loading branch information
LouiseABowler committed Aug 16, 2018
1 parent 1bd1ef0 commit fea5414
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
15 changes: 13 additions & 2 deletions Evaluation_tool.py
Expand Up @@ -70,6 +70,11 @@ def __init__(self):
"all retained run lengths",
"has true CPs", "true CP locations",
"true CP model index", "true CP model labels"]

"""Initialise the list of results: empty apart from names and no true CPs"""
self.results = [None]*len(self.names)
self.results[self.names.index("names")] = self.names
self.results[self.names.index("has true CPs")] = False

"""NOTE: Plotting will work with 7 different colors and 4 different
line styles!"""
Expand Down Expand Up @@ -241,12 +246,18 @@ def add_true_CPs(self, true_CP_location, true_CP_model_index,
CP location. *true_CP_model_label* gives you the string label of the
true DGP starting at the CP, e.g.
true_CP_model_label = ["BVAR(4,4,1)", "BVAR(1,1,1,1,1)"]."""

# Store CPs and their properties in the EvT
self.true_CP_location = true_CP_location
self.true_CP_model_index = true_CP_model_index
#if self.model_labels is None:
# self.model_labels = true_CP_model_label
self.true_CP_model_label = true_CP_model_label
self.has_true_CPs = True

# Update the values in results
self.results[self.results[0].index("true CP locations")] = self.true_CP_location
self.results[self.results[0].index("true CP model index")] = self.true_CP_model_index
self.results[self.results[0].index("true CP model labels")] = self.true_CP_model_label
self.results[self.results[0].index("has true CPs")] = self.has_true_CPs


"""*********************************************************************
Expand Down
27 changes: 24 additions & 3 deletions tests/test_Evaluation_tool.py
Expand Up @@ -124,16 +124,37 @@ def test_add_true_cps(example_detector):
det = example_detector
det.run()

# Add the true CPs to the evt
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(50, 4)
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")] == 50
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


def test_initialise_from_not_run_detector(example_detector):
Expand Down

0 comments on commit fea5414

Please sign in to comment.