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

📄 forwsel_main.m

📁 Feature Selection using matlab
💻 M
📖 第 1 页 / 共 2 页
字号:
            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        set(findobj(gcf,'Tag','ListSelFeats'), 'String', ...            sort(SelectedFeatPool));        axes(handles.FeatSelCurve);    end    HCCRCurve(1) = plot( ResultMat(:,2)          , 'b.-');    legend(HCCRCurve(1), 'CCR');      hold on    if strcmp(MahalInfoLossMethod , 'on')        HCCRCurve(2) = plot( LowLimitMahalInfLoss, 'r.-');        legend(HCCRCurve, 'CCR', 'Lower Limit of CCR',...                                                'Location','Best');    end    title([DatasetToUse ' ' ErrorEstMethod ' ' FSMethod]);    drawnow    %--------------------------------------------------------------           %--------------- Report ---------------------------------------    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 Exclusion ---    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    % Now keep removing features until the criterion gets worse.    CritvalMaxCurrBack = CritvalMaxCurrForw;    FlagBackwSteps=1;    if NSelectedFeat == KFeatures        ContinueFlag = 0;    end    while (NSelectedFeat > 2) && FlagBackwSteps == 1 && ...                       ContinueFlag == 1 && strcmp(FSMethod,'SFFS')                if LogViewOfIntStep == 1                             fprintf(1, [StrExclusionStep StrLine '\n']);        end                for FeatSerialIndx = 1:NSelectedFeat            CandidateFeatSet = SelectedFeatPool;            % Remove one feature from the selected ones.            CandidateFeatSet(FeatSerialIndx) = [];            HISTORYtable(end+1,1) =...                -SelectedFeatPool(FeatSerialIndx);            [Critval(FeatSerialIndx),  ConfMat, lowCL, upCL] = ...             BayesClassMVGaussPDFs(Patterns(:,CandidateFeatSet),...                   Targets, PercTest, ErrorEstMethod, NRepThres,...                    GammaParam, CritvalMaxCurrBack, ConfMatSwitch);                                 HISTORYtable(end, 2)  =  Critval(FeatSerialIndx);            % If removing this feature gives the best result so far            % (or the same result using less features), and we have            % not yet removed all NFeatToSelect features, store it.            if strcmp(ErrorEstMethod,'ProposedAB')                CritvalThres = CritvalMaxCurrBack + GammaParam;            else                CritvalThres = CritvalMaxCurrBack;            end            if Critval(FeatSerialIndx) > CritvalThres                CritvalMaxCurrBack       = Critval(FeatSerialIndx);                FeatSerialIndxCritvalMaxCurr = FeatSerialIndx;                ConfMatOptBack           = ConfMat;                lowCLoptBack             = lowCL;                upCLoptBack              = upCL;                HISTORYtable(end, 4)     = Critval(FeatSerialIndx);            end                       if LogViewOfIntStep == 1              fprintf(1, FormatToPrintInterStep, ...                   HISTORYtable(end,1), HISTORYtable(end,2), ...                          HISTORYtable(end,3), CritvalMaxCurrBack);           end        end    % end checking all selected features        % If this subset is better than any found before, store        % and report it. Otherwise, stop removing features.        if strcmp(ErrorEstMethod,'ProposedAB')            CritvalThres = CritvalMaxCurrForw + GammaParam;        else            CritvalThres = CritvalMaxCurrForw;        end        if CritvalMaxCurrBack > CritvalThres            FeatureToExclude         = ...                    SelectedFeatPool(FeatSerialIndxCritvalMaxCurr);            NSelectedFeat            = NSelectedFeat - 1;            CritvalOpt(NSelectedFeat)= CritvalMaxCurrBack ;            ConfMatOpt               = ConfMatOptBack;            lowCLopt                 = lowCLoptBack;            upCLopt                  = upCLoptBack;            PoolRemainFeat      =[PoolRemainFeat FeatureToExclude];            PoolRemainFeat           = sort(PoolRemainFeat);            ResultMat(end+1,1:5)     = [NSelectedFeat ...                                         CritvalMaxCurrBack ...                               -FeatureToExclude lowCLopt upCLopt];            NSteps = size(ResultMat,1);            SelectedFeatPool(FeatSerialIndxCritvalMaxCurr ) = [];            HISTORYtable(end, 4)       = CritvalMaxCurrBack;            CritvalMaxCurrForw         = CritvalMaxCurrBack;            %----- 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 exclusion ------------            if ~isempty(handles)                delete(HYelLines(FeatureToExclude));                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            FlagBackwSteps = 0;   % continue with forward 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')    [OptimumCCR, OptimumStepIndx] = max( ResultMat(:,6));else    [OptimumCCR, OptimumStepIndx] = max( ResultMat(:,4));endOptimumFeatureSet= FindOptFeatSet(ResultMat(1:OptimumStepIndx, 3));    OptimumFeatureSet= sort(OptimumFeatureSet);%--------- Calculate Execution Time -------------------------------TimeStampEnd =  clock;Tlapse       =  etime(TimeStampEnd, TimeStampStart);%----------- Plot module ------------------------------------------LinesToDeleteFeatInd = setxor(SelectedFeatPool, OptimumFeatureSet);if ~isempty(handles)    delete( HYelLines(LinesToDeleteFeatInd));    set(findobj(gcf,'Tag','ListSelFeats'), 'String', ...        OptimumFeatureSet);    axes(handles.FeatSelCurve);endhold onplot(OptimumStepIndx*ones(2,1), [0 OptimumCCR], 'r');title(['Optimum FeatSet: ' num2str(OptimumFeatureSet')]);xlabel(['Time Lapse: ' num2str(Tlapse) ' secs']);StopByUser = 0;return%------------------------------------------------------------------%--------------- Best Set after Removals --------------------------%------------------------------------------------------------------function OptimumFeatureSet = FindOptFeatSet(PathOfFeaturesSelected)OptimumFeatureSet=PathOfFeaturesSelected;for IndexStep=1:length(OptimumFeatureSet),    if OptimumFeatureSet(IndexStep)<0,        remov = OptimumFeatureSet(1:IndexStep) ...                                 == -OptimumFeatureSet(IndexStep);        OptimumFeatureSet(remov==1) =0;        OptimumFeatureSet(IndexStep)=0;    endendOptimumFeatureSet = OptimumFeatureSet( 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 + -