24小时热门版块排行榜    

查看: 477  |  回复: 2

xiaoyaojushi

新虫 (初入文坛)

[求助] matlab求助

请问帮我解释一下这个程序的意思吧,希望能详细解释一下每句的意思!
function [res mi]=forward_sel_class(X,Y,k)
% Forward feature selection using the MI criterion.
% X is a dataset (n x d) with n samples and d features and Y is the class
% vector with classes denoted 1, 2 ... c.
[s1,s2]=size(X);
res = [];
remainingset = [1:size(X,2)];
for j=1:size(X,2)
    j;
currscore=[];
for i=1:length(remainingset)
    tempset = [res remainingset(i)];
    tempscore=miv_opt(X(:,tempset),Y,k);
    currscore(i,=tempscore;
end
    [winnerscore, winner] = max(currscore);
    mi(i)=winnerscore;
    res = [res remainingset(winner)];
    remainingset(winner) = [];
end
function res = miv(X,Y,k)
if(size(Y,1) > size(Y,2))
    Y = Y';
end
warning off
% Estimate mutual information between X ad Y with Y a discrete random variable
% and X a real random vector
% k must be smaller than the minimum number of points in a class.

load digammaMAT;
Y = 1 + Y - min(Y);
[N,d]   = size(X);              % Sample size and dimension
C       = full(ind2vec(Y))';    % Matrix of binary class description
[N, L]  = size(C);              % Sample size and number of classes
cN      = sum(C);               % sample size of each class
for l=1:L, digammacN(l) = digammaMAT(cN(l));end
distmat = pairwisedistances(X,2);
epsilonallclasses = zeros(N,1);
epsilonsameclass = zeros(N,1);
for j = 1:N
    % get vector of all distances
    dist = distmat(j,;
    % sort this vector
    [sorteddistances, distanceindices] = sort(dist);

    % find the distance to the k th neighbour
    epsilonallclasses(j) = 2*sorteddistances(k+1); % the first neighbour is the point itself
    % find the distance to the k th neighbour in the same class
    whichclass = Y(j);
    mask = C(:,whichclass);
    mask = mask(distanceindices);
    sorteddistancesinsameclass = sorteddistances(find(mask));
    epsilonsameclass(j) = 2*sorteddistancesinsameclass(k+1);
end
res = digammaMAT(N) - 1/N * sum(cN.*digammacN)+ d/N * sum((log(epsilonallclasses))-(log(epsilonsameclass)));
res=res/log(2);
% ajout
% if (isnan(res)==1)|(res==-Inf)|(res<0)
%     res=0;
% end
% if j is specified, output is the distance from all points in X to j
% otherwise, output is a full squared distance matrix with all distances
% between all points
function [res] = pairwisedistances(X, pp,j)
[n,p] = size(X);
if nargin < 3
    %outClass = class(X);
    Y = zeros(1,n*(n-1)./2, 'single');
    k = 1;
    for i = 1:n-1
        dsq = zeros(n-i,1,'single');
        for q = 1:p
            dsq = dsq + abs(X(i,q) - X((i+1):n,q)).^pp;
        end
        Y(kk+n-i-1)) = (dsq).^(1/pp);
        k = k + (n-i);
    end
    res = squareform(Y);
else
     res = (sum(abs(X-repmat(X(j,,n,1)).^pp,2)).^(1/pp);
end

[ 来自科研家族 人工智能 ]
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

nono2009

超级版主 (文学泰斗)

No gains, no pains.

优秀区长优秀区长优秀区长优秀区长优秀版主

【答案】应助回帖

感谢参与,应助指数 +1
希望能详细解释一下每句的意思?那估计没有人这么有空。
建议先搞明白这个程序背后的原理,然后再读程序就会比较简单。
2楼2012-05-23 18:00:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

lijie169

铜虫 (著名写手)

【答案】应助回帖

感谢参与,应助指数 +1
貌似是分类基于MI分类的,原理是基于距离
3楼2012-05-24 13:49:43
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 xiaoyaojushi 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] *O_o^ +3 jk31rb6vyz 2026-06-12 3/150 2026-06-14 09:08 by 8bmv3h4hvh
[找工作] *囍 +4 m584r2z4j3 2026-06-12 4/200 2026-06-14 09:06 by 8bmv3h4hvh
[公派出国] T^T +6 q1zg6x4lf3 2026-06-12 6/300 2026-06-14 08:28 by 8bmv3h4hvh
[考研] O(∩_∩)O +4 q1zg6x4lf3 2026-06-12 5/250 2026-06-14 08:23 by 8bmv3h4hvh
[硕博家园] O(∩_∩)O +6 jk31rb6vyz 2026-06-12 8/400 2026-06-14 08:10 by 8bmv3h4hvh
[公派出国] π_π +5 m584r2z4j3 2026-06-11 5/250 2026-06-14 08:08 by 8bmv3h4hvh
[考研] ╭(╯ε╰)╮ +5 m584r2z4j3 2026-06-11 5/250 2026-06-14 08:03 by 8bmv3h4hvh
[找工作] 售SCI文章,我:8.O.5.51O.5.4,科目齐全,可十急 +3 q1zg6x4lf3 2026-06-12 3/150 2026-06-13 19:07 by 1js5n6upxm
[公派出国] +4 q1zg6x4lf3 2026-06-12 4/200 2026-06-13 19:05 by 1js5n6upxm
[考研] T^T +6 m584r2z4j3 2026-06-11 6/300 2026-06-13 18:29 by lkmi35jdzt
[文学芳草园] 咸菜 +3 myrtle 2026-06-10 3/150 2026-06-13 18:29 by ahsoarli
[考博] π_π +4 m584r2z4j3 2026-06-11 4/200 2026-06-13 18:25 by lkmi35jdzt
[考研] o&gt;_&lt;o +5 m584r2z4j3 2026-06-11 5/250 2026-06-13 18:22 by lkmi35jdzt
[考博] T^T +4 jk31rb6vyz 2026-06-12 4/200 2026-06-13 12:09 by 80j16ujcu8
[找工作] 售SCI文章,我:8.O.5.51O.5.4,科目齐全,可十急 +4 q1zg6x4lf3 2026-06-12 4/200 2026-06-13 08:53 by t4hz8376wy
[论文投稿] →_→ +5 m584r2z4j3 2026-06-11 5/250 2026-06-13 08:13 by t4hz8376wy
[基金申请] 面上项目没有好文章就没希望了吗? +19 1234567wang 2026-06-07 21/1050 2026-06-12 21:24 by littlezl
[基金申请] 前几天时间戳更新了 +8 vito刘 2026-06-11 13/650 2026-06-12 14:17 by BlakeReary
[考博] 还有课题组有博士名额吗 +5 冻雨天 2026-06-07 6/300 2026-06-08 20:59 by RCS_tyro
[考博] 博士申请 +3 张城斐 2026-06-07 3/150 2026-06-08 09:15 by A大朋同学
信息提示
请填处理意见