欢迎订阅《FPGA学习入门100例教程》、《MATLAB学习入门100例教程》
目录
刹车类别A
| 温度1 | 测试1 | 测试2 | ....... | 测试n |
| 温度3 | 测试1 | 测试2 | ....... | 测试n |
| ....... | ||||
| ....... | ||||
| 温度N | 测试1 | 测试2 | ....... | 测试n |
每次测试的温度间隔,根据实际操作的可行性,来选择。这个无所谓,从里面看到温度从20多度到60度,如果条件允许,可以再将温度扩展一下。即测试的温度范围再大点。然后,对于同一个温度,测试次数的确定,如果你每次测试的数值差别较大,那么测试次数最好多点,如果每次测试的差别不大,那么测试20次就够了。
粒子群优化(PSO)算法是通过模拟鸟群觅食过程中的迁徙和群聚行为而提出的一种基于群体智能的全局随机搜索算法。PSO是将群体(swarm)中的个体看作是在D维搜索空间中没有质量和体积的粒子(particle),每个粒子以一定的速度在解空间运动,并向自身历史最佳位置pbest和邻域历史最佳位置聚集,实现对候选解的进化。
PSO从这种模型中得到启示并用于解决优化问题。PSO中,每个优化问题的潜在解都是搜索空间中的一只鸟,称之为粒子。所有的粒子都有一个由被优化的函数决定的适值( fitness value),每个粒子还有一个速度决定它们飞翔的方向和距离。然后粒子们就追随当前的最优粒子在解空间中搜索。
PSO初始化为一群随机粒子,然后通过迭代找到最优解。在每一次迭代中,粒子通过跟踪两个极值来更新自己;第一个就是粒子本身所找到的最优解,这个解称为个体极值;另一个极值是整个种群目前找到的最优解,这个极值是全局极值。另外也可以不用整个种群而只是用其中一部分作为粒子的邻居,那么在所有邻居中的极值就是局部极值。

