better softmax clipping

This commit is contained in:
wassname
2017-11-12 14:41:24 +08:00
parent ae95c65246
commit 3597f185cc
+2 -1
View File
@@ -16,7 +16,8 @@ def MDD(returns):
def softmax(w, t=1.0):
"""softmax implemented in numpy."""
w = np.clip(w, -1000, 50) # avoid inf/nan
log_eps = np.log(eps)
w = np.clip(w, -log_eps, log_eps) # avoid inf/nan
e = np.exp(np.array(w) / t)
dist = e / np.sum(e)
return dist