Skip to content

Commit 9e48fe0

Browse files
remove distributions and populates
1 parent bbd2dd9 commit 9e48fe0

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

causal_testing/json_front/json_class.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
logger = logging.getLogger(__name__)
2222

23+
2324
class JsonUtility(ABC):
2425
"""
2526
The JsonUtility Class provides the functionality to use structured JSON to setup and run causal tests on the
@@ -73,10 +74,10 @@ def set_variables(self, inputs: dict, outputs: dict, metas: dict, distributions:
7374
:param distributions:
7475
:param populates:
7576
"""
76-
self.inputs = [Input(i['name'], i['type'], distributions[i['distribution']]) for i in
77+
self.inputs = [Input(i['name'], i['type'], i['distribution']) for i in
7778
inputs]
7879
self.outputs = [Output(i['name'], i['type']) for i in outputs]
79-
self.metas = [Meta(i['name'], i['type'], populates[i['populate']]) for i in
80+
self.metas = [Meta(i['name'], i['type'], [i['populate']]) for i in
8081
metas] if metas else list()
8182

8283
def setup(self):
@@ -131,8 +132,6 @@ def execute_tests(self, effects: dict, mutates: dict, estimators: dict, f_flag:
131132

132133
def _json_parse(self):
133134
"""Parse a JSON input file into inputs, outputs, metas and a test plan
134-
:param distributions: dictionary of user defined scipy distributions
135-
:param populates: dictionary of user defined populate functions
136135
"""
137136
with open(self.json_path) as f:
138137
self.test_plan = json.load(f)

examples/poisson/run_causal_tests.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ def populate_num_shapes_unit(data):
9292
area = data['width'] * data['height']
9393
data['num_shapes_unit'] = data['num_shapes_abs'] / area
9494

95+
9596
inputs = [
96-
{"name": "width", "type": float, "distribution": "uniform"},
97-
{"name": "height", "type": float, "distribution": "uniform"},
98-
{"name": "intensity", "type": float, "distribution": "uniform"}
97+
{"name": "width", "type": float, "distribution": scipy.stats.uniform(0, 10)},
98+
{"name": "height", "type": float, "distribution": scipy.stats.uniform(0, 10)},
99+
{"name": "intensity", "type": float, "distribution": scipy.stats.uniform(0, 10)}
99100
]
100101

101102
outputs = [
@@ -104,23 +105,13 @@ def populate_num_shapes_unit(data):
104105
]
105106

106107
metas = [
107-
{"name": "num_lines_unit", "type": float, "populate": "populate_num_lines_unit"},
108-
{"name": "num_shapes_unit", "type": float, "populate": "populate_num_shapes_unit"},
109-
{"name": "width_plus_height", "type": float, "populate": "populate_width_height"}
108+
{"name": "num_lines_unit", "type": float, "populate": populate_num_lines_unit},
109+
{"name": "num_shapes_unit", "type": float, "populate": populate_num_shapes_unit},
110+
{"name": "width_plus_height", "type": float, "populate": populate_width_height}
110111
]
111112

112113
constraints = ["width > 0", "height > 0", "intensity > 0"]
113114

114-
populates = {
115-
"populate_width_height": populate_width_height,
116-
"populate_num_lines_unit": populate_num_lines_unit,
117-
"populate_num_shapes_unit": populate_num_shapes_unit
118-
}
119-
120-
distributions = {
121-
"uniform": scipy.stats.uniform(0, 10)
122-
}
123-
124115
effects = {
125116
"PoissonWidthHeight": PoissonWidthHeight(),
126117
"Positive": Positive(),
@@ -136,9 +127,9 @@ def populate_num_shapes_unit(data):
136127
}
137128

138129
# Create input structure required to create a modelling scenario
139-
modelling_inputs = [Input(i['name'], i['type'], distributions[i['distribution']]) for i in inputs] + \
130+
modelling_inputs = [Input(i['name'], i['type'], i['distribution']) for i in inputs] + \
140131
[Output(i['name'], i['type']) for i in outputs] + \
141-
[Meta(i['name'], i['type'], populates[i['populate']]) for i in metas] if metas else list()
132+
[Meta(i['name'], i['type'], [i['populate']]) for i in metas] if metas else list()
142133

143134
# Create modelling scenario to access z3 variable mirrors
144135
modelling_scenario = Scenario(modelling_inputs, None)

0 commit comments

Comments
 (0)