10
10
CausalTestResult
11
11
from causal_testing .json_front .json_class import JsonUtility
12
12
from causal_testing .testing .estimators import Estimator
13
-
13
+ from causal_testing .specification .scenario import Scenario
14
+ from causal_testing .specification .variable import Input , Output , Meta
14
15
15
16
class WidthHeightEstimator (LinearRegressionEstimator ):
16
17
"""
@@ -113,11 +114,12 @@ def get_args() -> argparse.Namespace:
113
114
{"name" : "height" , "type" : float , "distribution" : "uniform" },
114
115
{"name" : "intensity" , "type" : float , "distribution" : "uniform" }
115
116
]
117
+
116
118
outputs = [
117
119
{"name" : "num_lines_abs" , "type" : float },
118
120
{"name" : "num_shapes_abs" , "type" : float }
119
-
120
121
]
122
+
121
123
metas = [
122
124
{"name" : "num_lines_unit" , "type" : float , "populate" : "populate_num_lines_unit" },
123
125
{"name" : "num_shapes_unit" , "type" : float , "populate" : "populate_num_shapes_unit" },
@@ -151,6 +153,24 @@ def get_args() -> argparse.Namespace:
151
153
}
152
154
153
155
156
+ # Create input structure required to create a modelling scenario
157
+ modelling_inputs = [Input (i ['name' ], i ['type' ], distributions [i ['distribution' ]]) for i in inputs ] + \
158
+ [Output (i ['name' ], i ['type' ]) for i in outputs ] + \
159
+ [Meta (i ['name' ], i ['type' ], populates [i ['populate' ]]) for i in metas ] if metas else list ()
160
+
161
+ # Create modelling scenario to access z3 variable mirrors
162
+ modelling_scenario = Scenario (modelling_inputs , None )
163
+ modelling_scenario .setup_treatment_variables ()
164
+
165
+ mutates = {
166
+ "Increase" : lambda x : modelling_scenario .treatment_variables [x ].z3 >
167
+ modelling_scenario .variables [x ].z3 ,
168
+ "ChangeByFactor(2)" : lambda x : modelling_scenario .treatment_variables [x ].z3 ==
169
+ modelling_scenario .variables [
170
+ x ].z3 * 2
171
+ }
172
+
173
+
154
174
class MyJsonUtility (JsonUtility ):
155
175
"""Extension of JsonUtility class to add modelling assumptions to the estimator instance"""
156
176
@@ -167,18 +187,10 @@ def add_modelling_assumptions(self, estimation_model: Estimator):
167
187
args = get_args ()
168
188
169
189
json_utility = MyJsonUtility () # Create an instance of the extended JsonUtility class
170
- json_utility .set_path (args .directory_path ) # Set the path to the data.csv, dag.dot and causal_tests.json file
190
+ json_utility .set_path (args .directory_path ) # Set the path to the data.csv, dag.dot and causal_tests.json file
171
191
172
192
# Load the Causal Variables into the JsonUtility class ready to be used in the tests
173
193
json_utility .set_variables (inputs , outputs , metas , distributions , populates )
174
194
json_utility .setup () # Sets up all the necessary parts of the json_class needed to execute tests
175
195
176
- mutates = {
177
- "Increase" : lambda x : json_utility .modelling_scenario .treatment_variables [x ].z3 >
178
- json_utility .modelling_scenario .variables [x ].z3 ,
179
- "ChangeByFactor(2)" : lambda x : json_utility .modelling_scenario .treatment_variables [x ].z3 ==
180
- json_utility .modelling_scenario .variables [
181
- x ].z3 * 2
182
- }
183
-
184
196
json_utility .execute_tests (effects , mutates , estimators , args .f )
0 commit comments