diff --git "a/MachineLearningMathBasic/2.8 Moore-Penrose\344\274\252\351\200\206-\346\235\216\346\266\233.md" "b/MachineLearningMathBasic/2.8 Moore-Penrose\344\274\252\351\200\206-\346\235\216\346\266\233.md" index 36059919..d386571d 100644 --- "a/MachineLearningMathBasic/2.8 Moore-Penrose\344\274\252\351\200\206-\346\235\216\346\266\233.md" +++ "b/MachineLearningMathBasic/2.8 Moore-Penrose\344\274\252\351\200\206-\346\235\216\346\266\233.md" @@ -1,8 +1,7 @@ # 2.8 Moore-Penrose伪逆-李涛 -![-w797](media/15669588348534/15669601763364.jpg) -![-w803](media/15669588348534/15669602014898.jpg) - +![](https://tva1.sinaimg.cn/large/006y8mN6ly1g6fjbz5i93j318a0qiag2.jpg) +![](https://tva1.sinaimg.cn/large/006y8mN6ly1g6fjdlbpduj318m0iun0r.jpg) ```python import scipy as SP diff --git "a/MachineLearningMathBasic/6.3 \345\207\270\351\233\206\344\270\216\345\207\270\351\233\206\345\210\206\347\246\273\345\256\232\345\276\213-\346\235\216\346\266\233.md" "b/MachineLearningMathBasic/6.3 \345\207\270\351\233\206\344\270\216\345\207\270\351\233\206\345\210\206\347\246\273\345\256\232\345\276\213-\346\235\216\346\266\233.md" new file mode 100644 index 00000000..151a7866 --- /dev/null +++ "b/MachineLearningMathBasic/6.3 \345\207\270\351\233\206\344\270\216\345\207\270\351\233\206\345\210\206\347\246\273\345\256\232\345\276\213-\346\235\216\346\266\233.md" @@ -0,0 +1,45 @@ +# 6.3 凸集与凸集分离定律-李涛 +![](https://tva1.sinaimg.cn/large/006y8mN6ly1g6fjg1lhx6j30r20rk421.jpg) +![](https://tva1.sinaimg.cn/large/006y8mN6ly1g6fjg1f5udj30pe13sdje.jpg) +![](https://tva1.sinaimg.cn/large/006y8mN6ly1g6fjg19xnxj30p604o0u7.jpg) +``` +from cvxpy import * +import cvxpy as cvx + +``` +``` +problem : +minimize (x-y)^2 +subject to + x+y=1 + x-y>=1 +``` +``` +from cvxpy import * +# Create two scalar optimization variables. +# 在CVXPY中变量有标量(只有数值大小),向量,矩阵。 +# 在CVXPY中有常量(见下文的Parameter) +x = Variable() #定义变量x,定义变量y。两个都是标量 +y = Variable() +# Create two constraints. +#定义两个约束式 +constraints = [x + y == 1, + x - y >= 1] +#优化的目标函数 +obj = Minimize(square(x - y)) +#把目标函数与约束传进Problem函数中 +prob = Problem(obj, constraints) +prob.solve() # Returns the optimal value. +print("status:", prob.status) +print("optimal value", prob.value) #最优值 +print("optimal var", x.value, y.value) #x与y的解 +# Replace the objective. 不同的目标函数,相同的约束 +prob2 = cvx.Problem(cvx.Maximize(x + y), prob.constraints) +print("optimal p1 value", prob2.solve()) + +# Replace the constraint (x + y == 1).#不同的约束,相同的目标函数 +constraints = [x + y <= 3] + prob.constraints[1:] #注意:此处是列表相加,prob.constraints[1:]取prob的约束集中 +#从第二个开始的所有约束。 +prob2 = cvx.Problem(prob.objective, constraints) +print("optimal P2 value", prob2.solve()) +``` \ No newline at end of file