Skip to content

Commit

Permalink
Remove custom implementation of softmax in metropolis.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoV94 authored and twiecki committed Jan 20, 2022
1 parent ee2f18a commit 9af9320
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions pymc/step_methods/metropolis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import numpy as np
import numpy.random as nr
import scipy.linalg
import scipy.special

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


def softmax(x):
e_x = np.exp(x - np.max(x))
return e_x / np.sum(e_x, axis=0)


def delta_logp(point, logp, vars, shared):
[logp0], inarray0 = pm.join_nonshared_inputs(point, [logp], vars, shared)

Expand Down

0 comments on commit 9af9320

Please sign in to comment.