Skip to content

Commit

Permalink
Fixed bug in truncnorm sampling where min == max
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotcr committed Jul 5, 2019
1 parent 7bd4f16 commit 601b711
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lime/discretize.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,15 @@ def get_undiscretize_value(self, feature, val):
stds = self.stds[feature]
minz = (mins[val] - means[val]) / stds[val]
maxz = (maxs[val] - means[val]) / stds[val]
self.undiscretize_precomputed[feature][val] = (
scipy.stats.truncnorm.rvs(
minz, maxz, loc=means[val], scale=stds[val],
random_state=self.random_state, size=self.precompute_size))
if minz == maxz:
self.undiscretize_precomputed[feature][val] = (
np.ones(self.precompute_size) * minz)
else:
self.undiscretize_precomputed[feature][val] = (
scipy.stats.truncnorm.rvs(
minz, maxz, loc=means[val], scale=stds[val],
random_state=self.random_state,
size=self.precompute_size))
idx = self.undiscretize_idxs[feature][val]
ret = self.undiscretize_precomputed[feature][val][idx]
self.undiscretize_idxs[feature][val] += 1
Expand Down

0 comments on commit 601b711

Please sign in to comment.