24小时热门版块排行榜    

Znn3bq.jpeg
查看: 1904  |  回复: 1

chyzh1986

新虫 (初入文坛)

[求助] 有用过reliefF函数的吗?

有用过这个函数的吗:
function W = reliefF(Dnolabel,Dlabel,Num,k,typeD,Topn)
这里面的参数都代表什么,应该怎么设置呢?要是有个例子就更好了,谢谢~

函数内容如下:

function W = reliefF(Dnolabel,Dlabel,Num,k,typeD,Topn)
%     
%      To achieve attribute ranking using reliefF         
%      Dlabel is the array of the label for each record        
%      The data in Dlabel should be format 1,2,3 and so on         
%      Dnolabel is the array of each record without label            
%      Num is loop time for randomly choose instance            
%      k is the number of nearest hits and miss choosed  
%      Weight is output and it is the ranking of each attribute           
%      typeD is the type of Nolabel data, if it is numerical,   typeD=0;   
%      if it is nominal attributes, typeD=1;
%
[y,x]=size(Dnolabel);
W = zeros(1,Topn);
%calculate the label probability
LabelRange=max(Dlabel)-min(Dlabel)+1;
LabelCount=zeros(1,LabelRange);
LabelP=zeros(1,LabelRange);
for i=1:y
    LabelCount(Dlabel(i))=LabelCount(Dlabel(i))+1;   
end
for j=1:LabelRange
    LabelP(j)=LabelCount(j)/y;
end
LabelP
%*********************************************
DistanceArray=zeros(y-1,2);
%Weight=zeros(1,x);
Weight=zeros(x,2);
Diff=0;      
for i=1:x
    dominoDiff(i) = max(Dnolabel(:,i))- min(Dnolabel(:,i));
end
%for each loop of random choose instance
for NumN=1:Num
    NumN
    %randomly choose a instance
    InstanceId = round([y.*rand(1)]);
    while InstanceId==0,
        InstanceId = round([y.*rand(1)]);
    end
    index = 1;
    %calculate the distance to the choosed instance for each other instance  
    for i=1:y
        if (i~=InstanceId)
            for j=1:x
                DistanceArray(index,1)=DistanceArray(index,1)+...
                    (Dnolabel(i,j)-Dnolabel(InstanceId,j))^2;
            end
            DistanceArray(index,1)=(DistanceArray(index,1)/x)^(0.5);
            DistanceArray(index,2)=i;
            index = index+1;
        end
    end
    %sort distance ascending   
    DistanceArray=sortrows(DistanceArray,1);
   
    Result=zeros(LabelRange,y);
    classSize = zeros(1,LabelRange);
    for i=1:y-1
        class = Dlabel(DistanceArray(i,2));     
        classSize(class) = classSize(class)+1;
        Result(class,classSize(class))=DistanceArray(i,2);
    end
     
    %for each attribute  
    MissW=0; %the initial value for the part relative Miss in the weight
    HitW=0; %the initial value for the part relative Hit in the weight
    for AttributeNum=1:x
        %calculate the difference of min-max value in this attribute
        diff = Weight(AttributeNum,1);
        if (dominoDiff(AttributeNum)<0.0000001)
            Weight(AttributeNum,1)=0;
            Weight(AttributeNum,2)=AttributeNum;
            continue;
        end
        
        %calculate the weight for each attribute              
  for i=1:k %k is the number of nearest neighbours chosen by user        
    idHit = Result(Dlabel(InstanceId),k );
            %for the Hits
            if(round(typeD)==0)
                diff = diff - abs( Dnolabel(idHit, AttributeNum) -...
                    Dnolabel(InstanceId, AttributeNum) )...
                    /dominoDiff(AttributeNum)/k;
            else
                if (round(Dnolabel(InstanceId,AttributeNum))...
                        ==round(Dnolabel(idHit, AttributeNum)))
                    diff=diff-0;
                else
                    diff=diff-1;
                end
            end
        end
        
           
        for c=1:LabelRange
            if (c==Dlabel(InstanceId))
                continue;
            end
            
            P=LabelP(c)/(1-LabelP(Dlabel(InstanceId)));
            for i=1:k
                idMiss = Result(c,i);
                %for the misses   
                if (round(typeD)==0)
                    diff = diff + P*abs( Dnolabel(idMiss, AttributeNum) -...
                        Dnolabel(InstanceId, AttributeNum) )...
                        /dominoDiff(AttributeNum)/k;
                else
                    if (round(Dnolabel(InstanceId,AttributeNum))...
                            ==round(Dnolabel(idHit, AttributeNum)))
                        diff=diff;
                    else
                        diff=diff+1;
                    end
                end  
            end
        end % for m=1:LabelRange
        Weight(AttributeNum,1)=diff;
        Weight(AttributeNum,2)=AttributeNum;
    end %  for AttributeNum=1:x
