www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/+local/PredObsPlot.m

    classdef PredObsPlot < mbcmodelview.SpecialPlots
    %PredObsPlot special plot for predicted versus observed
    
    %  Copyright 2015-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (Constant)
        %ViewInfo creation arguments for multiview
        ViewInfo= {  @(varargin) mbcmodelview.local.PredObsPlot('PlotType','Sweep Plot',varargin{:});
            'S&weep Plot';
            xregrespath('sweepplot.bmp');
            'Sweep plot';
            1};
        PtbyPtInfo=  {  @(varargin) mbcmodelview.local.PredObsPlot('PlotType','Predicted/Observed',varargin{:});
            '&Predicted/Observed';
            xregrespath('predictedobserved.bmp');
            'Predicted/Observed';
            1};       
        
    end         
    
    
    properties (SetAccess=protected)
        %ShowRemoved show removed data on plot
        ShowRemoved = true;
        %ShowTransformed show transformed responses
        ShowTransformed = false;
        %ShowConfidenceIntervals show confidence intervals in plot
        ShowConfidenceIntervals = true;
    end
    
    methods
        function obj = PredObsPlot(varargin)
        obj@mbcmodelview.SpecialPlots(varargin{:});
        end
        
        function s = serializeView(obj) 
        %SERIALIZEVIEW Get serializable setup data for the view
        %
        %  OUT = SERIALIZEVIEW(OBJ) retuns a MATLAB array that contains the setup
        %  data that will allow this view to be recreated via the deserializeView
        %  function in the future.  Typically this function will return a cell
        %  array of property names and values, however any MATLAB array type is
        %  allowed.
        
        s.ShowRemoved = obj.ShowRemoved;
        s.ShowTransformed = obj.ShowTransformed;
        s.ShowConfidenceIntervals = obj.ShowConfidenceIntervals;    
        s.ShowLegend = obj.ShowLegend;    
        
        end
        
        function deserializeView(obj,s)
        %DESERIALIZEVIEW Set saved state data
        %  DESERIALIZEVIEW(OBJ, DATA) sets a copy of the serialized state of this
        %  View.  DATA is a MATLAB array that will have been created by a
        %  previous call to SERIALIZEVIEW on this View object.
        
        obj.ShowRemoved = s.ShowRemoved;
        obj.ShowTransformed = s.ShowTransformed;        
        obj.ShowConfidenceIntervals = s.ShowConfidenceIntervals;    
        obj.ShowLegend = s.ShowLegend;    
        
        end           
        
    end
    
    methods (Access=protected)
        function createActions(obj)
        %createActions extra actions for predicted/observed 
            
        createActions@mbcmodelview.SpecialPlots(obj);
        
        AG = mbcgui.actions.ActionGroup('','&Sweep plot');
        AG.MenuType = 'separate';
        AG.Actions = [mbcgui.actions.ToggleAction(@obj.onShowRemovedData,'Show &Removed Data')
            mbcgui.actions.ToggleAction(@obj.onShowTransformed,'Show &Transformed Data')
            mbcgui.actions.ToggleAction(@obj.onShowConfidenceIntervals,'Show &Confidence Intervals')];
        set(AG.Actions(:),{'Selected'},{obj.ShowRemoved,obj.ShowTransformed,obj.ShowConfidenceIntervals}')
        
        obj.Actions = [AG;obj.Actions(:)];
        
        end
        
        function plot(obj)
        %plot main plot routine
        
        ms = obj.MessageService;
        AxHand = obj.Axes;
        
        ATrans = obj.Actions(1).Actions(2);
        if isempty(get(ms.Model,'ytrans'))
            % disable ShowTransformed
            obj.ShowTransformed = false;
            ATrans.Enabled = false;
            ATrans.Selected = false;
        else
            ATrans.Enabled = true;
        end
        Aci = obj.Actions(1).Actions(3);
        if pevcheck(ms.Model)
            Aci.Enabled = true;
        else
            obj.ShowConfidenceIntervals = false;
            Aci.Enabled = false;
            Aci.Selected = false;
        end
        
        
        PlotOpts = [obj.ShowRemoved,obj.ShowTransformed,obj.ShowConfidenceIntervals,0,0];
        
        % twostage model
        TS= BestModel(ms.ModelDev);
        
        PlotOpts(4)=1;
        if ~isempty(TS) && ~ms.NeedsUpdate
            % two-stage plot
            
            % Global Dependents
            Xs= ms.XData;    % Local Input Data
            XG= ms.GlobalXData;        % Global Input Data
            Ys= ms.YData;
            
            Cord= get(AxHand,'ColorOrder');
            if mle_best(ms.ModelDev) % plot the purple MLE line
                set(AxHand,'ColorOrder',[0.5 0 0.5]);
            else
                set(AxHand,'ColorOrder',[0 0.5 0]);
            end
            % plot the twostage line(s)
            hLines= plot(TS,{Xs,XG},Ys,PlotOpts,AxHand);
            mbcgui.hgclassesutil.setNotPickable(hLines)
            
            set(AxHand,'ColorOrder',Cord);
        end
        
        State= get(AxHand,'NextPlot');
        set(AxHand,'NextPlot','add')
        
        if ms.Status
            % plot the local fit and the data points
            h= plot(ms.Model,ms.XData,ms.YData,ms.DataOK,PlotOpts,AxHand);
            set(h,'Tag','main line');
            
            if ~isempty(ms.ValidationXData)
                % add validation data for sweep
                Vyhat = ms.Model(ms.ValidationXData);
                if nfactors(ms.Model)==1
                    % validation points for 1D plot (Y vs X)
                    hVal = plot(AxHand,double(ms.ValidationXData),Vyhat,'^',...
                        'Color','k',...
                        'MarkerFaceColor',[50, 200, 50]/255,...
                        'MarkerSize',5,...
                        'Tag','valdata');
                else
                    % validation points for 2+D plot (Y vs Yhat)
                    hVal = plot(AxHand,double(ms.ValidationYData),Vyhat,'^',...
                        'Color','k',...
                        'MarkerFaceColor',[50, 200, 50]/255,...
                        'MarkerSize',5,...
                        'Tag','valdata');
                end
                mbcgui.hgclassesutil.setNotPickable(hVal)
            end
        end
        
        set(AxHand,'NextPlot',State)
        end
        
    end
    
    methods (Access=private)
        function onShowRemovedData(obj,h,~)
        obj.ShowRemoved = h.Selected;
        update(obj)
        end
        
        function onShowTransformed(obj,h,~)
        obj.ShowTransformed = h.Selected;
        update(obj)
        end
        
        function onShowConfidenceIntervals(obj,h,~)
        obj.ShowConfidenceIntervals = h.Selected;
        update(obj)
        end
        
    end
        
    
end