weighted_pick(weights) in model.py can return an index which is larger than len(chars)-1
this happens if sum(weights)<1, and at the same time np.random.rand(1)>sum(weights)
then, int(np.searchsorted(t, np.random.rand(1)*s) )==len(t), which leads to an IndexError
import numpy as np
p=np.array([ 0.1, 0.2, 0.699 ], dtype=np.float32)
t = np.cumsum(p)
s = np.sum(p)
randval=0.9999
print int(np.searchsorted(t, randval)) # gives 3, which is too large, as len(t)==3
so probably numpy.random.choice() is the better choice, despite being slower
weighted_pick(weights)
in model.py can return an index which is larger than len(chars)-1this happens if
sum(weights)<1
, and at the same timenp.random.rand(1)>sum(weights)
then,
int(np.searchsorted(t, np.random.rand(1)*s) )==len(t)
, which leads to an IndexErrorso probably numpy.random.choice() is the better choice, despite being slower