def dgap_l21(M, G, X, active_set, alpha, n_orient):
 GX = np.dot(G[:, active_set], X)
 R = (M - GX)
 penalty = norm_l21(X, n_orient, copy=True)
 nR2 = sum_squared(R)
 pobj = ((0.5 * nR2) + (alpha * penalty))
 dual_norm = norm_l2inf(np.dot(G.T, R), n_orient, copy=False)
 scaling = (alpha / dual_norm)
 scaling = min(scaling, 1.0)
 dobj = (((0.5 * (scaling ** 2)) * nR2) + (scaling * np.sum((R * GX))))
 gap = (pobj - dobj)
 return (gap, pobj, dobj, R)

def dgap_l21 ( M , G , X , active_set , alpha , n_orient ) : GX = np . dot ( G [ : , active_set ] , X ) R = ( M - GX ) penalty = norm_l21 ( X , n_orient , copy = True ) nR2 = sum_squared ( R ) pobj = ( ( 0.5 * nR2 ) + ( alpha * penalty ) ) dual_norm = norm_l2inf ( np . dot ( G . T , R ) , n_orient , copy = False ) scaling = ( alpha / dual_norm ) scaling = min ( scaling , 1.0 ) dobj = ( ( ( 0.5 * ( scaling ** 2 ) ) * nR2 ) + ( scaling * np . sum ( ( R * GX ) ) ) ) gap = ( pobj - dobj ) return ( gap , pobj , dobj , R )
duality gaps for the mixed norm inverse problem .