栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

凸优化Python实战(2)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

凸优化Python实战(2)

1.原理推导 1.1最速下降法的基本原理

1.2最速下降法的算法步骤

1.3最速下降法的最优步长



2.计算案例:



3.总结

4.代码实现

代码可以在 https://github.com/HarmoniaLeo/optimization-in-a-nutshell找到,如果帮助到你,请点个star,谢谢这对博主真的很重要!
本次引用Function.py和lagb.py也可以在最优化(1)_ 最优化问题概念与基本知识 找到

import numpy as np
from Function import Function   #定义法求导工具
from lagb import *  #线性代数工具库

n=2 #x的长度

def myFunc(x):  #x是一个包含所有参数的列表
    return x[0]**2 + 2*x[1]**2 + 2*x[0] - 6*x[1] +1 #目标方程

x=np.zeros(n)   #初值点
rho=0.6
beta=1
sigma=0.4
e=0.001
k=0
tar=Function(myFunc)
while tar.norm(x)>e:
    d=-tar.grad(x)
    a=1
    if not (tar.value(x+a*d)<=tar.value(x)+rho*a*dot(turn(tar.grad(x)),d) and dot(turn(tar.grad(x+a*d)),d)>=sigma*dot(turn(tar.grad(x)),d)):
        a=beta
        while tar.value(x+a*d)>tar.value(x)+rho*a*dot(turn(tar.grad(x)),d):
            a*=rho
        while dot(turn(tar.grad(x+a*d)),d)tar.value(x)+rho*(a+da)*dot(turn(tar.grad(x)),d):
                da*=rho
            a+=da
    x+=a*d
    k+=1
    print(k)
print(x)

引用参考:

深入浅出最优化(3) 最速下降法与牛顿法:https://www.jianshu.com/p/c1f40133e04a
最速下降法(上):https://www.bilibili.com/video/BV1RK4y1a75C?spm_id_from=333.999.0.0
最速下降法(下):https://www.bilibili.com/video/BV1ey4y1k7jY?spm_id_from=333.999.0.0

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/878782.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号