24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 458  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 一志愿北京化工大学材料与化工(085600)296求调剂 +23 稻妻小编 2026-03-26 23/1150 2026-03-30 17:49 by oooqiao
[考研] 0703化学321分求调剂 +8 三dd. 2026-03-30 9/450 2026-03-30 17:46 by oooqiao
[考研] 317分 一志愿南理工材料工程 本科湖工大 求调剂 +12 芋泥小铃铛 2026-03-28 12/600 2026-03-30 17:06 by wangjy2002
[考研] 324求调剂 +9 hanamiko 2026-03-26 11/550 2026-03-30 14:27 by JourneyLucky
[考研] 085701求调剂初试286分 +5 secret0328 2026-03-28 5/250 2026-03-30 12:54 by fangnagu
[考研] 311求调剂 +10 lin0039 2026-03-26 10/500 2026-03-30 10:26 by herarysara
[考研] 337求调剂 +6 《树》 2026-03-29 6/300 2026-03-30 10:15 by herarysara
[考研] 295求调剂 +5 wei-5 2026-03-26 5/250 2026-03-30 08:34 by 探123
[考研] 327求调剂 +4 小卡不卡. 2026-03-29 4/200 2026-03-30 06:15 by wxiongid
[考研] 085600 286分 材料求调剂 +10 麻辣鱿鱼 2026-03-27 11/550 2026-03-29 21:52 by nanaliuyun
[考研] 298求调剂 +4 种圣赐 2026-03-28 4/200 2026-03-29 08:42 by q1092522407
[考研] 11408软件工程求调剂 +3 Qiu学ing 2026-03-28 3/150 2026-03-28 21:50 by zhq0425
[考研] 本科新能源科学与工程,一志愿华理能动285求调剂 +7 AZMK 2026-03-28 11/550 2026-03-28 21:01 by xxxsssccc
[考研] 一志愿南京航空航天大学材料学硕求调剂 +3 @taotao 2026-03-28 3/150 2026-03-28 10:26 by JourneyLucky
[考研] 0703化学一志愿南京师范大学303求调剂 +3 zzffylgg 2026-03-24 3/150 2026-03-27 10:42 by shangxh
[考研] 336材料求调剂 +7 陈滢莹 2026-03-26 9/450 2026-03-27 00:20 by wxiongid
[考研] 327求调剂 +7 prayer13 2026-03-23 7/350 2026-03-26 20:48 by 不吃魚的貓
[考研] 07化学303求调剂 +5 睿08 2026-03-25 5/250 2026-03-25 22:46 by 418490947
[考研] 调剂 +4 13853210211 2026-03-24 4/200 2026-03-24 19:44 by ms629
[考研] 085404电子信息284分求调剂 +4 13659058978 2026-03-24 4/200 2026-03-24 12:15 by syl20081243
信息提示
请填处理意见