本文整理匯總了Python中cvxpy.pos方法的典型用法代碼示例。如果您正苦於以下問題:Python cvxpy.pos方法的具體用法?Python cvxpy.pos怎麽用?Python cvxpy.pos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cvxpy
的用法示例。
在下文中一共展示了cvxpy.pos方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_constr_error
# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import pos [as 別名]
def get_constr_error(constr):
if isinstance(constr, cvx.constraints.Equality):
error = cvx.abs(constr.args[0] - constr.args[1])
elif isinstance(constr, cvx.constraints.Inequality):
error = cvx.pos(constr.args[0] - constr.args[1])
elif isinstance(constr, cvx.constraints.PSD):
mat = constr.args[0] - constr.args[1]
error = cvx.neg(cvx.lambda_min(mat + mat.T)/2)
return cvx.sum(error)
示例2: newsvendor_opt
# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import pos [as 別名]
def newsvendor_opt(params, py):
z = cp.Variable(1)
d = params['d']
f = (params['c_lin'] * z + 0.5 * params['c_quad'] * cp.square(z) +
py.T * (params['b_lin'] * cp.pos(d-z) +
0.5 * params['b_quad'] * cp.square(cp.pos(d-z)) +
params['h_lin'] * cp.pos(z-d) +
0.5 * params['h_quad'] * cp.square(cp.pos(z-d)) ))
fval = cp.Problem(cp.Minimize(f), [z >= 0]).solve()
return z.value, fval
# Inventory ordering cost given demand realization
示例3: __str__
# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import pos [as 別名]
def __str__(self): return "huber loss"
# class FractionalLoss(Loss):
# PRECISION = 1e-10
# def loss(self, A, U):
# B = cp.Constant(A)
# U = cp.max_elemwise(U, self.PRECISION) # to avoid dividing by zero
# return cp.max_elemwise(cp.mul_elemwise(cp.inv_pos(cp.pos(U)), B-U), \
# return maximum((A - U)/U, (U - A)/A)
#
示例4: loss
# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import pos [as 別名]
def loss(self, A, U): return cp.sum_entries(cp.pos(ones(A.shape)-cp.mul_elemwise(cp.Constant(A), U)))
示例5: cost
# 需要導入模塊: import cvxpy [as 別名]
# 或者: from cvxpy import pos [as 別名]
def cost(self):
return np.matrix(self.alpha) * cvx.pos(self.power - self.terminals[0].power_var)