建模中的一些常见模型

更新时间:2024-05-12 20:43:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

①灰色模型

灰色模型:如果一个系统具有层次、结构关系的模糊性,动态变化的随机性,指标数据

的不完备或不确定性,则称这些特性为灰色性。具有灰色性的系统称为灰色系统。对灰色系统建立的预测模型称为灰色模型(Grey Model),简称GM模型,它揭示了系统内部事物连续发展变化的过程。

若一个系统的内部特征是完全已知的,即系统的信息是充足完全的,我们称之为白色系统。 若一个系统的内部信息是一无所知,一团漆黑,只能从它同外部的联系来观测研究,这种系统便是黑色系统。灰色系统介于二者之间,灰色系统的一部分信息是已知的,一部分是未知的。 区别白色和灰色系统的重要标志是系统各因素间是否有确定的关系。

灰色预测:灰色理论认为系统的行为现象尽管是朦胧的,数据是复杂的,但它毕竟是有序

的,是有整体功能的。灰数的生成,就是从杂乱中寻找出规律。同时,灰色理论建立的是生成数据模型,不是原始数据模型,因此,灰色预测是一种对含有不确定因素的系统进行预测的方法。灰色预测通过鉴别系统因素之间发展趋势的相异程度,即进行关联分析,并对原始数据进行生成处理来寻找系统变动的规律,生成有较强规律性的数据序列,然后建立相应的微分方程模型,从而预测事物未来发展趋势的状况。其用等时距观测到的反应预测对象特征的一系列数量值构造灰色预测模型,预测未来某一时刻的特征量,或达到某一特征量的时间。灰色系统分析方法是通过鉴别系统因素之间发展趋势的相似或相异程度,即进行关联度分析,并通过对原始数据的生成处理来寻求系统变动的规律。生成数据序列有较强的规律性,可以用它来建立相应的微分方程模型,从而预测事物未来的发展趋势和未来状态。

基本思想:是用原始数据组成原始序列(0),经累加生成法生成序列(1),它可以弱化原始数据的随机性,使其呈现出较为明显的特征规律。对生成变换后的序列(1) 建立微分方程型的模型即GM模型。GM(1,1) 模型表示1阶的、1个变量的微分方程模型。GM(1,1) 模型群中,新陈代谢模型是最理想的模型。这是因为任何一个灰色系统在发展过程中,随着时间的推移,将会不断地有一些随即扰动和驱动因素进入系统,使系统的发展相继地受其影响。用GM(1,1) 模型进行预测,精度较高的仅仅是原点数据(0)(n) 以后的1到2个数据,即预测时刻越远预测的意义越弱[3]。而新陈代谢GM(1,1)模型的基本思想为越接近的数据,对未来的影响越大。也就是说,在不断补充新信息的同时,去掉意义不大的老信息,这样的建模序列更能动态地反映系统最新的特征,这实际上是一种动态预测模型。

建模步骤:a、建模机理;

b、 把原始数据加工成生成数;

c、 对残差(模型计算值与实际值之差)修订后,建立差分微分方程模型; d、 基于关联度收敛的分析;

e、 gm模型所得数据须经过逆生成还原后才能用。

f、采用“五步建模(系统定性分析、因素分析、初步量化、动态量化、优化)”法,建立一种差分微分方程模型gm(1,1)预测模型。

GM(1,1)模型:

令 x(0)=(x⑴,x⑵,?,x(n)) 作一次累加生成, k

x(k)= ∑x(m) 消除数据的随机性和波动性 m=1

有 x=(x⑴,x⑵,?,x(n)) =(x⑴,x⑴+x⑵,?,x(n-1)+x(n)) x可建立白化方程:dx/dt+ax=u 即gm(1,1). 该方程的解为: x(k+1)=(x⑴-u/a)e+u/a

其中:α称为发展灰数;μ称为内生控制灰数

GM(n,h)模型:

1、残差模型:若用原始经济时间序列建立的GM(1,1)模型检验不合格或精度不理想时,要对建立的GM(1,1)模型进行残差修正或提高模型的预测精度。修正的方法是建立GM(1,1)的残差模型。

2、GM(n,h)模型 GM(n,h)模型是微分方程模型,可用于对描述对象作长期、连续、动态的反映。从原则上讲,某一灰色系统无论内部机制如何,只要能将该系统原始表征量表示为时间序列x(0)(t),并有 x(0)(t)>0,即可用GM模型对系统进行描述。

特点:对于一个模糊系统来说,传统的预测方法就会失去作用。处理模糊预测问题的数学方法

是模糊数学。模糊数学的基础是模糊集合论,而模糊集合是普通集合的扩展。美国学者l.a.zadeh教授建立的模糊集合论,为模糊预测理论与方法的研究奠定了理论基础。它用简捷有力的方法处理复杂系统,在某种程度上弥补了经典数学与统计数学的不足。

优点:1、不需要大量样本。

2、样本不需要有规律性分布。 3、计算工作量小。

4、定量分析结果与定性分析结果不会不一致。 5、可用于Recent、短期、中长期预测。 6、灰色预测准确度高。

②遗传算法

