I am new to python and statistical programming. For a class assignment we've been asked to implement python lasso L1 regression. This involves using a QP solver to solve .
0.5 *(x^t * H * x) + f^t * H
st x > 0 (every element of x is greater than zero)
These are block vectors and matrices. I am using 2 dimensional arrays for vectors and four dimensional array for the matrix H
def function(x):
x = x.reshape(2, -1)
return 0.5*np.tensordot(x,(np.tensordot(H,x,([1,3],[0,1]))),([0,1],[0,1])) + np.tensordot(f,x,([0,1],[0,1]))
initial_val = np.random.randn(2 * (k+1)).reshape((2,k+1))
bnds = (0,None)
theta = scipy.optimize.minimize(function, initial_val, method="SLSQP", bounds=bnds)
But still I am getting negative values in theta.x vector. Could anyone tell me Where am I going wrong?
functionandinitial_val, the error might lie with those.