1
我試圖實現一個損失函數,該函數試圖最小化從預測的雙變量高斯分佈參數獲得地面實際值(x,y)的負對數可能性。我在tensorflow實現此 - 這裏是代碼 -雙變量高斯的對數似然的負值
def tf_2d_normal(self, x, y, mux, muy, sx, sy, rho):
'''
Function that implements the PDF of a 2D normal distribution
params:
x : input x points
y : input y points
mux : mean of the distribution in x
muy : mean of the distribution in y
sx : std dev of the distribution in x
sy : std dev of the distribution in y
rho : Correlation factor of the distribution
'''
# eq 3 in the paper
# and eq 24 & 25 in Graves (2013)
# Calculate (x - mux) and (y-muy)
normx = tf.sub(x, mux)
normy = tf.sub(y, muy)
# Calculate sx*sy
sxsy = tf.mul(sx, sy)
# Calculate the exponential factor
z = tf.square(tf.div(normx, sx)) + tf.square(tf.div(normy, sy)) - 2*tf.div(tf.mul(rho, tf.mul(normx, normy)), sxsy)
negRho = 1 - tf.square(rho)
# Numerator
result = tf.exp(tf.div(-z, 2*negRho))
# Normalization constant
denom = 2 * np.pi * tf.mul(sxsy, tf.sqrt(negRho))
# Final PDF calculation
result = -tf.log(tf.div(result, denom))
return result
當我做培訓,我可以看到損耗值減少,但它遠遠低於過去0我可以理解,應該是因爲,我們正在將「負面」可能性降至最低。即使損失值正在下降,我也無法獲得準確的結果。如果我爲損失函數編寫的代碼是否正確,是否有人可以幫助驗證?
也是這樣的性質損失理想的訓練神經網絡(特別是RNN)?
Thankss