Skip to content

Commit 83d7e30

Browse files
author
Andrew Clark
authored
Merge pull request #69 from CITCOM-project/remove_intervention
Removed Intervention and all references
2 parents 683e6c5 + 9e15de3 commit 83d7e30

File tree

10 files changed

+1650
-104
lines changed

10 files changed

+1650
-104
lines changed
Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import Any
22

3-
from causal_testing.testing.intervention import Intervention
43
from causal_testing.testing.causal_test_outcome import CausalTestOutcome
54
from causal_testing.specification.variable import Variable
65

@@ -18,9 +17,8 @@ class CausalTestCase:
1817
"""
1918

2019
def __init__(self, control_input_configuration: dict[Variable: Any], expected_causal_effect: CausalTestOutcome,
21-
outcome_variables: dict[Variable], intervention: Intervention = None,
22-
treatment_input_configuration: dict[Variable: Any] = None, estimate_type: str = "ate",
23-
effect_modifier_configuration: dict[Variable: Any] = None):
20+
outcome_variables: dict[Variable], treatment_input_configuration: dict[Variable: Any] = None,
21+
estimate_type: str = "ate", effect_modifier_configuration: dict[Variable: Any] = None):
2422
"""
2523
When a CausalTestCase is initialised, it takes the intervention and applies it to the input configuration to
2624
create two distinct input configurations: a control input configuration and a treatment input configuration.
@@ -29,35 +27,18 @@ def __init__(self, control_input_configuration: dict[Variable: Any], expected_ca
2927
3028
:param control_input_configuration: The input configuration representing the control values of the treatment
3129
variables.
32-
:param intervention: The function which transforms the control configuration to the treatment configuration.
33-
Defaults to None.
3430
:param treatment_input_configuration: The input configuration representing the treatment values of the treatment
3531
variables. That is, the input configuration *after* applying the intervention.
3632
"""
37-
assert (
38-
intervention is None or treatment_input_configuration is None
39-
), 'Cannot define both treatment configuration and intervention.'
40-
assert (
41-
intervention is not None or treatment_input_configuration is not None
42-
), 'Must define either a treatment configuration or intervention.'
43-
if intervention is not None:
44-
assert isinstance(intervention, Intervention), \
45-
f'Intervention must be an instance of class Intervention not {type(intervention)}.'
46-
4733
self.control_input_configuration = control_input_configuration
4834
self.expected_causal_effect = expected_causal_effect
49-
self.intervention = intervention
5035
self.outcome_variables = outcome_variables
5136
self.treatment_input_configuration = treatment_input_configuration
5237
self.estimate_type = estimate_type
5338
if effect_modifier_configuration:
5439
self.effect_modifier_configuration = effect_modifier_configuration
5540
else:
5641
self.effect_modifier_configuration = dict()
57-
if intervention:
58-
self.treatment_input_configuration = intervention.apply(
59-
self.control_input_configuration
60-
)
6142
assert self.control_input_configuration.keys() == self.treatment_input_configuration.keys(),\
6243
"Control and treatment input configurations must have the same keys."
6344

@@ -78,12 +59,7 @@ def get_treatment_values(self):
7859
return list(self.treatment_input_configuration.values())
7960

8061
def __str__(self):
81-
if self.intervention is not None:
82-
control_input_configuration = {k.name: v for k, v in self.control_input_configuration.items()}
83-
return (f"Applying {self.intervention} to {control_input_configuration} should cause the following "
84-
f"changes to {[v.name for v in self.outcome_variables]}: {self.expected_causal_effect}.")
85-
else:
86-
treatment_config = {k.name: v for k, v in self.treatment_input_configuration.items()}
87-
control_config = {k.name: v for k, v in self.control_input_configuration.items()}
88-
return (f"Running {treatment_config} instead of {control_config} should cause the following "
89-
f"changes to {self.outcome_variables}: {self.expected_causal_effect}.")
62+
treatment_config = {k.name: v for k, v in self.treatment_input_configuration.items()}
63+
control_config = {k.name: v for k, v in self.control_input_configuration.items()}
64+
return (f"Running {treatment_config} instead of {control_config} should cause the following "
65+
f"changes to {self.outcome_variables}: {self.expected_causal_effect}.")

causal_testing/testing/causal_test_engine.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@ class CausalTestEngine:
3232
def __init__(self, causal_test_case: CausalTestCase, causal_specification: CausalSpecification,
3333
data_collector: DataCollector):
3434
self.causal_test_case = causal_test_case
35-
if self.causal_test_case.intervention is not None:
36-
self.treatment_variables = list(self.causal_test_case.intervention.treatment_variables)
37-
else:
38-
# This covers the case where a causal test case is specified in terms of a control/treatment run pair
39-
# rather than a control run and an intervention.
40-
# It might be better, though, to do this with an intervention which just returns the literal treatment run
41-
self.treatment_variables = list(self.causal_test_case.control_input_configuration)
42-
35+
self.treatment_variables = list(self.causal_test_case.control_input_configuration)
4336
self.casual_dag, self.scenario = causal_specification.causal_dag, causal_specification.scenario
4437
self.data_collector = data_collector
4538
self.scenario_execution_data_df = pd.DataFrame()

examples/covasim_/doubling_beta/causal_test_beta.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from causal_testing.data_collection.data_collector import ObservationalDataCollector
99
from causal_testing.testing.causal_test_case import CausalTestCase
1010
from causal_testing.testing.causal_test_outcome import Positive
11-
from causal_testing.testing.intervention import Intervention
1211
from causal_testing.testing.causal_test_engine import CausalTestEngine
1312
from causal_testing.testing.estimators import LinearRegressionEstimator
1413
from matplotlib.pyplot import rcParams
@@ -207,8 +206,8 @@ def identification(observational_data_path):
207206
# 5. Create a causal test case
208207
causal_test_case = CausalTestCase(control_input_configuration={beta: 0.016},
209208
expected_causal_effect=Positive,
210-
outcome_variables={cum_infections},
211-
intervention=Intervention((beta,), (0.032,), ), )
209+
treatment_input_configuration={beta: 0.032},
210+
outcome_variables={cum_infections})
212211

213212
# 6. Create a data collector
214213
data_collector = ObservationalDataCollector(scenario, observational_data_path)

examples/covasim_/vaccinating_elderly/causal_test_vaccine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def experimental_causal_test_vaccinate_elderly(runs_per_test_per_config: int = 3
7272
for outcome_variable, expected_effect in expected_outcome_effects.items():
7373
causal_test_case = CausalTestCase(control_input_configuration={vaccine: 0},
7474
expected_causal_effect=expected_effect,
75-
outcome_variables={outcome_variable},
76-
intervention=Intervention((vaccine,), (1,), ), )
75+
treatment_input_configuration={vaccine: 1},
76+
outcome_variables={outcome_variable})
7777

7878
# 7. Create an instance of the causal test engine
7979
causal_test_engine = CausalTestEngine(causal_test_case, causal_specification, data_collector)

examples/lr91/causal_test_max_conductances.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from causal_testing.data_collection.data_collector import ObservationalDataCollector
99
from causal_testing.testing.causal_test_case import CausalTestCase
1010
from causal_testing.testing.causal_test_outcome import Positive, Negative, NoEffect
11-
from causal_testing.testing.intervention import Intervention
1211
from causal_testing.testing.causal_test_engine import CausalTestEngine
1312
from causal_testing.testing.estimators import LinearRegressionEstimator
1413
from matplotlib.pyplot import rcParams
@@ -114,8 +113,8 @@ def effects_on_APD90(observational_data_path, treatment_var, control_val, treatm
114113
# 6. Create a causal test case
115114
causal_test_case = CausalTestCase(control_input_configuration={treatment_var: control_val},
116115
expected_causal_effect=expected_causal_effect,
117-
outcome_variables={apd90},
118-
intervention=Intervention((treatment_var,), (treatment_val,), ), )
116+
treatment_input_configuration={treatment_var: treatment_val},
117+
outcome_variables={apd90})
119118

120119
# 7. Create a data collector
121120
data_collector = ObservationalDataCollector(scenario, observational_data_path)

0 commit comments

Comments
 (0)