I have the following code snippet for CVXPY:
delta=1e-3
loglambda = rvec*theta #rvec: TxJ regressor matrix, theta: (Jx1) cvx variable
a= mul_elemwise(dy[0:T],loglambda) # size(Tx1)
b1=cvx.exp(loglambda)
b2=mul_elemwise(delta,b1)
cost= -a + b1
#cost= -a + b2 #size (Tx1)
prob = Problem(Minimize(sum_entries(cost)))
prob.solve(solver=SCS)
The code runs fine as it is with cost = - a + b1
. However, if I try to multiply b1
with a scalar using mul_elemwise
and try to run it with cost = - a + b2
, I get the error message:
UnboundLocalError: Local variable 'coeff' referenced before assignment.