我想像论文https://pdfs.semanticscholar.org/4957/0fb292730a435b1e9e3a85a5dac36f784821.pdf中那样用CVXPY解决GROUP DANTZIG SELECTOR 但这给了我以下错误:
Traceback (most recent call last): File "/home/bognev/PycharmProjects/BSBL-LSTM-Net/dantzig_selector.py", line 83, in <module>
constr_f = [cp.norm(d_f,"Inf") <= p, sum(a) <= q] File "/home/bognev/anaconda3/lib/python3.7/site-packages/cvxpy/atoms/norm.py", line 43, in norm
x = Expression.cast_to_const(x) File "/home/bognev/anaconda3/lib/python3.7/site-packages/cvxpy/expressions/expression.py", line 417, in cast_to_const
return expr if isinstance(expr, Expression) else cvxtypes.constant()(expr) File "/home/bognev/anaconda3/lib/python3.7/site-packages/cvxpy/expressions/constants/constant.py", line 44, in __init__
self._value = intf.DEFAULT_INTF.const_to_matrix(value) File "/home/bognev/anaconda3/lib/python3.7/site-packages/cvxpy/interface/numpy_interface/ndarray_interface.py", line 50, in const_to_matrix
return result.astype(numpy.float64) ValueError: setting an array element with a sequence.
问题是我想找到最大值(EXPRESSIONS),而cvxpy无法解决它。 该公式在MATLAB CVX中工作正常 也许有人知道如何避免此错误?
lambdas_f = cp.Parameter(nonneg=True)
lambdas_f.value = 30
# Define problem
x_v_f = cp.Variable(input_size*num_groups)
p_f = cp.Variable(1)
q_f = cp.Variable(1)
G = np.zeros((input_size,num_groups,output_size))
a_f = []
d_f = []
for ii in range(input_size):
G[ii,:,:] = (F@A[:,ii:input_size*num_groups:input_size]).transpose()
for ii in range(input_size):
a_f.append(cp.norm(x_v_f[ii:input_size*num_groups:input_size],2))
for ii in range(input_size):
d_f.append(cp.norm(G[ii]@(y-F@A@x_v_f),2))
objective_f = 0.5*p**2+lambdas*q
constr_f = [cp.norm(d_f,"Inf") <= p, sum(a) <= q]
prob_f = cp.Problem(cp.Minimize(objective_f), constr_f)
prob_f.solve()