def cond_projsplx_multi(Y,a_mat):
n, m = Y.shape
A = a_mat
s = -np.sort(-(A*Y),axis=1)
index = np.argsort(-(A*Y), axis=1)
tmpsum = np.zeros(n)
tmpsumdom = np.zeros(n)
bget = np.zeros(n, dtype=bool)
A_sort = A[np.arange(np.shape(A)[0])[:,np.newaxis], index]
cond_s = s/(A_sort**2)
tmax = np.zeros(n)
for ii in xrange(0,m-1):
active = (bget==False)
tmpsum[active] = tmpsum[active] + cond_s[active][:,ii]
tmpsumdom[active] = tmpsumdom[active]+ 1.0/A_sort[active][:,ii]**2
tmax[active] = (tmpsum[active] - 1)/tmpsumdom[active]
deactivate = (tmax >= s[:,ii+1]) & active
bget[deactivate] = True
active = (bget==False)
tmax[active] = (tmpsum[active] + cond_s[active][:,m-1] - 1)/(tmpsumdom[active]+1.0/(A_sort[active][:,m-1])**2)
X = (Y - np.matlib.repmat(tmax.reshape(n,1),1,m)*1.0/A)
X[X<0.0] = 0.0
X = X/A
return X
评论列表
文章目录