Skip to content

Commit d5c9dd0

Browse files
author
William de Vazelhes
committed
Simplify expression
1 parent 61eea28 commit d5c9dd0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

metric_learn/lmnn.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,11 @@ def _loss_grad(self, X, L, dfG, impostors, it, k, reg, target_neighbors, df,
191191
# do the gradient update
192192
assert not np.isnan(df).any()
193193
G = dfG * reg + df * (1 - reg)
194-
195-
grad = 2 * L.dot(G)
194+
G = L.dot(G)
196195
# compute the objective function
197196
objective = total_active * (1 - reg)
198-
objective += G.flatten().dot(L.T.dot(L).flatten())
199-
return grad, objective, total_active, df, a1, a2
197+
objective += G.flatten().dot(L.flatten())
198+
return 2 * G, objective, total_active, df, a1, a2
200199

201200
def _select_targets(self, X, label_inds):
202201
target_neighbors = np.empty((X.shape[0], self.k), dtype=int)

0 commit comments

Comments
 (0)