Hy guys
I need to implement Aitchison loss function for validation between input and output datasets. Data is 2 dimensional ( batch, features ). Batch dim constructed as 'None' size dimension for a while
If loss function could work with numpy arrays, it could be done easily approx in such way
def loss_Aitch(yTrue, yPred):
yTrue_np = yTrue.numpy()
yPred_np = yPred.numpy()
sample_dist_mean = 0
for i in range(yTrue_np.shape[0]):
mult1 = 1.
mult2 = 1.
for j in range(yTrue_np.shape[1]):
mult1 *= yTrue_np[i, j]
mult2 *= yPred_np[i, j]
mult1 = np.sqrt(mult1)
mult2 = np.sqrt(mult2)
sample_dist = 0
for j in range(yTrue_np.shape[1]):
sample_dist += np.square( np.log( yTrue_np[i, j] / mult1) - np.log(yPred_np[i, j] / mult2 ) )
sample_dist = np.sqrt(sample_dist)
sample_dist_mean += sample_dist
sample_dist_mean /= yTrue_np.shape[0]
return sample_dist_mean
but since tensors are placeholders, that's doesn't work.
So how this function could be directly implemented on tensors?