CVXPY错误:“NotImplementedError:不允许严格的不等式”

2024-06-16 10:19:43 发布

您现在位置:Python中文网/ 问答频道 /正文

def PPNM_model(a,E, beta):

  p = E.shape[1] 
  x = E*a
  x = sum(x,beta*cp.square(x))
  return x

def PPNM_model_cvxpy(a,E,beta):
  first = E*a
  second = beta*cp.square(first)
  third = sum(first,second)
  return third

def construct_ppnm_model(x_in,A,E, x_LMM, a_lmm):
 p = E.shape[1]
 d = E.shape[0]
 N = A.shape[0]
 x = np.zeros(shape=(N,d), dtype=np.float64)
 a_ppnm = np.zeros(shape=(N,p), dtype=np.float64)
 beta_ppnm = np.zeros(shape=(N,1), dtype=np.float64)
 current_lmm = cp.Variable(p)
 current_beta = cp.Variable()
 b_min = 0
 b_max = 100
 all_zeros = np.squeeze(np.zeros(shape=(N,1), dtype=np.double))
 sum_to_one_vector=np.ones(shape=(1,p),dtype=np.double)
      for i in np.arange(0, N):

         x_in_temp = x_in[i,:].astype(np.double)
         current_lmm.value=a_lmm[i,]


         objective = 
                 cp.Minimize(cp.sum_squares((PPNM_model_cvxpy(current_lmm, 
                 E, current_beta)) - x_in_temp))
         constraints = [current_lmm >= 0, 
                   current_lmm <= 1,
                   current_beta >= b_min,
                   current_beta <= b_max,
                  sum_to_one_vector*current_lmm == 1]        
        prob = cp.Problem(objective, constraints)
        result = prob.solve()
        a_ppnm[i,:]=current_lmm.value
        beta_ppnm[i] = current_beta.value
       current_vector = PPNM_model(a_ppnm[i,:], E, current_beta.value)
       x[i,:]=current_vector        
return x, a_ppnm, beta_ppnm      

在这个问题中,矩阵A的形状是(10000,4),即(总像素,尾数),E的形状(198,4):(光谱带,尾数) 并且x的形状(10000,198):(像素,光谱带) 当我这样称呼construct ppnm_模型时:

^{pr2}$

我收到以下错误消息:

NotImplementedError: Strict inequalities are not allowed.


Tags: inmodelvaluenpzeroscurrentcpbeta