遗传算法是模拟达尔文的遗传选择和自然淘汰的生物进化过程的计算 模型。它的思想源于生物遗传学和适者生存的自然规律, 是具有“生存+检测”的迭代过程的搜索算法。遗传算法 以一种群体中的所有个体为对象,并利用随机化技术指 导对一个被编码的参数空间进行高效搜索。其中,选择、 交叉和变异构成了遗传算法的遗传操作;参数编码、初始 群体的设定、适应度函数的设计、遗传操作设计、控制参 数设定等5个要素组成了遗传算法的核心内容。

遗传算法的基本步骤:遗传算法是一种基于生物自然选择与遗传机理的随机 搜索算法,与传统搜索算法不同,遗传算法从一组随机产 生的称为“种群(Population)”的初始解开始搜索过程。种 群中的每个个体是问题的一个解,称为“染色体(chromos ome)”。染色体是一串符号,比如一个二进制字符串。这 些染色体在后续迭代中不断进化,称为遗传。在每一代中 用“适值(fitness)”来测量染色体的好坏,生成的下一代染 色体称为后代(offspring)。后代是由前一代染色体通过交 叉(crossover)或者变异(mutation)运算形成的。 在新一代形成过程中,根据适度的大小选择部分后代,淘 汰部分后代。从而保持种群大小是常数。适值高的染色体 被选中的概率较高,这样经过若干代之后,算法收敛于最 好的染色体,它很可能就是问题的最优解或次优解。

主要步骤如下所示:

(1)编码:GA在进行搜索之前先将解空间的解数据表示成 遗传空间的基因型串结构数据,这些串结构数据的不同组 合便构成了不同的点。

(2)初始群体的生成:随机产生N个初始串结构数据,每个 串结构数据称为一个个体,N个个体构成了—个群体。 GA以这N个串结构数据作为初始点开始迭代。 应届生求职季宝典 开启你的职场征途

简历撰写 笔试真题 面试攻略 专业技能指导 公务员专区 (3)适应性值评估检测:适应性函数表明个体或解的优劣性。 对于不同的问题,适应性函数的定义方式也不同。

(4)选择:选择的目的是为了从当前群体个选出优良的个体 ,使它们有机会作为父代为下一代繁殖子孙。遗传算法通 过选择过程体现这一思想,进行选择的原则是适应性强的 个体为下一代贡献一个或多个后代的概率大。选择实现了 达尔文的适者生存原则。 (5)交叉:交叉操作是遗传算法中最主要的遗传操作。通过 交叉操作可以得到新一代个体,新个体组合了其父辈个体 的特性。交叉体现了信息交换的思想。

(6)变异:变异首先在群体中随机选择一个个体,对于选中 的个体以一定的概率随机地改变串结构数据中某个串的值。 同生物界一样,GA中变异发生的概率很低,通常取值在 0.001~0.01之间。变异为新个体的产中提供了机会。 实际上,遗传算法中有两类运算:

● 遗传运算:交叉和变异 ● 进化运算:选择

GA的计算过程流程图:

遗传算法的特点 :GA是对问题参数的编码组进行计算,而不是针对参数本身。 GA的搜索是从问题解的编码组开始搜素、而不是从单个解开始。 GA使用目标函数值(适应度)这一信息进行搜索, 而不需导数等其他信息。 GA算法使用的选择、交叉、变异这三个算子都是随机操作,而不是确定规则。 举例图解说明计算流程:

遗传算法的MATLAB实现 需要如下主函数:

编码和种群生成 :

function [pop] = initializega(num,bounds,evalFN,evalOps,options) % pop - the initial, evaluated, random population

