Computes the gradient of KL divergence with respect to the i'th example of Y

def gradient(self, P, Q, Y, i):
        """Computes the gradient of KL divergence with respect to the i'th example of Y"""

        return 4 * sum([
            (P[i, j] - Q[i, j]) * (Y[i] - Y[j]) * (1 + np.linalg.norm(Y[i] - Y[j]) ** 2) ** -1 \
            for j in range(Y.shape[0])
        ])