Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def temperature(y, T):
y = y**(1 / T)
return y / dd.apply_once(np.sum, y, [1])
M = 2500
for k in range(int(np.ceil(X.shape[0] / M))):
y = self.net_.forward_all(data=X[k*M:(k+1)*M]).values()[0].squeeze(axis=(2,3))
prob[k*M:(k+1)*M] = y
T = 30.0
eps = 0.0001
#prob = prob.clip(eps, 1-eps)
log_prob = np.log(prob)
print('log_prob', log_prob.min(), log_prob.max())
#log_prob = log_prob.clip(min=-4, max=4)
new_prob = np.exp(log_prob / T)
new_prob /= dd.apply_once(np.sum, new_prob, [1])
return new_prob