I have a convex objective function named "obj_lasso". The minimisation is with respect to a vector v1 of dimension (p=7). The minimisation is going for 500 iterations. That is, at each iteration, it should return a vector v1. For that I am using syntax
result_lasso$getValue(v1)
But it returns the following error :
"Error in result _lasso$getValue(v1) : attempt to apply non function"
after say 35 iterations.
Anyone please help how to overcome this issue. Thanks in advance.
I am attaching the script and error message also.
Before giving the code here is some remark :
- lambda_opt and alpha_shape are two known scalars
- y is a known row vector of dimension (n=500, known)
- x is the known design matrix without intercept column of dimension (nxp i.e 500x7)
- v1 should return as a column vector of dimension (p=7)
- The following code is iterated 500 times(not necessarily our n and this count should match always) . Basically 500 copies of beta_hat_final3 are used in long run.
- I am getting error at "final_lasso" line say after 35 iterations.
Now, here is the code for mentioned issue:
library (CVXR)
v1 = CVXR:: Variable (p)
penalty_lasso = lambda_opt*(p_norm(v1,1))
l1= alpha_shape*(sum(x%*%v1))
z_1 = as.matrix(y)
l2 =alpha_shape*(sum((z_1*(exp(-(x%*%v1)))))
)
obj_lasso = l1+l2+penalty_lasso
prob_lasso = Problem (Minimize(obj_lasso))
result_lasso = solve(prob_lasso)
result_lasso
##to get that minimizer v1, I am using now this:
final_lasso = result_lasso$getValue(v1)
final_lasso1 = as.matrix(final_lasso)
beta_hat_final3 = t(final_lasso1) ### as a row vector
Here is the error message I am getting :
" Error in result_lasso$getValue(v1) : attempt to apply non-function".
please help . Thanks in advance.