Skip to content

Commit

Permalink
Merge branch 'master' into gaugup/ContinueUnifyTest
Browse files Browse the repository at this point in the history
  • Loading branch information
gaugup committed Dec 16, 2021
2 parents e481e8b + bad94ac commit f719519
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 16 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Python Package using Conda

on: [push]

jobs:
build-linux:
runs-on: ubuntu-latest
strategy:
max-parallel: 5

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install core dependencies
run: |
conda env update --file environment.yml --name base
- name: Install deep learning dependencies
run: |
conda env update --file environment-deeplearning.yml --name base
- name: Test with pytest
run: |
conda install pytest ipython jupyter nbformat pytest-mock
pytest
2 changes: 1 addition & 1 deletion dice_ml/data_interfaces/public_data_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def get_valid_feature_range(self, feature_range_input, normalized=True):
"""
feature_range = {}

for idx, feature_name in enumerate(self.feature_names):
for _, feature_name in enumerate(self.feature_names):
feature_range[feature_name] = []
if feature_name in self.continuous_feature_names:
max_value = self.data_df[feature_name].max()
Expand Down
2 changes: 1 addition & 1 deletion dice_ml/explainer_interfaces/dice_tensorflow2.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def do_cf_initializations(self, total_CFs, algorithm, features_to_vary):
# CF initialization
if len(self.cfs) != self.total_CFs:
self.cfs = []
for ix in range(self.total_CFs):
for _ in range(self.total_CFs):
one_init = [[]]
for jx in range(self.minx.shape[1]):
one_init[0].append(np.random.uniform(self.minx[0][jx], self.maxx[0][jx]))
Expand Down
2 changes: 1 addition & 1 deletion dice_ml/explainer_interfaces/explainer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def feature_importance(self, query_instances, cf_examples_list=None,
continue

per_query_point_cfs = 0
for index, row in df.iterrows():
for _, row in df.iterrows():
per_query_point_cfs += 1
for col in self.data_interface.continuous_feature_names:
if not np.isclose(org_instance[col].iat[0], row[col]):
Expand Down
2 changes: 1 addition & 1 deletion dice_ml/explainer_interfaces/feasible_base_vae.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def generate_counterfactuals(self, query_instance, total_CFs, desired_class="opp
curr_cf_pred = []
curr_test_pred = train_y.numpy()

for cf_count in range(total_CFs):
for _ in range(total_CFs):
recon_err, kl_err, x_true, x_pred, cf_label = \
self.cf_vae.compute_elbo(train_x, 1.0-train_y, self.pred_model)
while(cf_label == train_y):
Expand Down
4 changes: 2 additions & 2 deletions dice_ml/model_interfaces/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_num_output_nodes(self, inp_size):
temp_input = np.transpose(np.array([np.random.uniform(0, 1) for i in range(inp_size)]).reshape(-1, 1))
return self.get_output(temp_input).shape[1]

def get_num_output_nodes2(self, input):
def get_num_output_nodes2(self, input_instance):
if self.model_type == ModelTypes.Regressor:
raise SystemException('Number of output nodes not supported for regression')
return self.get_output(input).shape[1]
return self.get_output(input_instance).shape[1]
2 changes: 1 addition & 1 deletion dice_ml/model_interfaces/keras_tensorflow_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_output(self, input_tensor, training=False, transform_data=False):
else:
return self.model(input_tensor)

def get_gradient(self, input):
def get_gradient(self, input_instance):
# Future Support
raise NotImplementedError("Future Support")

Expand Down
2 changes: 1 addition & 1 deletion dice_ml/model_interfaces/pytorch_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_output(self, input_tensor, transform_data=False):
def set_eval_mode(self):
self.model.eval()

def get_gradient(self, input):
def get_gradient(self, input_instance):
# Future Support
raise NotImplementedError("Future Support")

Expand Down
4 changes: 2 additions & 2 deletions dice_ml/utils/sample_architecture/vae_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def forward(self, x, c):
res['z'] = []
res['x_pred'] = []
res['mc_samples'] = mc_samples
for i in range(mc_samples):
for _ in range(mc_samples):
z = self.sample_latent_code(em, ev)
x_pred = self.decoder(torch.cat((z, c), 1))
res['z'].append(z)
Expand Down Expand Up @@ -239,7 +239,7 @@ def forward(self, x):
res['z'] = []
res['x_pred'] = []
res['mc_samples'] = mc_samples
for i in range(mc_samples):
for _ in range(mc_samples):
z = self.sample_latent_code(em, ev)
x_pred = self.decoder(z)
res['z'].append(z)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# -- Project information -----------------------------------------------------

project = 'DiCE'
copyright = '2020, Ramaravind, Amit, Chenhao'
copyright = '2020, Ramaravind, Amit, Chenhao' # noqa: A001
author = 'Ramaravind, Amit, Chenhao'

# The full version, including alpha/beta/rc tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"elapsed_kd = 0\n",
"elapsed_genetic = 0\n",
"\n",
"for i in range(num_loops):\n",
"for _ in range(num_loops):\n",
" for q in query_instances:\n",
" if q in d.categorical_feature_names:\n",
" query_instances.loc[:, q] = \\\n",
Expand Down
5 changes: 5 additions & 0 deletions environment-deeplearning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: example-environment

dependencies:
- tensorflow>=1.13.0-rc1
- pytorch
9 changes: 9 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: example-environment

dependencies:
- numpy
- scikit-learn
- pandas
- h5py
- jsonschema
- tqdm
1 change: 0 additions & 1 deletion requirements-deeplearning.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
tensorflow>=1.13.0-rc1
torch
torchvision
4 changes: 4 additions & 0 deletions requirements-linting.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
flake8==3.9.2
flake8-bugbear==21.11.29
flake8-blind-except==0.1.1
flake8-builtins==1.5.3
flake8-logging-format==0.6.0
flake8-nb==0.3.0
isort
4 changes: 3 additions & 1 deletion tests/test_model_interface/test_keras_tensorflow_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@ def test_model_output(self, sample_adultincome_query, public_data_object, predic
predictval = self.sess.run(output_instance)[0][0]
else:
predictval = output_instance.numpy()[0][0]
pytest.approx(predictval, abs=1e-3) == prediction
assert predictval is not None
# TODO: The assert below fails.
# assert pytest.approx(predictval, abs=1e-3) == prediction
4 changes: 3 additions & 1 deletion tests/test_model_interface/test_pytorch_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ def test_model_output(self, sample_adultincome_query, public_data_object, predic
self.m.transformer.initialize_transform_func()
output_instance = self.m.get_output(sample_adultincome_query, transform_data=True)
predictval = output_instance.detach().numpy()[0][0]
pytest.approx(predictval, abs=1e-3) == prediction
assert predictval is not None
# TODO: The assert below fails.
# assert pytest.approx(predictval, abs=1e-3) == prediction
2 changes: 1 addition & 1 deletion tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _check_notebook_cell_outputs(filepath):
for cell in nb.cells:
if "outputs" in cell:
if len(cell['outputs']) > 0:
assert False, "Output cell found in notebook. Please clean your notebook"
raise AssertionError("Output cell found in notebook. Please clean your notebook")


def _notebook_run(filepath):
Expand Down

0 comments on commit f719519

Please sign in to comment.