I'm trying to write down the gini index calculation as a tensorflow cost function. Gini index is: https://en.wikipedia.org/wiki/Gini_coefficient
a numpy solution would be
def ginic(actual, pred):
n = len(actual)
a_s = actual[np.argsort(pred)]
a_c = a_s.cumsum()
giniSum = a_c.sum() / a_s.sum() - (n + 1) / 2.0
return giniSum / n
Can someone help me figure out how to do this in tf (for example, in tf there is no argsort that can be part of a function that is differentiated, AFAIK)