Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wachter.py #179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions carla/recourse_methods/catalog/wachter/library/wachter.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def wachter_recourse(
t_max = datetime.timedelta(minutes=t_max_min)
while f_x_new <= DECISION_THRESHOLD:
it = 0
while f_x_new <= 0.5 and it < n_iter:
while f_x_new <= DECISION_THRESHOLD and it < n_iter:
optimizer.zero_grad()
x_new_enc = reconstruct_encoding_constraints(
x_new, cat_feature_indices, binary_cat_features
Expand Down Expand Up @@ -146,8 +146,5 @@ def wachter_recourse(
lamb -= 0.05

if datetime.datetime.now() - t0 > t_max:
log.info("Timeout - No Counterfactual Explanation Found")
break
elif f_x_new >= 0.5:
log.info("Counterfactual Explanation Found")
return x_new_enc.cpu().detach().numpy().squeeze(axis=0)