Skip to content

Commit bce0158

Browse files
ankh1999erdogant
authored andcommitted
fix 2 minor bugs
1 parent 2c059df commit bce0158

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

bnlearn/bnlearn.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,11 +1549,12 @@ def predict(model, df, variables, to_df=True, method='max', verbose=3):
15491549

15501550
# %%
15511551
def _get_prob(query, method='max'):
1552-
# Setup all combinations
1553-
allcomb = np.array(list(itertools.product([0, 1], repeat=len(query.variables))))
1554-
# Get highest P-value and gather data
1555-
Pq = query.values.flatten()
15561552
if method=='max':
1553+
# Setup all combinations
1554+
possible_values = query.state_names.values()
1555+
allcomb = np.array(list(itertools.product(*possible_values)))
1556+
# Get highest P-value and gather data
1557+
Pq = query.values.flatten()
15571558
idx = np.argmax(Pq)
15581559
comb = allcomb[idx]
15591560
p = Pq[idx]

bnlearn/discretize/learn_discrete_bayes_net.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,11 @@ def prior_of_intval(continuous: pd.Series, lam: int) -> np.ndarray:
167167
N = len(continuous)
168168
d_1_N = continuous.iloc[N - 1] - continuous.iloc[0]
169169
prior = np.zeros(N, dtype="float64")
170+
# Small positive number to avoid zero
171+
epsilon = 1e-10
170172
for i in range(N - 1):
171173
d_i = continuous.iloc[i + 1] - continuous.iloc[i]
172-
prior[i] = 1 - math.exp(-lam * d_i / d_1_N)
174+
prior[i] = 1 - math.exp(-lam * d_i / d_1_N) + epsilon
173175
prior[N - 1] = 1
174176

175177
return prior

0 commit comments

Comments
 (0)