Skip to content

Commit

Permalink
Add causal analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
kbattocchi committed May 9, 2021
1 parent 70f7d0c commit 83b9e14
Show file tree
Hide file tree
Showing 8 changed files with 1,564 additions and 1 deletion.
5 changes: 5 additions & 0 deletions azure-pipelines-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ jobs:
displayName: 'Install graphviz on Linux'
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))

# Install OpenMP on Mac to support lightgbm
- script: 'brew install libomp'
displayName: 'Install OpenMP on Mac'
condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'))

# Install the package
- script: 'python -m pip install --upgrade pip && pip install --upgrade setuptools wheel Cython && pip install ${{ parameters.package }}'
displayName: 'Install dependencies'
Expand Down
1 change: 1 addition & 0 deletions econml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'ortho_iv',
'policy',
'score',
'solutions',
'sklearn_extensions',
'tree',
'two_stage_least_squares',
Expand Down
21 changes: 21 additions & 0 deletions econml/inference/_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,19 @@ def _expand_outputs(self, n_rows):
"""
pass

def translate(self, offset):
"""
Update the results in place by translating by an offset.
Parameters
----------
offset: array-like
The offset by which to translate these results
"""
# NOTE: use np.asarray(offset) becuase if offset is a pd.Series direct addition would make the sum
# a Series as well, which would subsequently break summary_frame because flatten isn't supported
self.pred = self.pred + np.asarray(offset)


class NormalInferenceResults(InferenceResults):
"""
Expand Down Expand Up @@ -1081,6 +1094,14 @@ def _expand_outputs(self, n_rows):
return EmpiricalInferenceResults(self.d_t, self.d_y, pred, pred_dist, self.inf_type, self.fname_transformer,
self.feature_names, self.output_names, self.treatment_names)

def translate(self, other):
# offset preds
super().translate(other)
# offset the distribution, too
self.pred_dist = self.pred_dist + np.asarray(other)

translate.__doc__ = InferenceResults.translate.__doc__


class PopulationSummaryResults:
"""
Expand Down
6 changes: 6 additions & 0 deletions econml/solutions/causal_analysis/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

from ._causal_analysis import CausalAnalysis

__all__ = ["CausalAnalysis"]
1,090 changes: 1,090 additions & 0 deletions econml/solutions/causal_analysis/_causal_analysis.py

Large diffs are not rendered by default.

Loading

0 comments on commit 83b9e14

Please sign in to comment.