Data_Driven_Science_Python_Demos icon indicating copy to clipboard operation
Data_Driven_Science_Python_Demos copied to clipboard

Faster linear programming alternative to `scipy.optimize.minimize` for solving basis pursuit problems

Open winwinashwin opened this issue 3 years ago • 0 comments

The scipy.optimize.minimize method tends to be really slow for solving the basis pursuit problem (ex. in the compressed sensing context) especially when we are dealing with less sparse vectors. A much faster alternative could be used by modelling the problem as a linear programming problem and using scipy.optimize.linprog instead

def basis_pursuit_v2(A, y):
    """Objective : minimize(  norm(x, 1)  )
       Subject to: A * x == y
    """
    numCols = A.shape[1]

    vF = np.ones((2 * numCols, 1))
    mAeq = np.hstack([A, -A])
    vBeq = y

    vUV = linprog(vF, None, None, mAeq, vBeq, bounds=(0, np.inf))
    return vUV.x[:numCols] - vUV.x[numCols:]

This answer explains the LP modelling

winwinashwin avatar Oct 14 '22 06:10 winwinashwin