Infinite loop in specific conditions
See original GitHub issueThe 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:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
ingenerate_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?
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
.