optim.py-使用tensorflow实现一般优化算法
optim.py
Project URL:https://github.com/Codsir/optim.git
Based on: tensorflow, numpy, copy, inspect
Why Tensorflow?
Tensorflow supports symbol computation well like Automatic derivation and the program
could be excuted with GPU, which will save our time.
dogleg(p_u, p_b, delta, tau = 2)
The Dogleg method to solve the subproblems of trust region method
getGrad(f, x_value)
Get the gradient of function f with tf.gradients()
f= lambda x:100*(x[1]-x[0]**2)**2 + (1-x[0])**2
x_value = [1.0,2.0]
f_gradients = getGrad(f, x_value)
getHess(f, x_value)
Get the Hessian matrix of f with tf.hessian
TrustRegion_dogleg(f, delta = 0.5, eta = 0, *x_0, tolerance= 0.0001)
Trust region method with subproblems solved by the Dogleg method
ExactLineSearch_quadratic(f, x_k, p_k)
Exact line search method when the target function is quadratic
QuasiNewton(f, *x_0, HUpdateMethod = 'BFGS', LineSearch = ExactLineSearch_quadratic, tolerance = 0.0001)
quasi-Newton method
PenaltySimple(f, c_eq, c_leq, epsilon)
f is the target function, c_eq is a list contains equation constraints,
c_leq is a list contains unequal constrains, epsilon is the terminal parameter
these functions could be function name or anonymous functions, which defined by 'lambda'
The subproblem is solved by Newton Method, but it will be modified in the future because sometimes it's hard to compute the inverse matrix of Hessian matrix.
Example
Demo 1:trust region method with subproblems solved by the Dogleg method
f = lambda x:100*(x[1]-x[0]**2)**2 + (1-x[0])**2
f.paraLength = 2 ## 这一步不可缺少
x_k, f_k = TrustRegion_dogleg(f, delta = 10)
Demo 2:quasi-Newton method demo
print('Demo 2:quasi-Newton method demo')
f = lambda x:x[0]**2 + 2 * x[1]**2
f.paraLength = 2
x_0 = np.array([1, 1])
x_k, f_k = QuasiNewton(f, x_0)
Demo 3:penalty function method demo
print('Demo 3:penalty function method demo')
f = lambda x:x[0] + x[1]
f.paraLength = 2
c_eq = [lambda x:x[0]**2 + x[1]**2 - 2]
c_leq = []
x_k, f_k = PenaltySimple(f, c_eq, c_leq, [-3,-4])
optim.py-使用tensorflow实现一般优化算法的更多相关文章
- TensorFlow中的优化算法
搭建好网络后,常使用梯度下降类优化算法进行模型参数求解,模型越复杂我们在训练神经网络的过程上花的时间就越多,为了解决这一问题,我们就需要找一些优化算法来提高训练速度,TF的tf.train模块中提供了 ...
- torch.optim优化算法理解之optim.Adam()
torch.optim是一个实现了多种优化算法的包,大多数通用的方法都已支持,提供了丰富的接口调用,未来更多精炼的优化算法也将整合进来. 为了使用torch.optim,需先构造一个优化器对象Opti ...
- TensorFlow实现与优化深度神经网络
TensorFlow实现与优化深度神经网络 转载请注明作者:梦里风林Github工程地址:https://github.com/ahangchen/GDLnotes欢迎star,有问题可以到Issue ...
- PyTorch-Adam优化算法原理,公式,应用
概念:Adam 是一种可以替代传统随机梯度下降过程的一阶优化算法,它能基于训练数据迭代地更新神经网络权重.Adam 最开始是由 OpenAI 的 Diederik Kingma 和多伦多大学的 Jim ...
- Tensorflow 中的优化器解析
Tensorflow:1.6.0 优化器(reference:https://blog.csdn.net/weixin_40170902/article/details/80092628) I: t ...
- Adam优化算法
Question? Adam 算法是什么,它为优化深度学习模型带来了哪些优势? Adam 算法的原理机制是怎么样的,它与相关的 AdaGrad 和 RMSProp 方法有什么区别. Adam 算法应该 ...
- 优化算法——拟牛顿法之L-BFGS算法
一.BFGS算法 在"优化算法--拟牛顿法之BFGS算法"中,我们得到了BFGS算法的校正公式: 利用Sherman-Morrison公式可对上式进行变换,得到 令,则得到: 二. ...
- 《深度学习-改善深层神经网络》-第二周-优化算法-Andrew Ng
目录 1. Mini-batch gradient descent 1.1 算法原理 1.2 进一步理解Mini-batch gradient descent 1.3 TensorFlow中的梯度下降 ...
- 【优化算法】Greedy Randomized Adaptive Search算法 超详细解析,附代码实现TSP问题求解
01 概述 Greedy Randomized Adaptive Search,贪婪随机自适应搜索(GRAS),是组合优化问题中的多起点元启发式算法,在算法的每次迭代中,主要由两个阶段组成:构造(co ...
随机推荐
- CE未知数值修改
一样,用植物大战僵尸测试.来搜索修改向日葵生产阳光的CD值. 由于开始并不知道向日葵cd的初始值,所以用CE搜索未知的初始值 返回游戏,每次向日葵晃一下搜索一下减少的值. 锁定修改为0发现成功. 然后 ...
- Java实现 LeetCode 724 寻找数组的中心索引(暴力)
724. 寻找数组的中心索引 给定一个整数类型的数组 nums,请编写一个能够返回数组"中心索引"的方法. 我们是这样定义数组中心索引的:数组中心索引的左侧所有元素相加的和等于右侧 ...
- Java实现 LeetCode 316 去除重复字母
316. 去除重复字母 给定一个仅包含小写字母的字符串,去除字符串中重复的字母,使得每个字母只出现一次.需保证返回结果的字典序最小(要求不能打乱其他字符的相对位置). 示例 1: 输入: " ...
- Java实现 洛谷 P1200 [USACO1.1]你的飞碟在这儿Your Ride Is He…
import java.util.Scanner; public class Main{ private static Scanner cin; public static void main(Str ...
- SSH原理常见应用升级及端口转发
SSH介绍 SSH是Secure Shell Protocol的简写,由IETF网络工作小组(Network working Group)指定:在进行数据传输之前,SSH先对联机数据包通过加密技术进行 ...
- Windows安装多个python解释器
Windows安装多个python解释器 在windows10系统下安装两个不同版本的的python解释器,在通常情况下编译执行文件都是没问题的,但是加载或下载包的时候pip的使用就会出现问题,无 ...
- 解决Zabbix 5.0不能选择中文和中文乱码问题
Zabbix web界面不能选择中文,提示: You are not able to choose some of the languages, because locales for them ar ...
- Py中去除列表中小于某个数的值
### Py去除列表中小于某个数的值 print('*'*10,'Py去除列表中小于某个数的值','*'*10) nums = [2,3,4,10,9,11,19,14] print('*'*10,' ...
- 操作-写入excel
xlwt模块 封装 #!/usr/bin/env python # -*- coding: utf-8 -*- import xlwt import xlrd from xlutils.copy im ...
- linux配置SVN服务
在linux下配置SVN库,网上找到不少教程,但是对于有几个容易混淆的地方需要记录下, 1.在创建SVN文档库的时候,需要使用svn命令先创建出来, svnadmin create /home/svn ...