1 function pfgui_rmse(action,hObject,varargin)
\r
2 % Sorry, I didn't have enough time to write nice and documented GUI code.
\r
4 % Toolbox for nonlinear filtering.
\r
5 % Copyright (C) 2005 Jakob Rosén <jakob.rosen@gmail.com>
\r
7 % This program is free software; you can redistribute it and/or
\r
8 % modify it under the terms of the GNU General Public License
\r
9 % as published by the Free Software Foundation; either version 2
\r
10 % of the License, or (at your option) any later version.
\r
12 % This program is distributed in the hope that it will be useful,
\r
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 % GNU General Public License for more details.
\r
17 % You should have received a copy of the GNU General Public License
\r
18 % along with this program; if not, write to the Free Software
\r
19 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
23 if strcmp(action,'init')
\r
24 parenthandles=guidata(hObject);
\r
26 if isempty(parenthandles.xhat)&&isempty(parenthandles.xpred)
\r
27 msgbox('No filtered data available!');
\r
31 if isempty(parenthandles.xtrue)
\r
32 msgbox('No true x(t) data exists.');
\r
36 if ~(size(parenthandles.xtrue,3)==1||size(parenthandles.xtrue,3)==max(size(parenthandles.xhat,3),size(parenthandles.xpred,3)))
\r
37 msgbox('Wrong dimensions of the true x(t) data.');
\r
41 xhat_length=length(parenthandles.xhat);
\r
42 xpred_length=length(parenthandles.xpred);
\r
44 % xvars=parenthandles.filtobj.model.xvars;
\r
45 xvars=get(get(parenthandles.filtobj,'model'),'xvars');
\r
47 if xhat_length&&xpred_length
\r
48 lnames=cell(1,2*length(xvars));
\r
49 for i=1:length(xvars);
\r
50 lnames{i}=[xvars{i},' [xhat]'];
\r
52 for i=1:length(xvars);
\r
53 lnames{i+length(xvars)}=[xvars{i},' [xpred]'];
\r
55 lindex=[1:length(xvars), 1:length(xvars)];
\r
56 larray=[repmat({'xhat'},1,length(xvars)), repmat({'xpred'},1,length(xvars))];
\r
58 lnames=cell(1,length(xvars));
\r
60 lindex=[1:length(xvars)];
\r
61 larray=repmat({'xhat'},1,length(xvars));
\r
63 lnames=cell(1,length(xvars));
\r
65 lindex=[1:length(xvars)];
\r
66 larray=repmat({'xpred'},1,length(xvars));
\r
69 hf=figure('Name','RMSE command window');
\r
70 uicontrol(hf,'Style','Text','String','Select the state(s) to be included in the calculations:','Units','normalized','Position',[0.05 0.91 0.9 0.05],'HorizontalAlign','Left','Min',1,'Max',3,'FontName',myfont);
\r
72 uicontrol(hf,'Style','Listbox','String',cell2str(lnames),'Units','normalized','Position',[0.05 0.5 0.9 0.4],'Tag','state_select','HorizontalAlign','Left','Min',1,'Max',3,'Value',1:length(xvars),'FontName','FixedWidth');
\r
74 uicontrol(hf,'Style','Pushbutton','String','RMSE!','Units','normalized','Position',[0.05 0.1 0.9 0.05],'callback',sprintf('pfgui_rmse(''rmse'',%g,%g)',hObject,hf),'HorizontalAlign','Left','FontName',myfont);
\r
76 handles=guihandles(hf);
\r
77 handles.lnames=lnames;
\r
78 handles.lindex=lindex;
\r
79 handles.larray=larray;
\r
80 guidata(hf,handles);
\r
83 elseif strcmp(action,'rmse');
\r
85 parenthandles=guidata(hObject);
\r
86 handles=guidata(hf);
\r
88 states=get(handles.state_select,'value');
\r
91 msgbox('Please select at least one state');
\r
95 Ts=parenthandles.filtobj.Ts;
\r
100 for i=1:length(states);
\r
101 if strcmp(handles.larray{states(i)},'xhat')
\r
102 xhat_states(end+1)=handles.lindex(i);
\r
104 xpred_states(end+1)=handles.lindex(i);
\r
115 % Hej Gustaf. Jag antar att du vill verifiera RMSE-beräkningarna :)
\r
116 % Det är inte så snyggt, men jag ville inte slösa något krut på något som kanske
\r
117 % ändå ändras snart... Du får fixa och trixa på fyra ställen... Du ser dem, förstås
\r
120 runs=max(size(parenthandles.xhat,3),size(parenthandles.xpred,3));
\r
122 if size(parenthandles.xtrue,3)==runs
\r
123 rmse=sqrt(sum(sum((parenthandles.xhat(xhat_states,:,:)-parenthandles.xtrue(xhat_states,:,:)).^2,3),1)/runs);
\r
125 rmse=sqrt(sum(sum((parenthandles.xhat(xhat_states,:,:)-repmat(parenthandles.xtrue(xhat_states,:,1),[1 1 runs])).^2,3),1)/runs);
\r
127 plot(Ts,rmse,getcolors(1));
\r
128 legendcell{end+1}='RMSE xhat';
\r
135 if size(parenthandles.xtrue,3)==runs
\r
136 xpred_rmse=sqrt(sum(sum((parenthandles.xpred(xpred_states,:,:)-parenthandles.xtrue(xpred_states,:,:)).^2,3),1)/runs);
\r
138 xpred_rmse=sqrt(sum(sum((parenthandles.xpred(xpred_states,:,:)-repmat(parenthandles.xtrue(xpred_states,:,1),[1 1 runs])).^2,3),1)/runs);
\r
140 plot(Ts,xpred_rmse,getcolors(2));
\r
141 legendcell{end+1}='RMSE xpred';
\r
146 legend(legendcell{:});
\r