24小时热门版块排行榜    

Znn3bq.jpeg
查看: 462  |  回复: 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的回帖

lijie169

铜虫 (著名写手)

【答案】应助回帖

感谢参与,应助指数 +1
貌似是分类基于MI分类的,原理是基于距离
3楼2012-05-24 13:49:43
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 3 个回答

nono2009

超级版主 (文学泰斗)

No gains, no pains.

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

【答案】应助回帖

感谢参与,应助指数 +1
希望能详细解释一下每句的意思?那估计没有人这么有空。
建议先搞明白这个程序背后的原理,然后再读程序就会比较简单。
2楼2012-05-23 18:00:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 322求调剂,08工科 +4 今天是个小号 2026-04-08 4/200 2026-04-13 00:20 by baobaoye
[考研] 调剂求收留 +29 果然有我 2026-04-10 30/1500 2026-04-12 22:14 by zxcwyt
[考研] 310求调剂 +13 666真好 2026-04-11 14/700 2026-04-12 16:48 by 1005715100
[考研] 308求调剂 +5 VvvvL 2026-04-10 5/250 2026-04-12 10:17 by babysonlkd
[考研] 一志愿厦大0856,306求调剂 +15 Bblinging 2026-04-11 15/750 2026-04-11 22:53 by 314126402
[考研] 284求调剂 +11 archer.. 2026-04-09 12/600 2026-04-11 20:23 by 蓝云思雨
[考研] 085400 328分 求调剂 +10 喂你一个大橙子 2026-04-09 14/700 2026-04-11 19:53 by lqspecial
[考研] 293求调剂 +6 勇远库爱314 2026-04-08 6/300 2026-04-11 10:08 by zhq0425
[考研] 368求调剂 +3 17385968172 2026-04-10 3/150 2026-04-10 20:12 by 电子奥德彪
[考研] 282,电气工程专业,求调剂,不挑专业 +9 jggshjkkm 2026-04-10 9/450 2026-04-10 14:55 by 逆水乘风
[考研] 调剂 +19 2261744733 2026-04-08 19/950 2026-04-09 19:11 by vgtyfty
[考研] 求调剂材料科学与工程一志愿985初试365分 +5 材化李可 2026-04-08 5/250 2026-04-09 17:00 by Lilly_Li
[考研] 复试调剂,一志愿郑州大学材料与化工289分 +31 硕星赴 2026-04-08 31/1550 2026-04-09 16:54 by Delta2012
[考研] 311求调剂 +6 surte 2026-04-08 13/650 2026-04-09 14:00 by surte
[考研] 化工学硕 285求调剂 +26 Wisjxn 2026-04-07 26/1300 2026-04-08 14:42 by screening
[考研] 277求调剂 +4 考研调剂lxh 2026-04-06 6/300 2026-04-08 10:40 by 逆水乘风
[考研] 313求调剂 +3 十六拾陆 2026-04-07 3/150 2026-04-07 23:20 by lbsjt
[考研] 22408 调剂材料 +7 我叫ez 2026-04-06 8/400 2026-04-07 17:12 by 蓝云思雨
[考研] 材料调剂 +11 一样YWY 2026-04-07 11/550 2026-04-07 15:13 by shdgaomin
[考研] 287分求调剂 有专利国奖一志愿哈工大085406 +6 白易辰 2026-04-06 7/350 2026-04-06 22:46 by 875465
信息提示
请填处理意见