- ................................................................
- parameter;
- ishow = (get(handles.checkbox1,'Value'));
- if choice == 1
- L2 = func_anti_noise(L1,T1);
- else
- L2 = func_anti_noise(L1,T2);
- end
- hold off;
- axes(handles.axes4);
- color_table;
- for i = 1:len1
- str = colors{i};
- plot(L2(i,:),str);
- hold on;
- end
- if ishow == 1
- figure;
- color_table;
- for i = 1:len1
- str = colors{i};
- plot(L2(i,:),str);
- hold on;
- end
- title('Leaks anti noise');
- end
-
-
- % --- Executes on button press in pushbutton4.
- function pushbutton4_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton4 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%多项式拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%多项式拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%多项式拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%多项式拟合%%%%%%%%%%%
- parameter;
- ishow = (get(handles.checkbox1,'Value'));
- KK = str2num(get(handles.edit1,'String'));
-
- if choice == 1
- [y1,x1,y0,x0,P1fit] = func_fit_means(T1,L2,KK);
- else
- [y1,x1,y0,x0,P1fit] = func_fit_means(T2,L2,KK);
- end
- hold off;
- axes(handles.axes5);
- plot(x0,y0,'o');
- hold on;
- plot(x1,y1,'r','LineWidth',1);
- hold on;
-
- if ishow == 1
- figure;
- plot(x0,y0,'o');
- hold on;
- plot(x1,y1,'r','LineWidth',1);
- hold on;
- title('多项式拟合曲线');
-
- end
- %计算拟合误差
- err1 = func_error(y0,x0,y1,x1);
- set(handles.edit2,'string',num2str(err1));
-
-
-
-
- % --- Executes on button press in pushbutton5.
- function pushbutton5_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton5 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最大值多项式拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最大值多项式拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最大值多项式拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最大值多项式拟合%%%%%%%%%%%
- parameter;
- ishow = (get(handles.checkbox1,'Value'));
- KK = str2num(get(handles.edit1,'String'));
- if choice == 1
- [y1max,x1max,y0max,x0max,P1max] = func_fit_max(T1,L2,KK);
- else
- [y1max,x1max,y0max,x0max,P1max] = func_fit_max(T2,L2,KK);
- end
- hold off;
- axes(handles.axes5);
- plot(x0,y0,'o');
- hold on;
- plot(x1,y1,'r','LineWidth',1);
- hold on;
- plot(x1max,y1max,'g','LineWidth',1);
- hold on;
- if ishow == 1
- figure;
- plot(x0,y0,'o');
- hold on;
- plot(x1,y1,'r','LineWidth',1);
- hold on;
- plot(x1max,y1max,'g','LineWidth',1);
- hold on;
- title('多项式拟合曲线');
- end
- function pushbutton6_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton6 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最小值多项式拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最小值多项式拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最小值多项式拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最小值多项式拟合%%%%%%%%%%%
- parameter;
- ishow = (get(handles.checkbox1,'Value'));
- KK = str2num(get(handles.edit1,'String'));
- if choice == 1
- [y1min,x1min,y0min,x0min,P1min] = func_fit_min(T1,L2,KK);
- else
- [y1min,x1min,y0min,x0min,P1min] = func_fit_min(T2,L2,KK);
- end
- hold off;
- axes(handles.axes5);
- plot(x0,y0,'o');
- hold on;
- plot(x1,y1,'r','LineWidth',1);
- hold on;
- plot(x1max,y1max,'g','LineWidth',1);
- hold on;
- plot(x1min,y1min,'m','LineWidth',1);
- hold on;
- if ishow == 1
- figure;
- plot(x0,y0,'o');
- hold on;
- plot(x1,y1,'r','LineWidth',1);
- hold on;
- plot(x1max,y1max,'g','LineWidth',1);
- hold on;
- plot(x1min,y1min,'m','LineWidth',1);
- hold on;
- title('多项式拟合曲线');
-
- end
- % --- Executes on button press in pushbutton7.
- function pushbutton7_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton7 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PSO优化拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PSO优化拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PSO优化拟合%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PSO优化拟合%%%%%%%%%%%
- parameter;
- ishow = (get(handles.checkbox1,'Value'));
- KK = str2num(get(handles.edit1,'String'));
- %进行PSO优化
- [V_score2,PP2] = func_pso(P1fit,x1,y0,x0);
- ypso = polyval(PP2,x1);
-
- hold off;
- axes(handles.axes6);
- plot(V_score2,'Linewidth',2);
-
-
-
- hold off;
- axes(handles.axes7);
- plot(x0,y0,'o');
- hold on;
- plot(x1,y1,'r','LineWidth',1);
- hold on;
- plot(x1max,y1max,'g','LineWidth',1);
- hold on;
- plot(x1min,y1min,'m','LineWidth',1);
- hold on;
- plot(x1,ypso,'k--','LineWidth',2);
- hold on;
-
- if ishow == 1
- figure;
- subplot(121);
- plot(V_score2,'Linewidth',2);
- xlabel('迭代次数');
- ylabel('拟合误差优化过程');
- subplot(122);
- plot(x0,y0,'o');
- hold on;
- plot(x1,y1,'r','LineWidth',1);
- hold on;
- plot(x1max,y1max,'g','LineWidth',1);
- hold on;
- plot(x1min,y1min,'m','LineWidth',1);
- hold on;
- plot(x1,ypso,'k--','LineWidth',2);
- hold on;
- title('多项式拟合曲线');
- legend('实际测量值','均值拟合曲线','最大测量值拟合曲线','最小测量值拟合曲线','优化后拟合曲线');
- end
-
- err2 = func_error(y0,x0,ypso,x1);
- set(handles.edit3,'string',num2str(err2));
-
-
- % --- Executes on button press in pushbutton8.
- function pushbutton8_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton8 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%统计量计算%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%统计量计算%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%统计量计算%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%统计量计算%%%%%%%%%%%
- parameter;
- %计算均值和方差,将这两个计算结果存放到四个变量的后两位
- for i = 1:size(T1,1)
- %计算均值
- E1(i) = mean(T1(i,:));
- E2(i) = mean(T2(i,:));
- E3(i) = mean(P1(i,:));
- E4(i) = mean(L2(i,:));
- %计算标准差
- D1(i) = std(T1(i,:));
- D2(i) = std(T2(i,:));
- D3(i) = std(P1(i,:));
- D4(i) = std(L2(i,:));
- %计算方差
- V1(i) = var(T1(i,:));
- V2(i) = var(T2(i,:));
- V3(i) = var(P1(i,:));
- V4(i) = var(L2(i,:));
- end
-
- figure(10);
- plot(E1,E4,'b-o');
- hold on;
- plot(E1,D4,'r-o');
- hold on;
- plot(E1,V4,'k-o');
- legend('均值','标准差','方差');
-
-
- fid = fopen('statistics.txt','wt');
- fprintf(fid,'均值 标准差 方差\n');
- for i = 1:length(E4)
- fprintf(fid,'%f ',E4(i));
- fprintf(fid,'%f ',D4(i));
- fprintf(fid,'%f ',V4(i));
- fprintf(fid,'\n');
- end
- fclose(fid);
-
-
- % --- Executes on button press in pushbutton9.
- function pushbutton9_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton9 (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%拟合统计分析%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%拟合统计分析%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%拟合统计分析%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%拟合统计分析%%%%%%%%%%%
- parameter;
- ishow = (get(handles.checkbox1,'Value'));
- hold off;
- axes(handles.axes8);
- plot(x0,y0,'o');
- hold on;
- plot(x1,ypso,'k--','LineWidth',2);
- hold on;
- %找到最接近0的温度
- Best_tmp = 0;
- Ind = 0;
- for i = 2:length(ypso)-1
- if ypso(i-1) < 0 & ypso(i)>=0
- Best_tmp = x1(i);
- Ind = i;
- end
- end
- plot(x1(Ind),-4:0.01:8,'r','LineWidth',1);
- hold on;
- plot(x1,ypso(Ind),'r','LineWidth',1);
-
-
- %根据统计量分析
- %找到均值最小的值
- Tmpes = abs(E4);
- [V,I] = sort(Tmpes);
- Best_Team_mean = I(1);
-
- %找到均值最小的值
- Tmpes = abs(D4);
- [V,I] = sort(Tmpes);
- Best_Team_std = I(1);
-
- if ishow == 1
- figure(11);
- subplot(121);
- plot(x0,y0,'o');
- hold on;
- plot(x1,ypso,'k--','LineWidth',2);
- hold on;
- plot(x1(Ind),-4:0.01:8,'r','LineWidth',1);
- hold on;
- plot(x1,ypso(Ind),'r','LineWidth',1);
- axis square;
-
- subplot(122)
- plot(E1(Best_Team_mean),E4(Best_Team_mean),'--rs','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
- hold on;
- plot(E1,E4,'b-o');
- hold on;
- plot(E1(Best_Team_std),D4(Best_Team_std),'--rs','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
- hold on;
- plot(E1,D4,'k-o');
- hold on;
- axis square;
- legend('均值','标准差');
- end
-
- if Best_Team_mean == Best_Team_std
- msgbox(['最稳定温度为:',num2str(Best_tmp),' 对应的测试组为:',num2str(Best_Team_mean)]);
- else
- msgbox(['最稳定温度为:',num2str(Best_tmp),' 对应的测试组为:',num2str(Best_Team_mean),' 和 ',num2str(Best_Team_std)]);
- end

1:显示EXCEL中的数据,将EXCEL导入MATLAB,然后显示出其中的数据:

2:3:显示两个温度和泄漏之间对应关系图,这个是根据样本直接显示的
4:显示多个LEAK的样本值:
5:去掉LEAK样本中的一些异常采样点:

6:多项式拟合效果显示:

7:粒子群优化后的误差收敛曲线
8:粒子群优化后的多项式拟合效果:

9:最后的稳定性分析结果:


左图是根据优化拟合结果,得到实际中最有可能为稳定区域的温度值,如上面的对话框为31.43.
但是这个在实际中可能没法测试到。
所以上图中右图就是表示的这个情况,通过均值和方差最小化,得到测试组13和14两个测试温度区域为最佳的区域。
通过分析,

在GUI上的数据显示区域,会自动对最佳的数据测试组显示the best的字样。
A28-13