使用logcdf在cvxopt(python)中定义函数

使用logcdf在cvxopt(python)中定义函数,python,function,cdf,cvxopt,Python,Function,Cdf,Cvxopt,我想将目标函数定义为:-sum(log(normcdf(x)),其中normcdf作用于x的每个组件。看起来cvxpy已经实现了它,但我想继续使用Python中的cvxopt。有什么建议吗 ***** Example python code to make this question clearer: from cvxopt import spmatrix, log from cvxopt.modeling import variable, op, sum # A is m x n matri

我想将目标函数定义为:
-sum(log(normcdf(x))
,其中
normcdf
作用于
x
的每个组件。看起来
cvxpy
已经实现了它,但我想继续使用Python中的
cvxopt
。有什么建议吗

***** Example python code to make this question clearer:
from cvxopt import spmatrix, log
from cvxopt.modeling import variable, op, sum

# A is m x n matrix of type 'cvxopt.base.spmatrix' (not included here to save space)
# a_hat is n x 1 vector of type 'cvxopt.modeling.variable
a_hat = variable(n)

# constraints
c1 = (a_hat >= 0)
c2 = (a_hat <= 0)

#valid objective and optimization problem
f = -sum(A*a_hat)
op(f, [c1, c2]).solve()

# desired objective
# f = -sum(log( "cdf of each element of (A*a_hat)" ))

# this doesn't work either (because log 'argument must be a number of dense matrix')
# f = -sum(log(A*a_hat))
****让这个问题更清楚的python示例代码:
从cvxopt导入spmatrix,记录
从cvxopt.modeling导入变量,op,sum
#A是“cvxopt.base.spmatrix”类型的m x n矩阵(此处不包括以节省空间)
#a_hat是'cvxopt.modeling.variable'类型的nx1向量
a_hat=变量(n)
#约束条件
c1=(a_hat>=0)

c2=(a_hat我找到了这样做的方法:需要计算自己的梯度和hessian,并使用cvxopt.cp(下面,G和h是约束条件,为清楚起见省略)


你可能会想研究,它(以及)增加了对科学计算的支持,并为你提供了与Matlab所能做的几乎所有事情的等价物。特别是,它看起来像是你想研究这个模块,因为它看起来像是你在尝试做凸优化。
def myFunc(x=None, z=None):
  if x is None: return 0, matrix(0.2, (n,1))
  y = (1/sigma)*A*x
  f = -sum(log(matrix(stats.norm.cdf(y))))
  r = matrix(stats.norm.pdf(y)/stats.norm.cdf(y))
  gradf = -A.T * r
  if z is None: return f, gradf.T
  H = A.T * spdiag( (1.0/sigma) * z[0] * r**2 + mul(r,y)) * A
  return f, gradf.T, H
xlb = solvers.cp(myFunc, G = G, h = h)