CVXPY是史丹福大學凸最佳化組發起的一個開源項目,以第三方Python包的形式開源在Github上。
基本介紹
- 中文名:CVXPY
- 外文名:CVXPY
- 創立者:史丹福大學凸最佳化組
CVXPY是史丹福大學凸最佳化組開發的一個Python軟體包。方便用戶以數學形式定義凸最佳化模型,而不受限於問題解決者(solvers)。例如以下代碼可求解最小二乘問題。
from cvxpy import *import numpy# Problem data.m = 30n = 20numpy.random.seed(1)A = numpy.random.randn(m, n)b = numpy.random.randn(m)# Construct the problem.x = Variable(n)objective = Minimize(sum_squares(A*x - b))constraints = [0 <= x, x <= 1]prob = Problem(objective, constraints)# The optimal objective is returned by prob.solve().result = prob.solve()# The optimal value for x is stored in x.value.print x.value# The optimal Lagrange multiplier for a constraint# is stored in constraint.dual_value.print constraints[0].dual_value