当前位置:首页 » 操作系统 » imm算法

imm算法

发布时间: 2022-05-13 14:34:26

⑴ 求IMM算法的matlab仿真代码

function imm_extend2() %交互式多模型 初步改进
clear all;
close all;
timenum=75;
t=1;
transfer_matric=[0.98 0.02; %马尔科夫转移矩阵 矩阵为j行i列
0.02 0.98];
u_10=0.5; %目标1在模型i在k-1时刻的概率
u_20=0.5; %目标1在模型i在k-1时刻的概率
u=[u_10 u_20];
Q1=100; %目标1的状态噪声协方差阵
Q2=4000; %目标1的状态噪声协方差阵
R=10000; %观测噪声协方差阵
%R2=700;
x00_1=[0 0 0]'; %模型1估计的初始值
x00_2=[0 0 0]'; %模型2估计的初始值
p00_1=[100 0 0;
0 10 0;
0 0 0];
p00_2=[100 0 0;
0 10 0;
0 0 10];
dis=1000; %位移
vel=450; %速度
acc=50; %加速度
xx01=[dis vel 0]'; %状态的初始值
xx02=[dis vel acc]'; %状态的初始值
%xx2=0;
f1=[1 t 0;
0 1 0;
0 0 0]; %状态转移阵
f2=[1 t 0.5*t^2;
0 1 t;
0 0 1];
l1=[0.5*t^2 t 0]'; %状态干扰阵
l2=[0.5*t^2 t 1]';
h=[1 0 0]; %观测转移阵
I=[1 0 0;
0 1 0;
0 0 1];
num=1;
XX1=zeros(3,25);
XX2=XX1;
XX3=XX1;
while num<=timenum
if num<=25
xx1=f1*xx01+l1*sqrt(Q1); %目标的状态值
XX1(:,num)=xx1;
z(num)=h*xx1+sqrt(R)*randn(1); %目标的观测值
else
if 25<num<=50
xx2=f2*xx02+l2*sqrt(Q2); %目标的状态值
XX2(:,num-25)=xx2;
z(num)=h*xx2+sqrt(R)*randn(1); %目标的观测值
else
if 50<num<=timenum
xx3=f1*xx01+l1*sqrt(Q1); %目标的状态值
XX3(:,num-50)=xx3;
z(num)=h*xx3+sqrt(R)*randn(1); %目标的观测值
end;
end;
end;

