Skip to content

Commit e1d4e52

Browse files
committed
Merge branch 'master' into gaugup/AddValidationsToGenerateCounterfactuals
2 parents d4d51aa + e6a1dc3 commit e1d4e52

21 files changed

Lines changed: 132 additions & 19 deletions

.github/workflows/code-scan.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: code scan
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
analyze:
11+
name: Analyze
12+
runs-on: ubuntu-latest
13+
permissions:
14+
actions: read
15+
contents: read
16+
security-events: write
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
language: ["python"]
22+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
23+
# Learn more:
24+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v2
29+
30+
# Initializes the CodeQL tools for scanning.
31+
- name: Initialize CodeQL
32+
uses: github/codeql-action/init@v1
33+
with:
34+
languages: ${{ matrix.language }}
35+
# If you wish to specify custom queries, you can do so here or in a config file.
36+
# By default, queries listed here will override any specified in a config file.
37+
# Prefix the list here with "+" to use these queries and those in the config file.
38+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
39+
40+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
41+
# If this step fails, then you should remove it and run the build manually (see below)
42+
- name: Autobuild
43+
uses: github/codeql-action/autobuild@v1
44+
45+
# ℹ️ Command-line programs to run using the OS shell.
46+
# 📚 https://git.io/JvXDl
47+
48+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
49+
# and modify them (or add more) to build your code if your project
50+
# uses a compiled language
51+
52+
#- run: |
53+
# make bootstrap
54+
# make release
55+
56+
- name: Perform CodeQL Analysis
57+
uses: github/codeql-action/analyze@v1

.github/workflows/python-linting.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip
25-
python -m pip install flake8==3.9.2 flake8-nb==0.3.0 isort
25+
pip install -r requirements-linting.txt
2626
- name: Check sorted python imports using isort
2727
run: |
2828
isort . -c
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Python Package using Conda
2+
3+
on: [push]
4+
5+
jobs:
6+
build-linux:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
max-parallel: 5
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Set up Python 3.8
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.8
17+
- name: Add conda to system path
18+
run: |
19+
# $CONDA is an environment variable pointing to the root of the miniconda directory
20+
echo $CONDA/bin >> $GITHUB_PATH
21+
- name: Install core dependencies
22+
run: |
23+
conda env update --file environment.yml --name base
24+
- name: Install deep learning dependencies
25+
run: |
26+
conda env update --file environment-deeplearning.yml --name base
27+
- name: Test with pytest
28+
run: |
29+
conda install pytest ipython jupyter nbformat pytest-mock
30+
31+
pytest

dice_ml/data_interfaces/public_data_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def get_valid_feature_range(self, feature_range_input, normalized=True):
260260
"""
261261
feature_range = {}
262262

263-
for idx, feature_name in enumerate(self.feature_names):
263+
for _, feature_name in enumerate(self.feature_names):
264264
feature_range[feature_name] = []
265265
if feature_name in self.continuous_feature_names:
266266
max_value = self.data_df[feature_name].max()

dice_ml/explainer_interfaces/dice_KD.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def find_counterfactuals(self, data_df_copy, query_instance, query_instance_orig
260260
if total_cfs_found < total_CFs:
261261
self.elapsed = timeit.default_timer() - start_time
262262
m, s = divmod(self.elapsed, 60)
263-
print('Only %d (required %d) ' % (total_cfs_found, self.total_CFs),
263+
print('Only %d (required %d) ' % (total_cfs_found, total_CFs),
264264
'Diverse Counterfactuals found for the given configuation, perhaps ',
265265
'change the query instance or the features to vary...' '; total time taken: %02d' % m,
266266
'min %02d' % s, 'sec')

dice_ml/explainer_interfaces/dice_tensorflow2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def do_cf_initializations(self, total_CFs, algorithm, features_to_vary):
177177
# CF initialization
178178
if len(self.cfs) != self.total_CFs:
179179
self.cfs = []
180-
for ix in range(self.total_CFs):
180+
for _ in range(self.total_CFs):
181181
one_init = [[]]
182182
for jx in range(self.minx.shape[1]):
183183
one_init[0].append(np.random.uniform(self.minx[0][jx], self.maxx[0][jx]))

dice_ml/explainer_interfaces/explainer_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def feature_importance(self, query_instances, cf_examples_list=None,
380380
continue
381381

382382
per_query_point_cfs = 0
383-
for index, row in df.iterrows():
383+
for _, row in df.iterrows():
384384
per_query_point_cfs += 1
385385
for col in self.data_interface.continuous_feature_names:
386386
if not np.isclose(org_instance[col].iat[0], row[col]):
@@ -561,7 +561,7 @@ def misc_init(self, stopping_threshold, desired_class, desired_range, test_pred)
561561
self.target_cf_class = np.array(
562562
[[self.infer_target_cfs_class(desired_class, test_pred, self.num_output_nodes)]],
563563
dtype=np.float32)
564-
desired_class = self.target_cf_class[0][0]
564+
desired_class = int(self.target_cf_class[0][0])
565565
if self.target_cf_class == 0 and self.stopping_threshold > 0.5:
566566
self.stopping_threshold = 0.25
567567
elif self.target_cf_class == 1 and self.stopping_threshold < 0.5:

dice_ml/explainer_interfaces/feasible_base_vae.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def generate_counterfactuals(self, query_instance, total_CFs, desired_class="opp
186186
curr_cf_pred = []
187187
curr_test_pred = train_y.numpy()
188188

189-
for cf_count in range(total_CFs):
189+
for _ in range(total_CFs):
190190
recon_err, kl_err, x_true, x_pred, cf_label = \
191191
self.cf_vae.compute_elbo(train_x, 1.0-train_y, self.pred_model)
192192
while(cf_label == train_y):

dice_ml/model_interfaces/base_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def get_num_output_nodes(self, inp_size):
6464
temp_input = np.transpose(np.array([np.random.uniform(0, 1) for i in range(inp_size)]).reshape(-1, 1))
6565
return self.get_output(temp_input).shape[1]
6666

67-
def get_num_output_nodes2(self, input):
67+
def get_num_output_nodes2(self, input_instance):
6868
if self.model_type == ModelTypes.Regressor:
6969
raise SystemException('Number of output nodes not supported for regression')
70-
return self.get_output(input).shape[1]
70+
return self.get_output(input_instance).shape[1]

dice_ml/model_interfaces/keras_tensorflow_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_output(self, input_tensor, training=False, transform_data=False):
4040
else:
4141
return self.model(input_tensor)
4242

43-
def get_gradient(self, input):
43+
def get_gradient(self, input_instance):
4444
# Future Support
4545
raise NotImplementedError("Future Support")
4646

0 commit comments

Comments
 (0)