% num - the size of the population, i.e. the number to create % bounds - the number of permutations in an individual (e.g., number % of cities in a tsp

% evalFN - the evaluation fn, usually the name of the .m file for evaluation % evalOps- any options to be passed to the eval function defaults [ ] % options- options to the initialize function, ie. [eps, float/binary, prec] % where eps is the epsilon value and the second option is 1 for % orderOps, prec is the precision of the variables defaults [1e-6 1] 交叉

function [c1,c2] = arithXover(p1,p2,bounds,Ops)

% Arith crossover takes two parents P1,P2 and performs an interpolation % along the line formed by the two parents. %

% function [c1,c2] = arithXover(p1,p2,bounds,Ops)

% p1 - the first parent ( [solution string function value] ) % p2 - the second parent ( [solution string function value] ) % bounds - the bounds matrix for the solution space

% Ops - Options matrix for arith crossover [gen #ArithXovers] 选择

normGeomSelect:NormGeomSelect is a ranking selection function based on the normalized geometric distribution. (基于正态分布的序列选择函数) 变异

function[newPop] = normGeomSelect(oldPop,options)

% NormGeomSelect is a ranking selection function based on the normalized % geometric distribution. %

% function[newPop] = normGeomSelect(oldPop,options) % newPop - the new population selected from the oldPop % oldPop - the current population % options - options to normGeomSelect [gen probability_of_selecting_best]

一些辅助函数:

f2b :Return the binary representation of the float number fval(将浮点数转化为二进制数)

b2f:Return the float number corresponing to the binary representation of bval. (将二进制

数转化为 浮点数)

nonUnifMutation: Non uniform mutation changes one of the parameters of the parent based on a non-uniform probability distribution. This Gaussian distribution starts wide, and narrows to a point distribution as the current generation approaches the maximum generation. (基于非均一概率分布进行非均一变异)

maxGenTerm:Returns 1, i.e. terminates the GA when the maximal_generation is reached. (当迭代次数大于最大迭代次数时,终止遗传算法,返回 为1,否则返回为0。)

roulette:roulette is the traditional selection function with the probability of surviving equal to the fittness of i / sum of the fittness of all individuals

应用举例

1. 计算下列函数的最大值。

f(x)=x+10*sin(5x)+7cos(4x) , x∈[0,9] 方式1 >>gademo 方式2

step 1 编写目标函数gademo1eval1.m

function [sol, val] = gaDemo1Eval(sol,options) x=sol(1);

val = x + 10*sin(5*x)+7*cos(4*x); step 2 生成初始种群,大小为10

initPop=initializega(10,[0, 9],'gademo1eval1',[],[1e-6,1]); step 3 25次遗传迭代

[x,endPop,bpop,trace] = ga([0 9],'gademo1eval1',[],initPop,... [1e-6 1 1],'maxGenTerm',25,... 'normGeomSelect',[0.08],... ['arithXover'],[2],... 'nonUnifMutation',[2, 25 ,3]) % Output Arguments:

% x - the best solution found during the course of the run % endPop - the final population

% bPop - a trace of the best population (解的变化)

% traceInfo - a matrix of best and means of the ga for each generation (种群平均值的变化) %

% Input Arguments:

% bounds - a matrix of upper and lower bounds on the variables % evalFN - the name of the evaluation .m function

% evalOps - options to pass to the evaluation function ([NULL]) % startPop - a matrix of solutions that can be initialized % from initialize.m

% opts - [epsilon, prob_ops ,display] change required to consider two solutions different, prob_ops 0 if you want to apply the

% genetic operators probabilisticly to each solution, 1 if you are supplying a deterministic number of operator applications and display is 1 to output progress 0 for quiet. ([1e-6 1 0])

% termFN - name of the .m termination function

% termOps - options string to be passed to the termination function ([100]). % selectFN - name of the .m selection function (['normGeomSelect']) % selectOpts - options string to be passed to select after % select(pop,#,opts) ([0.08])

% xOverFNS - a string containing blank seperated names of Xover.m files (['arithXover heuristicXover simpleXover'])

% xOverOps - A matrix of options to pass to Xover.m files with the first column being the number of that xOver to perform similiarly for mutation ([2 0;2 3;2 0])

% mutFNs - a string containing blank seperated names of mutation.m files (['boundaryMutation multiNonUnifMutation ...

% nonUnifMutation unifMutation'])

% mutOps - A matrix of options to pass to Xover.m files with the first column being the number of that xOver to perform similiarly for mutation ([4 0 0;6 100 3;4 100 3;4 0 0])

2. 求sin(x) 在0到3.14之间的最大值.

function [sol, val] = sin1(sol,options) x=sol(1); val =sin(x);

initPop=initializega(10,[0, 3.14],'sin1',[],[1e-6,1]);

[x, endPop,bpop,trace] = ga([0 3.14],'sin1',[],initPop,... [1e-6 1 1],'maxGenTerm',25,... 'normGeomSelect',[0.08],... ['arithXover'],[2],... 'nonUnifMutation',[2, 25 ,3])

3 求解非线性规划问题

max f(x) s.t. gi(x)<=0,i=1,...,m hi(x)=0,i=m+1,...,n x∈Ω ?不可行的后代? 拒绝策略 修复策略 惩罚策略

e.g. min f(x)=(x1-2)2+(x2-1)2

s.t. g1(x)=x1-2x2+1>=0 g2(x)=x12/4-x22+1>=0 分析:取加法形式的适值函数: val(x)=f(x)+p(x)

惩罚函数 p(x)由两部分组成,可变乘法因子和 违反约束乘法,其表达式如下:

改进遗传算子策略

其中ri是约束i的可变惩罚系数。 步骤如下:

function [sol,eval]=f552(sol,options) x1=sol(1); x2=sol(2);

r1=0.1; r2=0.8; %约束条件 g1=x1-2*x2+1; g2=x1.^2/4-x2.^2+1; %加惩罚项的适值

if (g1>=0)&(g2>=0) eval=(x1-2).^2+(x2-1).^2; else eval=(x1-2).^2+(x2-1).^2+r1*g1+r2*g2; end eval=-eval;

%%%%%%%%%%%%%%%%%%%%%%%%%%% %维数n=2 %设置参数边界

bounds = ones(2,1)*[-1 1];%??????

%遗传算法优化 [p,endPop,bestSols,trace]=ga(bounds,'f552'); p %性能跟踪

plot(trace(:,1),trace(:,3),'b-') hold on

plot(trace(:,1),trace(:,2),'r-') xlabel('Generation'); ylabel('Fittness');

legend('解的变化','种群平均值的变化');

本文来源:https://www.bwwdw.com/article/zkug.html

Top