-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathinterpreter.py
More file actions
48 lines (35 loc) · 1.52 KB
/
interpreter.py
File metadata and controls
48 lines (35 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import logging
import dowhy.causal_estimator
import dowhy.causal_model
import dowhy.causal_refuter
class Interpreter:
"""Base class for all interpretation methods."""
# Can use these lists to specify the models/estimators/refuters that a particular interpreter supports. Throw a ValueError if the user provides an incompatible object to intepret.
SUPPORTED_MODELS = []
SUPPORTED_ESTIMATORS = []
SUPPORTED_REFUTERS = []
def __init__(self, instance, **kwargs):
"""Initialize an interpreter.
:param instance: An object of type CausalModel, CausalEstimate or CausalRefutation.
"""
self.model = None
self.estimate = None
self.refutation = None
if isinstance(instance, dowhy.causal_model.CausalModel):
self.model = instance
elif isinstance(instance, dowhy.causal_estimator.CausalEstimate):
self.estimate = instance
elif isinstance(instance, dowhy.causal_refuter.CausalRefutation):
self.refutation = instance
else:
self.logger.error("Type of object passed not supported for interpretation.")
# Unpacking the keyword arguments
if kwargs is not None:
for key, value in kwargs.items():
setattr(self, key, value)
self.logger = logging.getLogger(__name__)
def interpret(self):
"""Method that implements the functionality of an interpreter.
To be overridden by interpreter sub-classes.
"""
raise NotImplementedError