Uh oh!
There was an error while loading. Please reload this page.
Broadcasting - #3
Conversation
shahin1009
commented
Jun 23, 2022
cvxpy pakage can manage the L1-norm optimization much faster than SLSQP method in scipy. The process of defining the problem is the same but I add comments to make it more readable. more detail on CVXPY pakage: import cvxpy as cp # defining parameters same as in the previous example # Creating cvxpy variables(the variable that we want to optimize) # Creating constraints (y = Theta * s) # creating objective # Solving the problem s_L1_cvxpy = s.value # s_L1_cvxpy is the optimized solution |
Using broadcasting to subtract the average face from the training faces, makes the code more readable.
X = trainingFaces - np.tile(avgFace,(trainingFaces.shape[1],1)).T
to:
X = trainingFaces - avgFace.reshape(-1,1).
avgFace.reshape(-1,1) is an array with shape=(32256,1). For conducting the subtraction, numpy would broadcast this array to (322561,n) so the shape become equal to trainingFaces.shape.