end % for NumN=1:Num
Weight(AttributeNum,1)=diff/Num;
Weight(AttributeNum,2)=AttributeNum;        
W1 = sortrows(Weight);
for i = 1:Topn
    W(i) = W1(x-i+1,2);
end
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

驹行千里

金虫 (小有名气)

以前听一个师姐汇报过 在人脸识别中 特征选择环节用过 貌似效果不错 不过没有具体了解过
新手上路,从零开始
2楼2013-09-18 10:43:50
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 chyzh1986 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[硕博家园] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 1rx34o113h 2026-05-23 3/150 2026-05-24 17:41 by 0i3mu4vkjz
[基金申请] 评审有感 +16 popular289 2026-05-18 27/1350 2026-05-24 17:34 by hhs666
[考博] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 hvkbtfonbv 2026-05-23 3/150 2026-05-24 17:01 by 75ui6h7z2t
[考研] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 a2tycdlnq1 2026-05-23 5/250 2026-05-24 16:21 by hhx1yx9evi
[论文投稿] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +3 a2tycdlnq1 2026-05-23 4/200 2026-05-24 16:16 by hhx1yx9evi
[基金申请] 河北省自然科学基金 +6 Peterchao 2026-05-18 9/450 2026-05-24 16:02 by 130067131
[硕博家园] 售SCI一区T0P文章,我:8.O.5.5.1.O.5.4,科目齐全,可+急 +4 pmo95bazuy 2026-05-23 8/400 2026-05-24 15:56 by 1uy1ht2y9r
[基金申请] 西安交大新媒学院副院长用撤稿论文结题 +3 bjvtcliu 2026-05-24 5/250 2026-05-24 10:16 by kudofaye
[教师之家] 某211大学教师把个人教师官方主页改成:我跑了我跑了我跑了!官宣跑路! +4 zju2000 2026-05-21 5/250 2026-05-24 09:35 by songwz
[考博] 26/27申博自荐 10+4 ZXW0202 2026-05-22 9/450 2026-05-24 08:47 by bjvtcliu
[基金申请] 青B发送上会通知了吗 +5 chemBioBro 2026-05-22 7/350 2026-05-23 12:35 by zhuifengzhy
[考博] 博士申请 +3 焦晓明 2026-05-21 3/150 2026-05-23 11:26 by mlc840311
[论文投稿] 投稿求助,期刊 +4 希冀,有书读 2026-05-20 8/400 2026-05-22 10:16 by 希冀,有书读
[文学芳草园] 献血感触 +7 呀呀好傻 2026-05-19 13/650 2026-05-21 20:15 by 呀呀好傻
[基金申请] 面上本子正文33页,违规吗?会被低分嘛? +14 1234567wang 2026-05-17 16/800 2026-05-21 17:58 by 脆脆的饼干
[基金申请] 国自然评分 +4 无名者登山 2026-05-20 5/250 2026-05-21 16:35 by swuq
[基金申请] 提交了我也来说说感想 +9 fummck 2026-05-20 10/500 2026-05-21 14:17 by draco1987
[有机交流] 反应很差,大量原料没有反应 5+3 Mr.Zot 2026-05-19 8/400 2026-05-20 22:19 by Equinoxhua
[考博] 博士申请 +5 星…… 2026-05-18 6/300 2026-05-18 23:49 by 糊糊涂涂好
[硕博家园] 我在等一个没有答案的答案 +3 Love_MH 2026-05-17 3/150 2026-05-18 02:22 by 竹林孤影
信息提示
请填处理意见