Skip to content

Commit

Permalink
latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
youssefmecky96 committed Nov 8, 2023
1 parent 78146cc commit 48dc500
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion icu_benchmarks/models/dl_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ def forward(
# out = out["prediction"].reshape(1, -1)

pred = self.logit(out["prediction"])

print(pred)
return pred


Expand Down
11 changes: 7 additions & 4 deletions icu_benchmarks/models/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def explantation_captum(self, test_loader, method, log_dir=".", plot=False, **kw
# Reformat attributions.
attr_all_timesteps = []
for time_step in range(0, 24):
attr, delta = explantation.attribute(
attr = explantation.attribute(
data, target=(time_step, 1), baselines=baselines, **kwargs
)
# Convert attributions to numpy array and append to the list
Expand All @@ -546,9 +546,10 @@ def explantation_captum(self, test_loader, method, log_dir=".", plot=False, **kw
# Concatenate a‚ttribution values for all instances along the batch dimension
all_attrs = np.mean(all_attrs, axis=0)
means_feature = all_attrs.mean(axis=(0, 1))

self.log('Attribution Featues', means_feature)
# Compute mean along the batch dimension
means = all_attrs.mean(axis=(0, 2))
self.log('Attribution Time steps', means)
# Normalize the means values to range [0, 1]
# normalized_means = (means - means.min()) / (means.max() - means.min())
if plot:
Expand Down Expand Up @@ -687,7 +688,9 @@ def Faithfulness_Correlation(
att_sums.append(np.sum(attribution[a_ix]))

similarities.append(similarity_func(pred_deltas, att_sums))
return np.nanmean(similarities)
score = np.nanmean(similarities)
self.log('Faithfulness correlation', score)
return score

def Data_Randomization(self, test_loader, attribution, explain_method, random_model, similarity_func=None, test_dataset=None):
"""
Expand Down Expand Up @@ -762,7 +765,7 @@ def Data_Randomization(self, test_loader, attribution, explain_method, random_mo
# Normalize the means values to range [0, 1]
# normalized_a_perturbed = (a_perturbed - a_perturbed.min()) / (a_perturbed.max() - a_perturbed.min())
score = similarity_func(a_perturbed, attribution)

self.log('data_randomization', score)
return score


Expand Down
3 changes: 2 additions & 1 deletion icu_benchmarks/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ def main(my_args=tuple(sys.argv[1:])):
explain=explain,
pytorch_forecasting=pytorch_forecasting,
XAI_metric=XAI_metric,
random_model_dir=random_model_dir
random_model_dir=random_model_dir,
random_labels=random_labels,
)

log_full_line("FINISHED TRAINING", level=logging.INFO, char="=", num_newlines=3)
Expand Down

0 comments on commit 48dc500

Please sign in to comment.