www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/validate_prediction.m

    function varargout= validate_prediction(Action,varargin)
% VALIDATE_PREDICTION prediction plots for MBC model selection tools

%  Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc.


switch lower(Action)
    case 'create'
        [varargout{1:2}]= i_Create(varargin{:});
    case {'modelselect','draw','view'}
        i_View(varargin{:});
    case 'print'
        i_Print(varargin{:});
end


function [Tool, mainLyt]= i_Create(hParent,DataType)

Tool.Name= '&Predicted/Observed';
Tool.MultiSelect= 0;
Tool.mfile= mfilename;
Tool.Icon = 'obspred.bmp';
Tool.Renderer='painters';

if nargin<2
    Tool.DataType= 'FIT';
else
    Tool.DataType= DataType;
end

%-------------ContextMenu for plots---------------%%
uic=i_uxmenu(hParent);
%----------------------Legend------------------------%%
pH=uicontrol('Parent',hParent,...
    'Style','text',...
    'HorizontalAlignment','left',...
    'String','Legend:');
legendWrapper = mbcgui.widget.AxesPanel(...
    'Parent',hParent);
hLegend=legendWrapper.AxesHandle;
set(hLegend,...
    'Units','pixels',...
    'XLim',[0 1],'YLim',[0 1],...
    'Box','on',...
    'XTick',[],'YTick',[],...
    'DefaultTextFontSize',8,...
    'DefaultTextFontName','Lucida Console');

%-------------------------Axes--------------------------------
axLyt=mbcgui.widget.AxesContainer(...
    'Parent',hParent,...
    'Border', [60 35 30 30]);
AxHand = axLyt.AxesHandle;
set(AxHand,...
    'Units','pixels',...
    'NextPlot','add',...
    'XGrid','on','YGrid','on',...
    'ButtonDownFcn',@(h,evt) mv_zoom(h),...
    'UIContextMenu',uic,...
    'Box','on');


mbctitle(AxHand, 'Predicted/Observed');

Tool.Legend= hLegend;
Tool.AxHand= AxHand;

%---------------LAYOUTS----------------------%
mainLyt = xreggridbaglayout(hParent,...
    'packstatus','off',...
    'dimension',[3 3],...
    'rowsizes',[15 80 -1],...
    'colsizes', [10 -1 10], ...
    'border',[0 10 0 5],...
    'mergeblock', {[3 3], [1 3]}, ...
    'elements',{[], [], axLyt, pH, legendWrapper});

Tool.helpmenus={'&Predicted/Observed Help','xreg_modSel_predObs'};


% --------------------------------------------------------
% SUBFUNCTION i_View
% --------------------------------------------------------
function i_View(hParent,varargin)

[Tool,p,Models]= i_GetTool(hParent);
ax=Tool.AxHand(1);

ch=get(ax,'Children');
delete(ch(isgraphics(ch)));

% get context menus for plot options
ux=get(ax,'UIContextMenu');
uitn = findobj(ux,'Tag','Test Num');
uibd = findobj(ux,'Tag','showBD1');
uiy = findobj(ux,'Tag','ytrans_units');
uici = findobj(ux,'Tag','confidence interval');
% check if ytrans available
if HasTransform(Models{1})
    set(uiy,'Enable','on');
else
    set(uiy,'Enable','off','Checked','off');
end
% check that confidence intervals can be drawn
% use pevcheck as is done inside plot
if pevcheck(Models{1})
    set(uici,'Enable','on');
else
    set(uici,'Enable','off','Checked','off');
end

plotoptions = [strcmp(get(uibd,'Checked'),'on'),...
    strcmp(get(uitn,'Checked'),'on'),...
    strcmp(get(uici,'Checked'),'on')];

if strcmp(Tool.DataType,'FIT')
    % do the plotting
    [X,Y,DataOk]= FitData(p(1).info);
else
    [X,Y]= getdata(p(1).info,Tool.DataType);
    DataOk= ~isbad(Y);
end
lh= plot(Models{1},X,Y,DataOk,plotoptions,ax);
set(lh(1),'Tag','main line');
% check whether or not TestNumbers are needed
i_TestNums(uitn,[],hParent,X(DataOk,:),Y(DataOk));
% set up the legend
delete(get(Tool.Legend,'Children'));

tags = {'main line','BDPts','localfit','free knot line',...
    'Rbf center mark'};
