一维最优化:二次插值法(Quadratic interpolation method)

理论见参考《Practical Optimization》中4.5节,代码实现如下:(

可以将黄金分割法和二次插值法结合起来,想用黄金分割法快速搜索得到最优解,然后用该最优解作为二次插值的初值,可以提高计算精度。Matlab中就是采用此组合策略。

OneDimensionalOptimization.h
#ifndef _OneDimensionalOptimization_
#define _OneDimensionalOptimization_
#include <algorithm>
using namespace std;

class OneDimensionalOptimization
{
public:
	//参考《Practical Optimization》中4.5节
	double quadraticInterpolationSearch(double(*p)(double x),double& l, double& u, double& x, double tol = 1e-6);
};
#endif
OneDimensionalOptimization.cpp
double OneDimensionalOptimization::quadraticInterpolationSearch(double(*p)(double x),double& l, double& u, double& x, double tol)
{
	int mm = 0;
	//1)
	double x1 = l;
	double x3 = u;
	double x0_aver = 1e99;

	//2)
	double x2 = 0.5 * (x1 + x3);
	double f1 = p(x1);
	double f2 = p(x2);
	double f3 = p(x3);

	//3)
	while(true)
	{
		mm++;
		double x_aver = ((x2*x2 - x3*x3)*f1 + (x3*x3 - x1*x1)*f2 + (x1*x1 - x2*x2)*f3 )/(2*((x2 - x3)*f1 + (x3 - x1)*f2 + (x1 - x2)*f3));
		double f_aver = p(x_aver);
		if(abs(x_aver - x0_aver) < tol)
		{
			x = x_aver;
			return f_aver;
		}
		//4)
		if(x1 < x_aver && x_aver < x2)
		{
			if(f_aver <= f2)
			{
				x3 = x2;
				f3 = f2;
				x2 = x_aver;
				f2 = f_aver;
			}
			else
			{
				x1 = x_aver;
				f1 = f_aver;
			}
		}
		else if(x2 < x_aver && x_aver < x3)
		{
			if(f_aver <= f2)
			{
				x1 = x2;
				f1 = f2;
				x2 = x_aver;
				f2 = f_aver;
			}
			else
			{
				x3 = x_aver;
				f3 = f_aver;
			}
		}
		x0_aver = x_aver;
	}
}


测试代码如下:

main.cpp
#include "src\Optimizer\OneDimensionalOptimization.h"

#include <fstream>
using namespace std;

double p(double x)
{
	return -sin(x);
}
int main(int argv, char** argc)
{
	OneDimensionalOptimization* one = new OneDimensionalOptimization();
	double l = 0;
	double u = 2*3.1415926;
	double x;
	double res1 = one->quadraticInterpolationSearch(p,l,u,x,1e-10);
	return 1;
}
 

 



matlab最优化程序包括:无约束一维极值问题、进退法、黄金分割法、斐波那契法、牛顿法基本牛顿法、全局牛顿法、割线法、抛物线法、三次插值法、可接受搜索法、Goidstein法、Wolfe Powell法、单纯形搜索法、Powell法、最速下降法、共轭梯度法、牛顿法、修正牛顿法、拟牛顿法、信赖域法、显式最速下降法、Rosen梯度投影法、罚函数法、外点罚函数法、內点罚函数法、混合罚函数法、乘子法、G-N法、修正G-N法、L-M法、线性规划、单纯形法、修正单纯形法、大M法、变量有界单纯形法、整数规划、割平面法、分支定界法、0-1规划、二次规划、拉格朗曰法、起作用集算法、路径跟踪法、粒子群优化算法、基本粒子群算法、带压缩因子的粒子群算法、权重改进的粒子群算法、线性递减权重法、自适应权重法、随机权重法、变学习因子的粒子群算法、同步变化的学习因子、异步变化的学习因子、二阶粒子群算法、二阶振荡粒子群算法 (matlab optimization process includes Non-binding one-dimensional extremum problems Advance and retreat method Golden Section Fibonacci method of basic Newton s method Newton s method Newton s Law of the global secant method parabola method acceptable to the three interpolation search method Goidstein France Wolfe.Powell France Simplex search method Powell steepest descent method Conjugate gradient method Newton s method Newton s method to amend Quasi-Newton Method trust region method explicitly steepest descent method, Rosen gradient projection method Penalty function method outside the penalty function method within the penalty function method Mixed penalty function multiplier method G-N was amended in G-N method L-M method Of linear programming simplex method, revised simplex method Big M method variables bounded simplex method, Cutting Plane Method integer programming branch and bound method 0-1 programming quadratic programming )
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值