⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myproxm.m

📁 数据挖掘的工具箱,最新版的,希望对做这方面研究的人有用
💻 M
字号:
%MYPROXM MyProximity mapping% % 	W = MYPROXM(A,TYPE,P,G)% % Computation of the k*m proximity mapping (or kernel) defined by % the m*k dataset A. % The proximities are defined by the following possible TYPEs: % % 	'polynomial'  | 'p':   sign(a*b'+1).*(a*b'+1).^p% 	'exponential' | 'e':   exp(-(||a-b||)/p)% 	'radial_basis'| 'r':   exp(-(||a-b||.^2)/(p*p))% 	'sigmoid'     | 's':   sigm((sign(a*b').*(a*b'))/p)% 	'distance'    | 'd':   ||a-b||.^p% 	'minkowski'   | 'm':   sum(|a-b|^p).^(1/p)% 	'city-block'  | 'c':   sum(|a-b|)% 	'gower'       | 'g':   gower-dissimilarity (see gower.m)% % In the polynomial case and p not integer D is computed by D = % sign(d)*abs(d).^p in order to avoid problems with negative inner % products d. The features of the objects in A may be weighted % by the weights in the vector g (default 1).% % Default is the Euclidean distance: type = 'distance', p = 1% % See also mappings, datasets% Copyright: D.M.J. Tax, R.P.W. Duin, duin@ph.tn.tudelft.nl% Faculty of Applied Physics, Delft University of Technology% P.O. Box 5046, 2600 GA Delft, The Netherlandsfunction W = myproxm(A,type,s,g)		prtrace(mfilename);if nargin < 4, g = []; endif nargin < 3 | isempty(s), s = 1; endif nargin < 2 | isempty(type), type = 'd'; endif nargin < 1 | isempty(A),	W = mapping(mfilename,{type,s,g});	W = setname(W,'MyProximity mapping');	returnend%A = dataset(A); % why do I need this??[m,k] = size(A);  % Definition, just store itif isstr(type)		% Check the inputs, to avoid problems later.	all = char('polynomial','p','exponential','e','radial_basis','r', ...             'sigmoid','s','distance','d','minkowski','m',...             'city-block','c','gower','g');	if ~any(strcmp(cellstr(all),type))		error(['Unknown proximity type: ' type])	end		W.A = A;	W.type = type;	W.s = s;	W.g = g;	if isa(A,'dataset')		W = mapping(mfilename,'trained',W,getlab(A), ...	                                       getfeatsize(A),getobjsize(A));	else		W = mapping(mfilename,'trained',W,[],k,m);	end	W = setname(W,'MyProximity mapping ...');										   elseif isa(type,'mapping')  % Execution, input data A and W.A, output in D (-->W)	W = getdata(type);	[kk,n] = size(type);	if k ~= kk, error('Matrices should have equal numbers of columns'); end		if ~isempty(W.g)		if length(W.g) ~= k, error('Weight vector has wrong length'); end		A = +A.*(ones(m,1)*W.g(:)');		W.A = +W.A.*(ones(n,1)*W.g(:)');	end	switch W.type	case {'polynomial','p'}		D = +(A*W.A'); 		D = D + ones(m,n);		if W.s ~= round(W.s)			D = sign(D).*abs(D).^W.s;		elseif W.s ~= 1			D = D.^W.s;		end		case {'sigmoid','s'}		D = +(A*W.A'); 		D = sigm(D/W.s);			case {'city-block','c'}		D = zeros(m,n);		for j=1:n			D(:,j) = sum(abs(A - repmat(W.A(j,:),m,1)),2);		end			case {'minkowski','m'}		D = zeros(m,n);		for j=1:n			D(:,j) = sum(abs(A - repmat(W.A(j,:),m,1)).^W.s,2).^(1/W.s);		end			case {'exponential','e'}		D = sqeucldistm(+A,+W.A);		D = exp(-sqrt(D)/W.s);			case {'radial_basis','r'}		D = sqeucldistm(+A,+W.A);		D = exp(-D/(W.s*W.s));			case {'distance','d'}		D = sqeucldistm(+A,+W.A);		if W.s ~= 2			D = sqrt(D).^W.s(1);		end		if length(W.s)>1			D = 2./(1+exp(-D./W.s(2))) - 1;		end	case {'gower', 'g'} 		[feattype,featrange] = getfeattype(W.A);		ft2 = getfeattype(A);		if any(feattype~=ft2),			error('Both datasets have to have the same discrete features');		end		D = zeros(m,n);		for j=1:m			D(j,:) = gower(+A(j,:),+W.A,feattype,featrange)';		end			otherwise		error('Unknown proximity type')	end	W = setdat(A,D,type);	else	error('Illegal arguments')endreturn

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -