| 3 | 1/1 | 返回列表 |
| 查看: 451 | 回復(fù): 2 | |||
xiaoyaojushi新蟲 (初入文壇)
|
[求助]
matlab求助
|
|
請問幫我解釋一下這個程序的意思吧,希望能詳細(xì)解釋一下每句的意思! 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 [ 來自科研家族 人工智能 ] |
超級版主 (文學(xué)泰斗)
No gains, no pains.
![]() |
專家經(jīng)驗(yàn): +21105 |
| 3 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 一志愿中南化學(xué)337求調(diào)劑 +3 | niko- 2026-03-19 | 4/200 |
|
|---|---|---|---|---|
|
[考研] 招收調(diào)劑碩士 +4 | lidianxing 2026-03-19 | 12/600 |
|
|
[考研] 085700資源與環(huán)境308求調(diào)劑 +10 | 墨墨漠 2026-03-18 | 11/550 |
|
|
[考研] 317求調(diào)劑 +4 | 申子申申 2026-03-19 | 8/400 |
|
|
[考研] 0817 化學(xué)工程 299分求調(diào)劑 有科研經(jīng)歷 有二區(qū)文章 +20 | rare12345 2026-03-18 | 20/1000 |
|
|
[考研] 0703化學(xué)調(diào)劑 +5 | pupcoco 2026-03-17 | 8/400 |
|
|
[考研] 一志愿985,本科211,0817化學(xué)工程與技術(shù)319求調(diào)劑 +10 | Liwangman 2026-03-15 | 10/500 |
|
|
[考研] 0817調(diào)劑 +3 | 沒有答案_ 2026-03-14 | 3/150 |
|
|
[考研] 0703化學(xué)調(diào)劑,求各位老師收留 +10 | 秋有木北 2026-03-14 | 10/500 |
|
|
[考研] 297求調(diào)劑 +8 | 戲精丹丹丹 2026-03-17 | 8/400 |
|
|
[考研] 一志愿西南交大,求調(diào)劑 +4 | 材化逐夢人 2026-03-18 | 4/200 |
|
|
[考研] 312求調(diào)劑 +8 | 陌宸希 2026-03-16 | 9/450 |
|
|
[考研] 301求調(diào)劑 +9 | yy要上岸呀 2026-03-17 | 9/450 |
|
|
[考研] 334求調(diào)劑 +3 | 志存高遠(yuǎn)意在機(jī)?/a> 2026-03-16 | 3/150 |
|
|
[考研] 0854控制工程 359求調(diào)劑 可跨專業(yè) +3 | 626776879 2026-03-14 | 9/450 |
|
|
[考研] 326求調(diào)劑 +3 | mlpqaz03 2026-03-15 | 3/150 |
|
|
[考研] 求老師收留調(diào)劑 +4 | jiang姜66 2026-03-14 | 5/250 |
|
|
[考研] 085601材料工程315分求調(diào)劑 +3 | yang_0104 2026-03-15 | 3/150 |
|
|
[考研] 297一志愿上交085600求調(diào)劑 +5 | 指尖八千里 2026-03-14 | 5/250 |
|
|
[考研] 304求調(diào)劑 +7 | 7712b 2026-03-13 | 7/350 |
|