coefficient of correlation loss
ipingtw opened this issue · 0 comments
ipingtw commented
`
def correlation_coefficient(y_true, y_pred):
max_y_pred = K.repeat_elements(K.expand_dims(K.repeat_elements(K.expand_dims(K.max(K.max(y_pred, axis=2), axis=2)),
shape_r_out, axis=-1)), shape_c_out, axis=-1)
y_pred /= max_y_pred
sum_y_true = K.repeat_elements(K.expand_dims(K.repeat_elements(K.expand_dims(K.sum(K.sum(y_true, axis=2), axis=2)),
shape_r_out, axis=-1)), shape_c_out, axis=-1)
sum_y_pred = K.repeat_elements(K.expand_dims(K.repeat_elements(K.expand_dims(K.sum(K.sum(y_pred, axis=2), axis=2)),
shape_r_out, axis=-1)), shape_c_out, axis=-1)
y_true /= (sum_y_true + K.epsilon())
y_pred /= (sum_y_pred + K.epsilon())
N = shape_r_out * shape_c_out
sum_prod = K.sum(K.sum(y_true * y_pred, axis=2), axis=2)
sum_x = K.sum(K.sum(y_true, axis=2), axis=2)
sum_y = K.sum(K.sum(y_pred, axis=2), axis=2)
sum_x_square = K.sum(K.sum(K.square(y_true), axis=2), axis=2)
sum_y_square = K.sum(K.sum(K.square(y_pred), axis=2), axis=2)
num = sum_prod - ((sum_x * sum_y) / N)
den = K.sqrt((sum_x_square - K.square(sum_x) / N) * (sum_y_square - K.square(sum_y) / N))
return -2 * num / den
`
Hi
thank you for this repo. I am trying to replicate your work but I am having some question understanding your implementation of coefficient of correlation.
Can you please explain why did you divided the prediction by max valuse in the array, and divided both prediction and ground truth by their sum respectively. Is this some kind of optimization trick?