allLabels = {'Data','Removed data','Model fit','Knot position','RBF center'};
% throw out empty lines
lineh=[];legLabels={};
for i=1:length(tags)
    h= findobj(ax,'Type','line','Tag',tags{i});
    if ~isempty(h) && isgraphics(h) && ~isempty(get(h,'XData')) % no xdata
        lineh=[lineh(:)',h]; legLabels={legLabels{:},allLabels{i}};
    end
end

ht= .98;
for i=1:length(lineh);
    if ~strcmp(get(lineh(i),'LineStyle'),'-')
        xd= 0.05;
        yd=ht-0.05;
    else
        xd=[0.03, 0.07]; yd=[ht-0.05,ht-0.05];
    end

    line('XData',xd,'YData',yd,...
        'Marker',get(lineh(i),'Marker'),...
        'MarkerFaceColor',get(lineh(i),'MarkerFaceColor'),...
        'MarkerSize',get(lineh(i),'MarkerSize'),...
        'LineStyle',get(lineh(i),'LineStyle'),...
        'LineWidth',get(lineh(i),'LineWidth'),...
        'Color',get(lineh(i),'Color'),...
        'Parent',Tool.Legend);
    th=text('Position',[.1 ht],'String',legLabels{i},...
        'HorizontalAlignment','left','VerticalAlignment','top',...
        'Clipping','on',...
        'Interpreter','none',...
        'Parent',Tool.Legend);
    Textent= get(th,'Extent');
    ht= ht-Textent(4);
end

% --------------------------------------------------------
% SUBFUNCTION i_TestNums
% --------------------------------------------------------
function i_TestNums(src,~,hParent,X,~)

Tool=i_GetTool(hParent);
if strcmp(get(src,'Checked'),'off')
    tH= findobj(Tool.AxHand,'Type','text','Tag','testnum');
    delete(tH);
else
    lH1= findobj(Tool.AxHand(1),'Type','line','Tag','main line');
    xdata1= get(lH1(end),'XData');
    ydata1= get(lH1(end),'YData');

    if size(X,3)==size(X,1)
        tns= testnum(X);
    else
        tns= 1:size(X,1);
    end
    
    for i=1:length(xdata1)
        text(xdata1(i),ydata1(i),num2str(tns(i)),...
            'Parent',Tool.AxHand(1),...
            'FontSize',8,...
            'HorizontalAlignment','right',...
            'HitTest','off',...
            'Tag','testnum',...
            'Clipping','on',...
            'VerticalAlignment','bottom');
    end
end


% ===========================================
% Function i_viewoptsflag
% ===========================================
function i_viewoptsflag(~,~,hParent)
% callback when uicontextmenus clicked for Conf Intervals, Show Outliers etc
h=gcbo;

ch= get(h,'Checked');
% change the check status
if strcmp(ch,'on')
    set(h,'Checked','off');
else
    set(h,'Checked','on');
end
i_View(hParent)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% i_Print printing subfunction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function i_Print(Tool,Name)

lyt1= Tool.AxHand;
lyt2= [];
printlayout1(lyt1,lyt2,Name);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% i_GetTool subfunction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Tool,p,Models,ModNo,ModelList]=i_GetTool(hParent)

if nargout==1
    Tool=mv_ValidationTool('get',hParent);
else
    [Tool,ModelInfo,ModelList]=mv_ValidationTool('get',hParent);
    ModNo= ModelInfo{1};
    p= ModelInfo{2};
    Models= ModelInfo{3};
end

% ===========================================
% Function i_copy
% ===========================================
function i_copy(~, ~,hParent)
% get the axes
ax= gca( ancestor(hParent,'figure'));
f= figure;
newax = xregGui.HGPlotCopy(ax, f);
pos=get(f,'DefaultAxesPosition');
set(newax,'Units','normalized',...
    'Position',pos,...
    'Color',[1 1 1]);
kids= get(newax,'Children');
set(kids,'HitTest','off');

% ===========================================
% Function i_uxmenu
% ===========================================
function ux=i_uxmenu(hParent)
% MODELDEV/DIAGMENU - Makes contextmenu for the diagnostic plots

% Build the parent context menu
ux=uicontextmenu('Parent',ancestor(hParent, 'figure'),...
    'Tag','prediction context menu');

% set up labels for menus
Labels= {...
    'Sho&w Removed Data',...
    'Show &Transformed Units',...
    'Show Confidence &Intervals',...
    '&Print to Figure',...
    '&Test Number',...
    };

Check= {...
    'on',...
    'off',...
    'on',...
    'off',...
    'off',...
    };

% set up callbacks for menus
Cbks= {...
    {@i_viewoptsflag,hParent},...
    {@i_viewoptsflag,hParent},...
    {@i_viewoptsflag,hParent},...
    {@i_copy,hParent},...
    {@i_viewoptsflag,hParent},...
    };

% set up Tags for menus
Tags= {...
    'showBD1',...
    'ytrans_units',...
    'confidence interval',...
    'Copy Plot',...
    'Test Num',...
    };

% build the context menu
u= xregmenutool('create',...
    ux,...
    'label',Labels,...
    'callback', Cbks,...
    'Tag',Tags,...
    'check',Check);
set([u(4),u(5)],'Separator','on');