%================input alternation==============================
tran_11=transfer_matric(1,1)*u(1);
tran_12=transfer_matric(1,2)*u(1);
tran_21=transfer_matric(2,1)*u(2);
tran_22=transfer_matric(2,2)*u(2);
sum_tran_j1=tran_11+tran_21;
sum_tran_j2=tran_12+tran_22;
sum_tran_j=[sum_tran_j1 sum_tran_j2];
u_mix(1,1)=tran_11/sum_tran_j1;
u_mix(1,2)=tran_12/sum_tran_j2;
u_mix(2,1)=tran_21/sum_tran_j1;
u_mix(2,2)=tran_22/sum_tran_j2;
% for i=1:2
% x00_estimate_j(i)=sum_tran_j(i)*x00(i);
% p00_estimate_j(i)=sum_tran_j(i)*(p00+(x00-x00_estimate_j(i))*(x00-x00_estimate_j(i))');%p00_estimate以行存储
%end;
x00_estimate_j(:,1)=x00_1*u_mix(1,1)+x00_2*u_mix(2,1);
x00_estimate_j(:,2)=x00_1*u_mix(1,2)+x00_2*u_mix(2,2);
p00_estimate_j1=(p00_1+(x00_1-x00_estimate_j(:,1))*(x00_1-x00_estimate_j(:,1))')*u_mix(1,1)+...
(p00_2+(x00_2-x00_estimate_j(:,1))*(x00_2-x00_estimate_j(:,1))')*u_mix(2,1);
p00_estimate_j2=(p00_1+(x00_1-x00_estimate_j(:,2))*(x00_1-x00_estimate_j(:,2))')*u_mix(1,2)+...
(p00_2+(x00_2-x00_estimate_j(:,2))*(x00_2-x00_estimate_j(:,2))')*u_mix(2,2);
%==================filter calculate=================================
%================model 1===================================
x1_pre=f1*x00_estimate_j(:,1);
p1_pre=f1*p00_estimate_j1*f1'+l1*Q1*l1';
s1=h*p1_pre*h'+R;
k_gain1=p1_pre*h'*inv(s1);
p1_estimate=(I-k_gain1*h)*p1_pre;
v1=z(num)-h*x1_pre;
x1_estimate=x1_pre+k_gain1*v1;
X1_estimate(:,num)=x1_estimate;
%================model 2===================================
x2_pre=f2*x00_estimate_j(:,2);
p2_pre=f2*p00_estimate_j2*f2'+l2*Q2*l2';
s2=h*p2_pre*h'+R;
k_gain2=p2_pre*h'*inv(s2);
p2_estimate=(I-k_gain2*h)*p2_pre;
v2=z(num)-h*x2_pre;
x2_estimate=x2_pre+k_gain2*v2;
X2_estimate(:,num)=x2_estimate;
%===============================================================
%===================model probability alternate=================
p_pre=[p1_pre;p2_pre];
x_pre=[x1_pre' x2_pre'];
s=[s1(1) s2(1)];
v=[v1 v2];
for i=1:2
model_fun(i)=(1/sqrt(2*pi*s(i)))*exp(-v(i)*v(i)'/(2*abs(s(i))));
end;
sum_tran=model_fun(1)*sum_tran_j1+model_fun(2)*sum_tran_j2;
u_j1=model_fun(1)*sum_tran_j1/sum_tran;
u_j2=model_fun(2)*sum_tran_j2/sum_tran;
u_j=[u_j1 u_j2];
%==============================================================
%====================output alternation=========================
x_sum=x1_estimate*u_j(1)+x2_estimate*u_j(2)

X_sum(:,num)=x_sum;
p_sum=(p1_estimate+(x_sum-x1_estimate)*(x_sum-x1_estimate)')*u_j1+(p2_estimate+(x_sum-x2_estimate)*(x_sum-x2_estimate)')*u_j2;
P_sum(3*num-2:3*num,1:3)=p_sum;
%x00=x_sum(k);
%x00=[x1_estimate(k) x2_estimate(k)];
x00_1=x1_estimate;
x00_2=x2_estimate;
%p00=[p1_estimate(k) p2_estimate(k)];
p00_1=p1_estimate;
p00_2=p2_estimate;

if (num<=25|25<num<=75)
xx01=xx1;
else if 25<num<=50
xx02=xx2;
%else
% xx01=xx3;
end;
end;

%xx2=xx_2(k);
u=[u_j1 u_j2];
num=num+1;
end;
XX=[XX1 XX2 XX3];
figure;
plot(XX(1,:)','b');
hold on;
plot(X_sum(1,:),'m')
legend('状态','融合输出的估计');
plot(z,'r')

xlabel('采样次数');
ylabel('相应值');
grid;
hold off;
%figure;
%plot(p1_estimate,'b');
%hold on;
%plot(p2_estimate,'m');
%plot(p_sum,'r');
%hold off;
%legend('模型1的协方差','模型2的协方差','融合输出的协方差');
%xlabel('采样次数');
%ylabel('相应值');
%grid;

figure;
plot(XX(2,:)','b');
hold on;
plot(X_sum(2,:)','r');
legend('状态','融合输出的估计');
xlabel('采样次数');
ylabel('相应值');
grid;
hold off;

figure;
plot(XX(3,:),'b');
hold on;
plot(X_sum(3,:)','r');
legend('状态','融合输出的估计');
xlabel('采样次数');
ylabel('相应值');
grid;
hold off;
X_sum
XX

⑵ 求IMM算法的matlab仿真代码

function
imm_extend2()
%交互式多模型
初步改进
clear
all;
close
all;
timenum=75;
t=1;
transfer_matric=[0.98
0.02;
%马尔科夫转移矩阵
矩阵为j行i列
0.02
0.98];
u_10=0.5;
%目标1在模型i在k-1时刻的概率
u_20=0.5;
%目标1在模型i在k-1时刻的概率
u=[u_10
u_20];
Q1=100;
%目标1的状态噪声协方差阵
Q2=4000;
%目标1的状态噪声协方差阵
R=10000;
%观测噪声协方差阵
%R2=700;
x00_1=[0
0
0]';
%模型1估计的初始值
x00_2=[0
0
0]';
%模型2估计的初始值
p00_1=[100
0
0;
0
10
0;
0
0
0];
p00_2=[100
0
0;
0
10
0;
0
0
10];
dis=1000;
%位移
vel=450;
%速度
acc=50;
%加速度
xx01=[dis
vel
0]';
%状态的初始值
xx02=[dis
vel
acc]';
%状态的初始值
%xx2=0;
f1=[1
t
0;
0
1
0;
0
0
0];
%状态转移阵
f2=[1
t
0.5*t^2;
0
1
t;
0
0
1];
l1=[0.5*t^2
t
0]';
%状态干扰阵
l2=[0.5*t^2
t
1]';
h=[1
0
0];
%观测转移阵
I=[1
0
0;
0
1
0;
0
0
1];
num=1;
XX1=zeros(3,25);
XX2=XX1;
XX3=XX1;
while
num<=timenum
if
num<=25
xx1=f1*xx01+l1*sqrt(Q1);
%目标的状态值
XX1(:,num)=xx1;
z(num)=h*xx1+sqrt(R)*randn(1);
%目标的观测值
else
if
25<num<=50
xx2=f2*xx02+l2*sqrt(Q2);
%目标的状态值
XX2(:,num-25)=xx2;
z(num)=h*xx2+sqrt(R)*randn(1);
%目标的观测值
else
if
50<num<=timenum
xx3=f1*xx01+l1*sqrt(Q1);
%目标的状态值
XX3(:,num-50)=xx3;
z(num)=h*xx3+sqrt(R)*randn(1);
%目标的观测值
end;
end;
end;
%================input
alternation==============================
tran_11=transfer_matric(1,1)*u(1);
tran_12=transfer_matric(1,2)*u(1);
tran_21=transfer_matric(2,1)*u(2);
tran_22=transfer_matric(2,2)*u(2);
sum_tran_j1=tran_11+tran_21;
sum_tran_j2=tran_12+tran_22;
sum_tran_j=[sum_tran_j1
sum_tran_j2];
u_mix(1,1)=tran_11/sum_tran_j1;
u_mix(1,2)=tran_12/sum_tran_j2;
u_mix(2,1)=tran_21/sum_tran_j1;
u_mix(2,2)=tran_22/sum_tran_j2;
%
for
i=1:2
%
x00_estimate_j(i)=sum_tran_j(i)*x00(i);
%
p00_estimate_j(i)=sum_tran_j(i)*(p00+(x00-x00_estimate_j(i))*(x00-x00_estimate_j(i))');%p00_estimate以行存储
%end;
x00_estimate_j(:,1)=x00_1*u_mix(1,1)+x00_2*u_mix(2,1);
x00_estimate_j(:,2)=x00_1*u_mix(1,2)+x00_2*u_mix(2,2);
p00_estimate_j1=(p00_1+(x00_1-x00_estimate_j(:,1))*(x00_1-x00_estimate_j(:,1))')*u_mix(1,1)+...
(p00_2+(x00_2-x00_estimate_j(:,1))*(x00_2-x00_estimate_j(:,1))')*u_mix(2,1);
p00_estimate_j2=(p00_1+(x00_1-x00_estimate_j(:,2))*(x00_1-x00_estimate_j(:,2))')*u_mix(1,2)+...
(p00_2+(x00_2-x00_estimate_j(:,2))*(x00_2-x00_estimate_j(:,2))')*u_mix(2,2);
%==================filter
calculate=================================
%================model
1===================================
x1_pre=f1*x00_estimate_j(:,1);
p1_pre=f1*p00_estimate_j1*f1'+l1*Q1*l1';
s1=h*p1_pre*h'+R;
k_gain1=p1_pre*h'*inv(s1);
p1_estimate=(I-k_gain1*h)*p1_pre;
v1=z(num)-h*x1_pre;
x1_estimate=x1_pre+k_gain1*v1;
X1_estimate(:,num)=x1_estimate;
%================model
2===================================
x2_pre=f2*x00_estimate_j(:,2);
p2_pre=f2*p00_estimate_j2*f2'+l2*Q2*l2';
s2=h*p2_pre*h'+R;
k_gain2=p2_pre*h'*inv(s2);
p2_estimate=(I-k_gain2*h)*p2_pre;
v2=z(num)-h*x2_pre;
x2_estimate=x2_pre+k_gain2*v2;
X2_estimate(:,num)=x2_estimate;
%===============================================================
%===================model
probability
alternate=================
p_pre=[p1_pre;p2_pre];
x_pre=[x1_pre'
x2_pre'];
s=[s1(1)
s2(1)];
v=[v1
v2];
for
i=1:2
model_fun(i)=(1/sqrt(2*pi*s(i)))*exp(-v(i)*v(i)'/(2*abs(s(i))));
end;
sum_tran=model_fun(1)*sum_tran_j1+model_fun(2)*sum_tran_j2;
u_j1=model_fun(1)*sum_tran_j1/sum_tran;
u_j2=model_fun(2)*sum_tran_j2/sum_tran;
u_j=[u_j1
u_j2];
%==============================================================
%====================output
alternation=========================
x_sum=x1_estimate*u_j(1)+x2_estimate*u_j(2)
X_sum(:,num)=x_sum;
p_sum=(p1_estimate+(x_sum-x1_estimate)*(x_sum-x1_estimate)')*u_j1+(p2_estimate+(x_sum-x2_estimate)*(x_sum-x2_estimate)')*u_j2;
P_sum(3*num-2:3*num,1:3)=p_sum;
%x00=x_sum(k);
%x00=[x1_estimate(k)
x2_estimate(k)];
x00_1=x1_estimate;
x00_2=x2_estimate;
%p00=[p1_estimate(k)
p2_estimate(k)];
p00_1=p1_estimate;
p00_2=p2_estimate;
if
(num<=25|25<num<=75)
xx01=xx1;
else
if
25<num<=50
xx02=xx2;
%else
%
xx01=xx3;
end;
end;
%xx2=xx_2(k);
u=[u_j1
u_j2];
num=num+1;
end;
XX=[XX1
XX2
XX3];
figure;
plot(XX(1,:)','b');
hold
on;
plot(X_sum(1,:),'m')
legend('状态','融合输出的估计');
plot(z,'r')
xlabel('采样次数');
ylabel('相应值');
grid;
hold
off;
%figure;
%plot(p1_estimate,'b');
%hold
on;
%plot(p2_estimate,'m');
%plot(p_sum,'r');
%hold
off;
%legend('模型1的协方差','模型2的协方差','融合输出的协方差');
%xlabel('采样次数');
%ylabel('相应值');
%grid;
figure;
plot(XX(2,:)','b');
hold
on;
plot(X_sum(2,:)','r');
legend('状态','融合输出的估计');
xlabel('采样次数');
ylabel('相应值');
grid;
hold
off;
figure;
plot(XX(3,:),'b');
hold
on;
plot(X_sum(3,:)','r');
legend('状态','融合输出的估计');
xlabel('采样次数');
ylabel('相应值');
grid;
hold
off;
X_sum
XX

⑶ 遗传算法中如何实现长度可变的编码

看来也没人回答了,把积分送给我吧!

附送模拟退火遗传算法的源程序

遗传算法求解f(x)=xcosx+2的最大值

其中在尺度变换部分应用到了类似模拟退火算法部分,所有变量均使用汉语拼音很好懂

//中国电子科技集团公司

//第一研究室

//呼文韬

//[email protected]

//随机初始种群
//编码方式为格雷码
//选择方法为随机遍历
//采用了精英保存策略
//采用了自适应的交叉率和变异率
//采用了与模拟退火算法相结合的尺度变换
//采用了均匀交叉法

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <iostream.h>
#include <iomanip.h>
#include <time.h>
#include <windows.h>
#define IM1 2147483563
#define IM2 2147483399
#define AM (1.0/IM1)
#define IMM1 (IM1-1)
#define IA1 40014
#define IA2 40692
#define IQ1 53668
#define IQ2 52774
#define IR1 12211
#define IR2 3791
#define NTAB 32
#define NDIV (1+IMM1/NTAB)
#define EPS 1.2e-7
#define RNMX (1.0-EPS)
#define zhenjuli 0.005
#define PI 3.14159265358
#define T0 100000//温度要取得很高才行。
#define zhongqunshu1 200
#define zuobianjie -2000
#define youbianjie 2000
unsigned int seed=0; //seed 为种子,要设为全局变量
void mysrand(long int i) //初始化种子
{
seed = -i;
}
long a[1];
//double hunn;
//double c=4;
//设置全局变量
struct indivial
{
unsigned *chrom; //染色体;
double geti;//变量值
double shiying; //目标函数的值;
double fitness; //变换后的适应度值;
};
indivial *zuiyougeti;//精英保存策略
int zhongqunshu; //种群大小
indivial *nowpop;//当前代
indivial *newpop;//新一代
double sumfitness;//当代的总适应度fitness
double sumshiying;//当代的总适应度shiying
double maxfitness;//最大适应度
double avefitness;//平均适应度
double maxshiying;//最大适应度
double avgshiying;//平均适应度
float pc;//交叉概率
float pm;//变异概率
int lchrom;//染色体长度
int maxgen;//最大遗传代数
int gen;//遗传代数
//函数
int flipc(double ,double );//判断是否交叉
int flipm(double );//判断是否变异
int rnd(int low,int high);//产生low与high之间的任意数
void initialize();//遗传算法初始化
void preselectfitness(); //计算sumfiness,avefitness,maxfitness
void generation();
double suijibianli();//产生随机遍历指针
int fu(float );//选择要复制的个体
void crossover(indivial ,indivial ,indivial &,indivial &);//交叉
void bianyi(indivial &);//变异
void mubiaohanshu(indivial &);//计算适应度
void chibianhuan(indivial &);//对shiying进行尺度变换赋给fitness
double ran1(long *);//随机数初始
void bianma(double bianliang,unsigned *p);//编码
double yima(unsigned *p);
void guanjiancanshujisuan();//计算shiying,根据shiying计算sumshiying,对shiying进行尺度变换变成fitness,根据fitness计算sumfitness,avefitness,maxfitness
void jingyingbaoliu();
void glp(int n,int s,int *,int (*)[1],float (*)[1]);//glp生成函数
BOOL Exist(int Val, int Num, int *Array);//判断一个数在前面是否出现过
int cmpfitness(const void *p1,const void *p2)
{
float i=((indivial *)p1)->shiying;//现在是按照"适应度"排序,改成"个体"的话就是按照"个体"排序
float j=((indivial *)p2)->shiying;
return i<j ? -1:(i==j ? 0:1);//现在是按升序牌排列,将1和-1互换后就是按降序排列
}
void main()
{
initialize();
cout<<zuiyougeti->geti<<" "<<zuiyougeti->shiying<<endl;/////////////
for(gen=1;gen<maxgen;gen++)
{ generation();
}
jingyingbaoliu();
cout<<setiosflags(ios::fixed)<<setprecision(6)<<zuiyougeti->geti<<" "<<setiosflags(ios::fixed)<<setprecision(6)<<(zuiyougeti->shiying)<<endl;////////////////
delete [] newpop;
delete [] nowpop;
delete [] zuiyougeti;
system("pause");
}
void initialize()
{
int q[zhongqunshu1][1],s=1;
float xx[zhongqunshu1][1];//生成的glp用x储存
int h[1]={1};//生成向量
zuiyougeti=new indivial;//最优个体的生成
zhongqunshu=200;//种群数量
nowpop=new indivial[zhongqunshu1];//当代
newpop=new indivial[zhongqunshu1];//新一代
maxgen=150;//最大代数
gen=0;//起始代
lchrom=22;//基因数量的初始化
mysrand(time(0));//随机数种子
a[0]=seed;//随机数种子
//对最优个体的初始化
zuiyougeti->geti=0;
zuiyougeti->fitness=0;
zuiyougeti->shiying=0;
//
glp(zhongqunshu,s,h,q,xx);
//for(int i=0;i<zhongqunshu1;i++)//产生初始种群
//{
// for(int j=0;j<s;j++)
// {
// nowpop[i].geti=zuobianjie+(youbianjie-zuobianjie)*xx[i][j];
// }
//}
for(int i=0;i<zhongqunshu1;i++)//产生初始种群
{
nowpop[i].geti=zuobianjie+(youbianjie-(zuobianjie))*ran1(a);
}
//nowpop[0].geti=999;//////////////////////////
guanjiancanshujisuan();
jingyingbaoliu(); //精英保留的实现
guanjiancanshujisuan();//计算shiying,根据shiying计算sumshiying,对shiying进行尺度变换变成fitness,根据fitness计算sumfitness,avefitness,maxfitness
}
void jingyingbaoliu() //精英保留的实现
{
indivial *zuiyougetiguo;
zuiyougetiguo=new indivial[zhongqunshu1];//建立一个过渡数组
for(int i=0;i<zhongqunshu;i++)//将当代个体复制到过渡数组中
zuiyougetiguo[i]=nowpop[i];
qsort(zuiyougetiguo,zhongqunshu1,sizeof(indivial),&cmpfitness);//按fitness升序排序
// cout<<"zuiyougetiguo适应度:"<<zuiyougetiguo[zhongqunshu1-1].shiying<<endl;///////////
// cout<<"zuiyougeti适应度:"<<zuiyougeti->shiying<<endl;///////////////////
//system("pause");
if(zuiyougetiguo[zhongqunshu-1].shiying>zuiyougeti->shiying)
{
*zuiyougeti=zuiyougetiguo[zhongqunshu1-1];//如果最优个体的fitness比当代最大的fitness小则用当代的代替之
//cout<<"zuiyougetiguo个体:"<<zuiyougetiguo[zhongqunshu1-1].geti<<endl;/////////////
//cout<<"zuiyougeti个体:"<<zuiyougeti->geti<<endl;/////////////
}
else
nowpop[rnd(0,(zhongqunshu1-1))]=*zuiyougeti;//否则的话从当代中随机挑选一个用最优个体代替之
delete [] zuiyougetiguo;//释放过渡数组
}
void guanjiancanshujisuan()//计算shiying,根据shiying计算sumshiying,对shiying进行尺度变换变成fitness,根据fitness计算sumfitness,avefitness,maxfitness
{
for(int i=0;i<zhongqunshu;i++)//计算shiying
mubiaohanshu(nowpop[i]);
for(i=0;i<zhongqunshu;i++)//对shiying进行尺度变换变成fitness
chibianhuan(nowpop[i]);
preselectfitness();//根据fitness计算sumfitness,avefitness,maxfitness
}
void mubiaohanshu(indivial &bianliang)//计算shiying
{
bianliang.shiying=(bianliang.geti*cos(bianliang.geti)+2.0);//目标函数
}
void chibianhuan(indivial &bianliang)//对shiying进行尺度变换变成fitness
{
double T;//退火温度
T=T0*(pow(0.99,(gen+1-1)));
double sum=0;
for(int j=0;j<zhongqunshu;j++)
sum+=exp(nowpop[j].shiying/T);
bianliang.fitness=exp(bianliang.shiying/T)/sum;//算出fitness
}
void preselectfitness()//根据fitness计算sumfitness,avefitness,maxfitness
{
int j;
sumfitness=0;
for(j=0;j<zhongqunshu;j++)
sumfitness+=nowpop[j].fitness;
indivial *guo;
guo=new indivial[zhongqunshu1];
for(j=0;j<zhongqunshu;j++)
guo[j]=nowpop[j];
qsort(guo,zhongqunshu1,sizeof(indivial),&cmpfitness);
maxfitness=guo[zhongqunshu1-1].fitness;
avefitness=sumfitness/zhongqunshu1;
delete [] guo;
}
void generation()
{
indivial fuqin1,fuqin2,*pipeiguo,*pipeichi;
int *peiishuzu;//用来存放产生的随机配对
pipeiguo=new indivial[zhongqunshu1];
pipeichi=new indivial[zhongqunshu1];
peiishuzu=new int[zhongqunshu1];
int member1,member2,j=0,fujishu=0,i=0,temp=0,tt=0;
float zhen;
//随机遍历的实现
for(zhen=suijibianli();zhen<1;(zhen=zhen+zhenjuli))//设定指针1/66
{
pipeichi[fujishu]=nowpop[fu(zhen)];
fujishu++;
}

//交叉与变异的实现
//交叉
for(i=0;i<zhongqunshu1;i++)
{
peiishuzu[i]=-1;
}
for (i=0; i<zhongqunshu1; i++)
{
temp =rnd(0,zhongqunshu1-1); //产生值在0-zhongqunshu1-1的随机数
while(Exist(temp, i, peiishuzu))//判断产生的随机数是否已经产生过,如果是,则再产生一个随机数
{
temp =rnd(0,zhongqunshu1-1);
}
//如果没有的话,则把产生的随机数放在peiishuzu中
*(peiishuzu+i) = temp;
}
for(i=0;i<zhongqunshu1-1;i=i+2)
{
fuqin1=pipeichi[peiishuzu[i]];
fuqin2=pipeichi[peiishuzu[i+1]];
crossover(fuqin1,fuqin2,newpop[i],newpop[i+1]);
}
for(j=0;j<zhongqunshu1;j++)
{
//if(newpop[j].geti<-1000)
//cout<<"个体数值小于下界了";
nowpop[j].geti=newpop[j].geti;
}
//
guanjiancanshujisuan();
//变异的实现
for(j=0;j<zhongqunshu;j++)
{
bianyi(nowpop[j]);
}
//
guanjiancanshujisuan();
//精英保留的实现
jingyingbaoliu();
//
guanjiancanshujisuan();
delete [] peiishuzu;
delete [] pipeichi;
delete [] pipeiguo;
}
void crossover(indivial parent1,indivial parent2,indivial &child1,indivial &child2)//交叉
{
int j;
unsigned *panan;
panan=new unsigned[lchrom];
parent1.chrom=new unsigned[lchrom];
parent2.chrom=new unsigned[lchrom];
child1.chrom=new unsigned[lchrom];
child2.chrom=new unsigned[lchrom];
//cout<<"jiaocha"<<endl;///////////////////////
bianma(parent1.geti,parent1.chrom);
bianma(parent2.geti,parent2.chrom);
if(flipc(parent1.fitness,parent2.fitness))
{
for(j=0;j<lchrom;j++)
panan[j]=rnd(0,1);
//for(j=0;j<lchrom;j++)////////////////
// {
// cout<<panan[j];/////////////
// }
// cout<<endl;////////////////
// system("pause");////////////////
for(j=0;j<lchrom;j++)
{
if(panan[j]==1)
child1.chrom[j]=parent1.chrom[j];
else
child1.chrom[j]=parent2.chrom[j];
}
for(j=0;j<lchrom;j++)
{
if(panan[j]==0)
child2.chrom[j]=parent1.chrom[j];
else
child2.chrom[j]=parent2.chrom[j];
}
//for(j=0;j<lchrom;j++)////////////////
//{
// cout<<child1.chrom[j];/////////////
// }
//cout<<endl;////////////////
// system("pause");////////////////
child1.geti=yima(child1.chrom);
child2.geti=yima(child2.chrom);
delete [] child2.chrom;
delete [] child1.chrom;
delete [] parent2.chrom;
delete [] parent1.chrom;
delete [] panan;
}
else
{
for(j=0;j<lchrom;j++)
{
child1.chrom[j]=parent1.chrom[j];
child2.chrom[j]=parent2.chrom[j];
}
child1.geti=yima(child1.chrom);
child2.geti=yima(child2.chrom);
delete [] child2.chrom;
delete [] child1.chrom;
delete [] parent2.chrom;
delete [] parent1.chrom;
delete [] panan;
}
}
void bianyi(indivial &child)//变异
{
child.chrom=new unsigned[lchrom];
//cout<<"变异"<<endl;
bianma(child.geti,child.chrom);
for(int i=0;i<lchrom;i++)
if(flipm(child.fitness))
{
if(child.chrom[i]=0)
child.chrom[i]=1;
else
child.chrom[i]=0;
}
child.geti=yima(child.chrom);
delete [] child.chrom;
}
void bianma(double bianliang,unsigned *p)//编码
{
unsigned *q;
unsigned *gray;
q=new unsigned[lchrom];
gray=new unsigned[lchrom];
int x=0;
int i=0,j=0;
if(bianliang<zuobianjie)///////////////////
{
cout<<"bianliang:"<<bianliang<<endl;/////////
system("pause");
}
//cout<<youbianjie-(zuobianjie)<<endl;
//system("pause");
x=(bianliang-(zuobianjie))*((pow(2,lchrom)-1)/(youbianjie-(zuobianjie)));
//cout<<x<<endl;///////////
if(x<0)
system("pause");///////////
for(i=0;i<lchrom;i++)
{
q[i]=0;
p[i]=0;
}
i=0;
while (x!=0&&(i!=lchrom))
{
q[i]=(unsigned)(x%2);
x=x/2;
i++;
}
// for(i=0;i<lchrom;i++)//////////////////
// cout<<q[i];///////////////
// cout<<endl;///////////
int w=lchrom-1;
if(q[w]!=0&&q[w]!=1)
system("pause");
for(j=0;j<lchrom&&w>0;j++)
{
p[j]=q[w];
w--;
}
//cout<<"yuanma"<<endl;
//for(j=0;j<lchrom;j++)///////////
// cout<<p[j];////////
//cout<<endl;////////////////////
gray[0]=p[0];
for(j=1;j<lchrom;j++)
{
if(p[j-1]==p[j])
gray[j]=0;
else if(p[j-1]!=p[j])
gray[j]=1;
}
for(j=0;j<lchrom;j++)
p[j]=gray[j];
//cout<<"geleima"<<endl;
//for(j=0;j<lchrom;j++)///////////
// cout<<p[j];////////
//cout<<endl;////////////////////
//system("pause");///////////

delete [] gray;
delete [] q;
}
double yima(unsigned *p) //译码
{

int i=0;
// for(i=0;i<lchrom;i++)/////////
// {
// cout<<p[i];//////
// }
// cout<<endl;/////////
// system("pause");//////////
int x=0;
unsigned *q;
q=new unsigned[lchrom];
q[0]=p[0];
// cout<<q[0]<<endl;//////////////////
// system("pause");//////////

for(int j=1;j<lchrom;j++)
{
if(q[j-1]==p[j])
q[j]=0;
else if(q[j-1]!=p[j])
q[j]=1;
}
// for(i=0;i<lchrom;i++)//////
// {
// cout<<q[i];//////////
// if(q[i]!=0&&q[i]!=1)
// {
// cout<<q[i];
// system("pause");
// }
// }
// cout<<endl;////////
// system("pause");///////////////////
for(i=0;i<lchrom;i++)
x=x+q[i]*pow(2,(lchrom-i-1));
if(x<0)
{
cout<<"译码出错1"<<endl;
system("pause");
}
//cout<<"x:"<<x<<endl;
double bianliang;
//cout<<pow(2,22)<<endl;
//cout<<2000*x<<endl;
//cout<<(x*(2000/(pow(2,22)-1)))<<endl;
bianliang=(x*((youbianjie-(zuobianjie))/(pow(2,lchrom)-1)))+zuobianjie;
if(bianliang<zuobianjie)
{
cout<<"译码出错2"<<endl;
system("pause");
}
delete [] q;
return bianliang;
}
double ran1(long *im)
{
int j;
long k;
static long im2=123456789;
static long iy=0;
static long iv[NTAB];
float temp;
if (*im <= 0)
{
if (-(*im) < 1) *im=1;
else *im = -(*im);
im2=(*im);
for (j=NTAB+7;j>=0;j--)
{
k=(*im)/IQ1;
*im=IA1*(*im-k*IQ1)-k*IR1;
if (*im < 0) *im += IM1;
if (j < NTAB) iv[j] = *im;
}
iy=iv[0];
}
k=(*im)/IQ1;
*im=IA1*(*im-k*IQ1)-k*IR1;
if (*im < 0) *im += IM1;
k=im2/IQ2;
im2=IA2*(im2-k*IQ2)-k*IR2;
if (im2 < 0) im2 += IM2;
j=iy/NDIV;
iy=iv[j]-im2;
iv[j] = *im;
if (iy < 1) iy += IMM1;
if ((temp=AM*iy) > RNMX) return RNMX;
else return temp;
}
double suijibianli()//随机遍历
{
double i=ran1(a);
while(i>zhenjuli)
{
i=ran1(a);
}
//cout<<i<<endl;//////////////
return i;
}
int fu(float p)//复制
{
int i;
double sum=0;
if(sumfitness!=0)
{
for(i=0;(sum<p)&&(i<zhongqunshu);i++)
sum+=nowpop[i].fitness/sumfitness;
}
else
i=rnd(1,zhongqunshu1);
return(i-1);
}

int rnd(int low, int high) /*在整数low和high之间产生一个随机整数*/
{
int i;
if(low >= high)
i = low;
else
{
i =(int)((ran1(a) * (high - low + 1)) + low);
if(i > high) i = high;
}
return(i);
}
int flipc(double p,double q)//判断是否交叉
{
double pc1=0.9,pc2=0.6;
if((p-q)>0)
{
if(p>=avefitness)
{
pc=pc1-(pc1-pc2)*(p-avefitness)/(maxfitness-avefitness);
}
else
pc=pc1;
}
else
{
if(q>=avefitness)
{
pc=pc1-(pc1-pc2)*(q-avefitness)/(maxfitness-avefitness);
}
else
pc=pc1;
}
if(ran1(a)<=pc)
return(1);
else
return(0);
}
int flipm(double p)//判断是否变异
{
double pm1=0.001,pm2=0.0001;
if(p>=avefitness)
{
pm=(pm1-(pm1-pm2)*(maxfitness-p)/(maxfitness-avefitness));
}
else
pm=pm1;
if(ran1(a)<=pm)
return(1);
else
return(0);
}
void glp(int n,int s,int *h,int (*q)[1],float (*xx)[1])//glp
{
int i=0,j=0;
//求解q
for(i=0;i<n;i++)
{
for(j=0;j<s;j++)
{
*(*(q+i)+j)=((i+1)*(*(h+j)))%n;
}
}
i=n-1;
for(j=0;j<s;j++)
{
*(*(q+i)+j)=n;
}
//求解x
for(i=0;i<n;i++)
{
for(j=0;j<s;j++)
{
*(*(xx+i)+j)=(float)(2*(*(*(q+i)+j))-1)/(2*n);
}
}
}
BOOL Exist(int Val, int Num, int *Array)//判断一个数是否在一个数组的前Num个数中
{
BOOL FLAG = FALSE;
int i;
for (i=0; i<Num; i++)
if (Val == *(Array + i))
{
FLAG = TRUE;
break;
}
return FLAG;
}

⑷ pso的多目标优化

在多目标优化问题中,每个目标函数可以分别独立进行优化,然后为每个目标找到最优值。但是,很少能找到对所有目标都是最优的完美解,因为目标之间经常是互相冲突的,只能找到Pareto最优解。
PSO算法中的信息共享机制与其他基于种群的优化工具有很大的不同。在遗传算法(GA)中,染色体通过交叉互相交换信息,是一种双向信息共享机制。但是在PSO算法中,只有gBest(或nBest)给其他微粒提供信息,是一种单向信息共享机制。由于点吸引特性,传统的PSO算法不能同时定位构成Pareto前锋的多个最优点。虽然通过对所有目标函数赋予不同的权重将其组合起来并进行多次运行,可以获得多个最优解,但是还是希望有方法能够一次同时找到一组Pareto最优解。
在PSO算法中,一个微粒是一个独立的智能体,基于其自身和同伴的经验来搜索问题空间。前者为微粒更新公式中的认知部分,后者为社会部分,这二者在引导微粒的搜索方面都有关键的作用。因此,选择适当的社会和认知引导者(gBest和pBest)就是MO-PSO算法的关键点。认知引导者的选择和传统PSO算法应遵循相同的规则,唯一的区别在于引导者应按照Pareto支配性来确定。社会引导者的选择包括两个步骤。第一步是建立一个从中选取引导者的候选池。在传统PSO算法中,引导者从邻居的pBest之中选取。而在MO-PSO算法中更常用的方法是使用一个外部池来存储更多的Pareto最优解。第二步就是选择引导者。gBest的选择应满足如下两个标准:首先,它应该能为微粒提供有效的引导来获得更好的收敛速度;第二,它还需要沿Pareo前锋来提供平衡的搜索,以维持种群的多样性。文献中通常使用两种典型的方法:(1)轮盘选择模式,该方式按照某种标准进行随机选择,其目的是维持种群的多样性;(2)数量标准:按照某种不涉及随机选择的过程来确定社会引导者。
Moore最早研究了PSO算法在多目标优化中的应用,强调了个体和群体搜索二者的重要性,但是没有采用任何维持多样性的方法。Coello在非劣最优概念的基础上应用了一个外部“容器”来记录已找到的非支配向量,并用这些解来指导其它微粒的飞行。Fieldsend采用一种称为支配树的数据结构来对最优微粒进行排序。Parsopoulos应用了权重聚合的方法。Hu应用了动态邻域,并在此基础上利用扩展记忆,按词典顺序依次优化各个目标。Ray使用聚集机制来维持多样性,并用一个多水平筛来处理约束。Lu使用了动态种群策略。Bartz-Beielstein采用归档技术来提高算法性能。Li在PSO算法中采用NSGA-II算法中的主要机制,在局部最优微粒及其后代微粒之间确定局部最优微粒;并此基础上又提出一种新的算法,在适应值函数中使用最大最小策略来确定Pareto支配性。张利彪使用多个目标函数下各最优位置的均值来指导微粒飞行。Pulido使用多个子种群并采用聚类技术来求解多目标规划问题。Mahfouf采用加权聚合方法来计算微粒的适应值,并据此确定引导微粒的搜索。Salazar-Lechuga使用适应值共享技术来引导微粒的搜索。Gong提出微粒角度的概念,并使用最小微粒角度和微粒密度来确定局部最优和全局最优微粒。基于AER模型,Zhang提出一种新的智能PSO模型,来将种群驱向Pareto最优解集。Ho提出一种新的适应值分配机制,并使用寿命(Age)变量来保存和选择最优历史记录。Huang将CLPSO算法应用到多目标规划中。Ho提出另一种基于Pareto的与尺度无关的适应值函数,并使用一种基于正交试验设计的智能运动机制(IMM)来确定微粒的下一步运动。Branke系统研究了多种个体最优微粒的选择方法对MOPSO算法性能的影响。张勇考虑储备集更新策略在多目标PSO算法中的关键作用,提出一种两阶段储备集更新策略。
原萍提出一种分布式PSO算法—分割域多目标PSO算法(DRMPSO),并将其应用到基站优化问题。向量评价PSO算法(VEPSO)是一种受向量评价遗传算法(VEGA)的启发提出的一种算法,在VEPSO算法中,每个种群仅使用多个目标函数之一来进行评价,同时各种群之间互相交互经验。将每个种群分配到一台网络PC上,即可直接使VEPSO算法并行化,以加速收敛。Vlachogiannis应用并行VEPSO算法来确定发电机对输电系统的贡献。熊盛武利用PSO算法的信息传递机制,在PSO算法中引入多目标演化算法常用的归档技术,并采用环境选择和配对选择策略,使得整个群体在保持适当的选择压力的情况下收敛于Pareto最优解集。
由于适应值的计算非常消耗计算资源,为了减少计算量,需要减少适应值评价的次数。Reyes-Sierra采用适应值继承和估计技术来实现该目标,并比较了十五种适应值继承技术和四种估计技术应用于多目标PSO算法时的效果。
保持MOPSO中的多样性的方法主要有两种:sigma方法和ε-支配方法。Villalobos-Arias在目标函数空间中引入条块划分来形成聚类,从而保持多样性。

⑸ 求助IMM算法与GPB算法仿真对比

这个简单,把数据输入电脑,按1厘米一个档次进行穷举,顶多穷举个几百次最优解就出来了,计算机一会就算完了

⑹ imm什么意思

IMM
abbr. Institution of Mining and Metallurgy<英>矿冶学会;
[例句]A novel two-layer interactive multiple model ( IMM) tracking algorithm for turn maneuver is proposed.
针对转弯机动目标跟踪,提出了一种两层交互多模型(IMM)跟踪算法。

⑺ imm推出的某九十天国库券期货的报价为95试计算该国债期货的价格

这你可以在官网就可以处理ID啊

⑻ 最好的背单词软件

Memoryer™新一代神经网络背单词软件,由记忆工场™的脑与神经科学、认知心理学和人工智能领域的科学家团队研制,具有独步全球的个性化多核记忆引擎IMME;独有的隔夜/长时记忆力算法,在抗遗忘方面处于世界领先地位;有史以来最大的英语单词记忆编码库;新一代人工智能虚拟老师;可能是你见过的最酷的在线成绩单;7大排行榜,网友大比拼;记忆论坛是学习记忆大师专业记忆术的好地方;易记网络邀请你分享所有学科的最佳记忆方法和快速记忆策略;Memoryer经过上千次的脑波分析验证和优化,被评为最酷最好的背单词软件。

⑼ 目标跟踪都有那些算法

目标跟踪,利用相邻两帧的区域匹配从图像序列中建立目标链,跟踪目标从进入监视范围到驶离监视范围的整个过程。首称要确定匹配准则。常用的图像匹配方法有Hausdorff距离区域法和图像互相关。

热点内容
集群服务器地址都是一样的吗 发布:2024-10-10 01:07:39 浏览:324
java怎么开平方 发布:2024-10-10 01:02:25 浏览:486
windowsserver更新服务器搭建 发布:2024-10-10 00:42:32 浏览:656
kz解压缩 发布:2024-10-10 00:27:19 浏览:667
方舟编译器呢 发布:2024-10-10 00:13:41 浏览:914
阿里云服务器安装图形 发布:2024-10-09 23:40:45 浏览:863
cb编译器怎么下 发布:2024-10-09 23:37:38 浏览:8
编译translation 发布:2024-10-09 23:24:23 浏览:10
服务器cpu能供多少电脑使用 发布:2024-10-09 23:05:21 浏览:350
算法和嵌入式 发布:2024-10-09 23:04:34 浏览:555