| 查看: 444 | 回复: 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(k k+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 [ 来自科研家族 人工智能 ] |
» 猜你喜欢
酰胺脱乙酰基
已经有12人回复
售SCI一区文章,我:8 O5 51O 54,科目齐全
已经有3人回复
售SCI一区文章,我:8 O5 51O 54,科目齐全
已经有3人回复
同年申请2项不同项目,第1个项目里不写第2个项目的信息,可以吗
已经有4人回复
有时候真觉得大城市人没有县城人甚至个体户幸福
已经有10人回复
天津大学招2026.09的博士生,欢迎大家推荐交流(博导是本人)
已经有5人回复
有院领导为了换新车,用横向课题经费买了俩车
已经有5人回复
CSC & MSCA 博洛尼亚大学能源材料课题组博士/博士后招生|MSCA经费充足、排名优
已经有6人回复
面上项目申报
已经有3人回复
博士延得我,科研能力直往上蹿
已经有7人回复
nono2009
超级版主 (文学泰斗)
No gains, no pains.
-

专家经验: +21105 - 应助: 28684 (院士)
- 贵宾: 513.911
- 金币: 2555220
- 散金: 27828
- 红花: 2147
- 沙发: 66666
- 帖子: 1602255
- 在线: 65200.9小时
- 虫号: 827383
- 注册: 2009-08-13
- 性别: GG
- 专业: 工程热物理与能源利用
- 管辖: 科研家筹备委员会
2楼2012-05-23 18:00:09
3楼2012-05-24 13:49:43













=tempscore;
k+n-i-1)) = (dsq).^(1/pp);
回复此楼