question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite loop in specific conditions

See original GitHub issue

https://github.com/interpretml/DiCE/blob/a772c8d4fcd88d1cab7f2e02b0bcc045dc0e2eab/dice_ml/explainer_interfaces/explainer_base.py#L73

The post-hoc sparsity enhancement can enter in an infinite loop in certain conditions (I tested with all numerical data, with data ranging, mostly, from -1 to 1). If you need, I can attach here the data. The cause is, for small numbers, sometimes the rate of change is very small or even zero, then, it stucks in this step.

I think one possible solution is to check the difference between the new diff and old difference old_diff, something like:

        if (old_diff == diff) or ((old_diff-diff) < 1e-5):
            n_tolerance += 1
        else:
            n_tolerance = 0

and adding another stop condition on the while loop: n_tolerance <= max_tolerance

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
raam93commented, Nov 23, 2020

Yes, that’s a good catch! Indeed, it gets stuck in an infinite loop for values much lower than zero. However, the default sparsity correction method that you are using performs a linear search. If the option posthoc_sparsity_algorithm in generate_counterfactuals() is changed to “binary”, which performs a binary search instead, the results are much faster. We have observed the binary option work well in practice with few real-world datasets. Can you try it and let me know how it goes?

That said, for the linear method, I really like your suggestion! Can you please raise a PR on the same?

0reactions
rmazzinecommented, May 8, 2022

Sorry for the late response!

Here’s the updated notebook reproducing the problem: https://colab.research.google.com/drive/1vIJ79cV1WmNAl2usZJIBNIxdcFQn3H_h?usp=sharing

I think the solution can be simpler. From my tests, the linear search should not take more than 10k steps. Therefore, just adding a counter and establishing an upper limit is sufficient.

You can see this change in this commit: https://github.com/rmazzine/DiCE/commit/22f2c12d822a7bcb26a5b1f169e601b217c022cb

And in this notebook below you can see it fixes the problem: https://colab.research.google.com/drive/1W6nlXucrure8hNwQ2bByjxdlxmtF-i3r?usp=sharing

This PR (https://github.com/interpretml/DiCE/pull/293) does that. Therefore, I implement an additional condition for the number of steps that can be changed by the user by modifying the parameter limit_steps_ls.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intentional Infinite Loops - Incremental Java
An infinite loop occurs when a condition always evaluates to true. Usually, this is an error. For example, you might have a loop...
Read more >
Infinite loops and break · CodeCraft-Python - BuzzCoder
This means that i < 10 will always be true and the loop will never end. This is called an infinite loop, which...
Read more >
Infinite Loop in C - Javatpoint
An infinite loop is a looping construct that does not terminate the loop and executes the loop forever. It is also called an...
Read more >
Top 5 Examples of the Infinite Loop in C - eduCBA
A loop that repeats indefinitely and does not terminate is called an infinite loop. An infinite loop also called as endless loop or...
Read more >
Infinite loop in C programming | For while do-while
An infinite loop is one that does not terminate the loop from its looping condition. An infinite loop can be needed in programming...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found