Skip to content

Commit 8af7d80

Browse files
committed
Remove custom implementation of softmax in metropolis.py
1 parent 614afcf commit 8af7d80

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

pymc/step_methods/metropolis.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import numpy as np
1717
import numpy.random as nr
1818
import scipy.linalg
19+
import scipy.special
1920

2021
from aesara.graph.fg import MissingInputError
2122
from aesara.tensor.random.basic import BernoulliRV, CategoricalRV
@@ -608,7 +609,7 @@ def metropolis_proportional(self, q, logp, logp_curr, dim, k):
608609
if candidate_cat != given_cat:
609610
q.data[dim] = candidate_cat
610611
log_probs[candidate_cat] = logp(q)
611-
probs = softmax(log_probs)
612+
probs = scipy.special.softmax(log_probs, axis=0)
612613
prob_curr, probs[given_cat] = probs[given_cat], 0.0
613614
probs /= 1.0 - prob_curr
614615
proposed_cat = nr.choice(candidates, p=probs)
@@ -995,11 +996,6 @@ def sample_except(limit, excluded):
995996
return candidate
996997

997998

998-
def softmax(x):
999-
e_x = np.exp(x - np.max(x))
1000-
return e_x / np.sum(e_x, axis=0)
1001-
1002-
1003999
def delta_logp(point, logp, vars, shared):
10041000
[logp0], inarray0 = pm.join_nonshared_inputs(point, [logp], vars, shared)
10051001

0 commit comments

Comments
 (0)