When I use this random generator: numpy.random.multinomialI keep getting:
ValueError: sum(pvals[:-1]) > 1.0
I always pass the output of this softmax function:
def softmax(w, t = 1.0):
e = numpy.exp(numpy.array(w) / t)
dist = e / np.sum(e)
return dist
in addition to getting this error, I also added this for the ( pvals) parameter :
while numpy.sum(pvals) > 1:
pvals /= (1+1e-5)
but it didn’t decide. What is the correct way to avoid this error?
EDIT: here is the function that includes this code
def get_MDN_prediction(vec):
coeffs = vec[::3]
means = vec[1::3]
stds = np.log(1+np.exp(vec[2::3]))
stds = np.maximum(stds, min_std)
coe = softmax(coeffs)
while np.sum(coe) > 1-1e-9:
coe /= (1+1e-5)
coeff = unhot(np.random.multinomial(1, coe))
return np.random.normal(means[coeff], stds[coeff])
source
share