本文整理汇总了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)