⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 backsel_main.m

📁 Feature Selection using matlab
💻 M
📖 第 1 页 / 共 2 页
字号:
    if NSelectedFeat == 1        ContinueFlag = 0;    end    %------ Curse-of-dim limits For Exclusion ---------------------    if strcmp(MahalInfoLossMethod, 'on')       LowLimitMahalInfLoss(NSteps) =  ...            MahalaInfoLoss(NSelectedFeat, ResultMat(end,2),...                     NPatterns/CClasses, CClasses, ErrorEstMethod);        ResultMat(end, 6) = LowLimitMahalInfLoss(NSteps);    else        LowLimitMahalInfLoss(NSteps) = 0;        ResultMat(end, 6) = LowLimitMahalInfLoss(NSteps);    end    %--------------------------------------------------------------     %------------- Plot Module for Exclusion ----------------------    if ~isempty(handles)        axes(handles.FeatSelCurve);        plot( ResultMat(:,2)      , 'b.-');        hold on        plot( LowLimitMahalInfLoss, 'r.-');                axes(handles.YelLinesAxes);           % Delete lines of          delete(HYelLines(-ResultMat(end,3))); % discarded features        set(findobj(gcf,'Tag','ListSelFeats'), 'String', ...                                                 SelectedFeatPool);    else        plot( ResultMat(:,2)          , 'b.-');        hold on        plot( LowLimitMahalInfLoss, 'r.-');        drawnow        title([DatasetToUse ' ' ErrorEstMethod ' Backward']);    end    drawnow    %----------------End Plot -------------------------------------            %--------------- Report for Exclusion -------------------------    fprintf(1, ['\n\n' StrFeatSelected StrLine '\n']);    for pre_i=1:size(ResultMat,1)        fprintf(1,FormatToPrintExterStep, ResultMat(pre_i,1), ...            ResultMat(pre_i,2), ResultMat(pre_i,3), ...            ResultMat(pre_i,4), ResultMat(pre_i,5),...            ResultMat(pre_i,6));    end    fprintf(1,[StrLine '\n\n\n']);        if ConfMatSwitch == 1        ShowConfMat(ConfMatOpt);    end    %-------------  End Report ------------------------------------                  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    %-------Conditional Inclusion ---    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    % Now keep adding features until the criterion gets worse.    CritvalMaxCurrForw = CritvalMaxCurrBack;    FlagForwSteps = 1;    if NSelectedFeat == KFeatures        ContinueFlag = 0;    end    while (NSelectedFeat<KFeatures - 2) && FlagForwSteps == 1 &&...                       ContinueFlag == 1 && strcmp(FSMethod,'SFBS')        if LogViewOfIntStep == 1                             fprintf(1, [StrInclusionStep StrLine '\n']);        end        for FeatSerialIndx = 1:length(PoolRemainFeat)            % Add one feature to the already selected ones.            CandFeatureToAdd = PoolRemainFeat(FeatSerialIndx);            CandidateFeatSet = [SelectedFeatPool CandFeatureToAdd];            HISTORYtable(end+1,1) = CandFeatureToAdd;            [Critval(FeatSerialIndx), ConfMat, lowCL, upCL] = ...             BayesClassMVGaussPDFs(Patterns(:,CandidateFeatSet),...                   Targets, PercTest, ErrorEstMethod, NRepThres,...                    GammaParam, CritvalMaxCurrBack, ConfMatSwitch);                                 HISTORYtable(end, 2)  =  Critval(FeatSerialIndx);                       % If this feature is the best so far and we have not yet           % selected NFeatToSelect features, store it.            if strcmp(ErrorEstMethod,'ProposedAB')                CritvalThres = CritvalMaxCurrForw + GammaParam;            else                CritvalThres = CritvalMaxCurrForw;            end            if Critval(FeatSerialIndx)  >= CritvalThres                CritvalMaxCurrForw       = Critval(FeatSerialIndx);                FeatSerialIndxCritvalMaxCurr = FeatSerialIndx;                ConfMatOptForw           = ConfMat;                lowCLoptForw             = lowCL;                upCLoptForw              = upCL;                HISTORYtable(end, 4)     = Critval(FeatSerialIndx);            end                       if LogViewOfIntStep == 1              fprintf(1, FormatToPrintInterStep, ...                   HISTORYtable(end,1), HISTORYtable(end,2), ...                          HISTORYtable(end,3), CritvalMaxCurrForw);           end        end    % End internal step of inclusion        % If this subset is better than any found before, store        % and report it. Otherwise, stop removing features.        if strcmp(ErrorEstMethod,'ProposedAB')            CritvalThres = CritvalMaxCurrBack + GammaParam;        else            CritvalThres = CritvalMaxCurrBack;        end        if CritvalMaxCurrForw > CritvalThres            FeatureToInclude         = ...                      PoolRemainFeat(FeatSerialIndxCritvalMaxCurr);            NSelectedFeat            = NSelectedFeat + 1;            CritvalOpt(NSelectedFeat)= CritvalMaxCurrForw ;            ConfMatOpt               = ConfMatOptForw;            lowCLopt                 = lowCLoptForw;            upCLopt                  = upCLoptForw;            PoolRemainFeat(FeatSerialIndxCritvalMaxCurr) = [];            PoolRemainFeat           = sort(PoolRemainFeat);            ResultMat(end+1,1:5)     = [KFeatures-NSelectedFeat ...             CritvalMaxCurrForw FeatureToInclude lowCLopt upCLopt];            NSteps = size(ResultMat,1);            SelectedFeatPool = [SelectedFeatPool FeatureToInclude];            HISTORYtable(end, 4)       = CritvalMaxCurrForw;            CritvalMaxCurrBack         = CritvalMaxCurrForw;            %----- Curse-of-dim limits For Exclusion --------------            if strcmp(MahalInfoLossMethod, 'on')                LowLimitMahalInfLoss(NSteps) =  ...                 MahalaInfoLoss(NSelectedFeat, ResultMat(end,2),...                                    NDc, CClasses, ErrorEstMethod);                               ResultMat(NSteps, 6)= LowLimitMahalInfLoss(NSteps);            end            %------------------------------------------------------                        %--------------- Plot module for inclusion ------------            if ~isempty(handles)                axes(handles.YelLinesAxes);                axis([0 NPatterns 0 KFeatures]); axis manual                hold on                if (NPatterns > KFeatures)                    HYelLines(FeatureToInclude)= ...                        plot([0 NPatterns+2],...                             (FeatureToInclude-0.5)*ones(1,2),'y');                else                    HYelLines(IndexFeature)= ...                         plot((FeatureToInclude-0.5)...                                   *ones(1,2),[0 NPatterns+2],'y');                end                set(gca,'Visible','off');                drawnow                                axes(handles.FeatSelCurve);                plot( ResultMat(:,2),  'b.-');                hold on                if strcmp(MahalInfoLossMethod, 'on')                    plot( LowLimitMahalInfLoss, 'r.-');                end                drawnow                set(findobj(gcf,'Tag','ListSelFeats'),'String',...                                           sort(SelectedFeatPool));                pause(0.1);            end            %------------------------------------------------------        else            FlagForwSteps = 0;   % continue with backward steps        end        %-------------------- Report Log --------------------------        fprintf(1, ['\n\n' StrFeatSelected StrLine '\n']);        for pre_i=1:size(ResultMat,1)            fprintf(1,FormatToPrintExterStep, ResultMat(pre_i,1),...                ResultMat(pre_i,2), ResultMat(pre_i,3),...                ResultMat(pre_i,4), ResultMat(pre_i,5),...                ResultMat(pre_i,6));        end        fprintf(1,[StrLine '\n\n\n\n']);        %----------------------------------------------------------    end % end backwards loop    %----------- Plot Hypergeo Upper Lower Limits -----------------    if 0        plot(   ResultMat(:,4) ,'b.-' )        hold on        plot(   ResultMat(:,5), 'r.-')        drawnow    end    %--------------------------------------------------------------end %====================== END FINAL =============================if ConfMatSwitch == 1    ShowConfMat(ConfMatOpt);end%--------- Find Optimum Feature Set -------------------------------if strcmp(MahalInfoLossMethod, 'on')    [OptimumError, OptimumStepIndx] = max( ResultMat(:,6));else    [OptimumError, OptimumStepIndx] = max( ResultMat(:,4));endOptimumFeatureSet= FindOptFeatSet(InitialSelectedFeatPool,...                                  ResultMat(1:OptimumStepIndx, 3));    %--------- Calculate Execution Time -------------------------------TimeStampEnd =  clock;Tlapse       =  etime(TimeStampEnd, TimeStampStart);                                                            %---------- Plot modulo -------------------------------------------if ~isempty(handles)    axes(handles.YelLinesAxes);    delete(HYelLines(SelectedFeatPool));     axis([0 NPatterns 0 KFeatures]); axis manual    hold on    for IndexFeatures = 1:length(OptimumFeatureSet)    if (NPatterns > KFeatures)        HYelLines(IndexFeatures) = plot([0 NPatterns+2], ...            (OptimumFeatureSet(IndexFeatures)-.5)*ones(1,2),'y');    else        HYelLines(IndexFeatures) = plot(...                        (OptimumFeatureSet(IndexFeatures)-.5)*...                                    ones(1,2),[0 NPatterns+2],'y');    end    set(gca,'Visible','off');    drawnow    end    set(findobj(gcf,'Tag','ListSelFeats'), 'String', ...                                       num2str(OptimumFeatureSet));    axes(handles.FeatSelCurve);enddrawnowhold onplot(OptimumStepIndx*ones(2,1), [0 OptimumError], 'r');xlabel(['Time Lapse: ' num2str(Tlapse) ' secs']);%------------------------------------------------------------------StopByUser = 0;return%------------------------------------------------------------------%--------------- Best Set after Removals --------------------------%------------------------------------------------------------------function OptimumFeatureSet =FindOptFeatSet(OptimumFeatureSet,...                                                     PathOfFeatures)                                       for IndexStep=1:length(PathOfFeatures),    if PathOfFeatures(IndexStep) < 0      OptimumFeatureSet(-PathOfFeatures(IndexStep)) = 0;    elseif PathOfFeatures(IndexStep) > 0      OptimumFeatureSet(PathOfFeatures(IndexStep)) = ...                                         PathOfFeatures(IndexStep);    endendOptimumFeatureSet = OptimumFeatureSet(find(OptimumFeatureSet>0));return%------------------------------------------------------------------%-------------- Mahalanobis Info Loss Limits ----------------------%------------------------------------------------------------------function LowLimitMahalInfLoss = MahalaInfoLoss(D, CCR, NDc, ...                                          CClasses, ErrorEstMethod) %Calculate Info Loss InfoLoss = CalcInfoLoss(D, floor(NDc), ErrorEstMethod);LowLimitMahalInfLoss = CCR - InfoLoss*(CCR-1/CClasses);return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -