Fix weighted minkowski grad
@@ -214,7 +214,11 @@ def weighted_minkowski_grad(x, y, w=_mock_ones, p=2):
result = 0.0
for i in range(x.shape[0]):
result += (w[i] * np.abs(x[i] - y[i])) ** p
- grad = w ** p * abs(x - y) ** (p - 1) * np.sign(x - y) * result ** (1.0 / p - 1)
+
+ grad = np.empty(x.shape[0], dtype=np.float32)
+ for i in range(x.shape[0]):
+ grad[i] = w[i] ** p * pow(np.abs(x[i] - y[i]), (p - 1.0)) * \
+ sign(x[i] - y[i]) * pow(result, (1.0 / (p - 1)))
return result ** (1.0 / p), grad
