Skip to content

Commit a92377e

Browse files
committed
multilabel QUIRE speed up a bit
1 parent 145e131 commit a92377e

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

libact/query_strategies/multilabel/multilabel_quire.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __init__(self, dataset, lamba=1.0, kernel='rbf', gamma=1., coef0=1.,
9797

9898
self.random_state_ = seed_random_state(random_state)
9999

100+
@profile
100101
@inherit_docstring_from(QueryStrategy)
101102
def make_query(self):
102103
dataset = self.dataset
@@ -120,24 +121,21 @@ def make_query(self):
120121
R = np.nan_to_num(R)
121122

122123
L = lamba * (np.linalg.pinv(np.kron(R, K) + lamba * np.eye(n*m)))
123-
inv_L = np.linalg.pinv(L)
124124

125125
vecY = np.reshape(np.array([y for y in Y if y is not None]), (-1, 1))
126126
invLuu = np.linalg.pinv(L[np.ix_(u, u)])
127127

128128
score = np.zeros((n, m))
129+
vYLllvY = np.dot(np.dot(vecY.T, L[np.ix_(l, l)]), vecY)[0, 0]
130+
U = np.dot(L[np.ix_(u, l)], vecY)
131+
temp0 = -(np.dot(np.dot(U.T, invLuu), U))[0, 0]
129132
for a in range(n):
130133
for b in range(m):
131134
s = b*n + a
132-
U = np.dot(L[np.ix_(u, l)], vecY) + L[np.ix_(u, [s])]
133-
temp1 = 2 * np.dot(L[[s], l], vecY) \
134-
- np.dot(np.dot(U.T, invLuu), U)
135-
U = np.dot(L[np.ix_(u, l)], vecY)
136-
temp0 = -(np.dot(np.dot(U.T, invLuu), U))
137-
score[a, b] = L[s, s] \
138-
+ np.dot(np.dot(vecY.T, L[np.ix_(l, l)]),
139-
vecY)[0, 0]\
140-
+ np.max((temp1[0, 0], temp0[0, 0]))
135+
tU = U + L[np.ix_(u, [s])]
136+
temp1 = (2 * np.dot(L[[s], l], vecY) \
137+
- np.dot(np.dot(tU.T, invLuu), tU))[0, 0]
138+
score[a, b] = L[s, s] + vYLllvY + np.max((temp1, temp0))
141139

142140
score = np.sum(score, axis=1)
143141

0 commit comments

Comments
 (0)