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

📄 editdm.m

📁 一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有用,谢谢支持
💻 M
字号:
% Demo of editing technique for data reduction

% Roger Jang, March 1997

use_pause = 1;
% Collect 2500 data points
[xx, yy, zz] = peaks(50);
x = xx(:); y = yy(:); z = zz(:);
axis_limit = [min(x) max(x) min(y) max(y)];
threshold = 0.5;
data_n = length(x);

% Plot these 2500 data points and the contour
%index2 = 1:data_n;
%index1 = find(z > threshold);
%index2(index1) = [];
%h = plot(x(index1), y(index1), 'y.', x(index2), y(index2), 'c.');
%set(h, 'markersize', 10);
%hold on
%[c, contourH] = contour(xx, yy, zz, [threshold threshold]);
%set(contourH, 'linewidth', 2, 'color', 'g');
%hold off
%axis(axis_limit);
%axis square;

% Randomly selected 500 data points
data_n = 500;
tmp = randperm(length(x));
index = tmp(1:data_n);
x = x(index); y = y(index); z = z(index);

index2 = 1:data_n;
index1 = find(z > threshold)';
index2(index1) = [];
figure;
%colordef(gcf, 'black');
% Plot a single contour as the decision boundary
[c, contourH] = contour(xx, yy, zz, [threshold threshold], 'g-');
set(contourH, 'linewidth', 2, 'erase', 'xor');
axis(axis_limit); axis square;
pointH = zeros(data_n,1);
textH = zeros(data_n,1);
for i = 1:data_n,
	pointH(i) = line(x(i), y(i), 'color', 'y', ...
		'erase', 'xor', 'linestyle', '.', 'markersize', 10);
	textH(i) = text(x(i), y(i), num2str(i), 'fontsize', 8, ...
		'erase', 'xor', 'visible', 'off');
end
% Set the color of class-2 points
for i = index2,
	set(pointH(i), 'color', 'c');
end

% Circles to display picked points and it's nearest neighbor
r1 = 0.2;
r2 = 0.2;
theta = linspace(0, 2*pi);
circle_x = cos(theta); 
circle_y = sin(theta); 
circle1H = line(nan, nan, 'color', 'r', 'erase', 'xor');
circle2H = line(nan, nan, 'color', 'w', 'erase', 'xor');
title('Red circle: picked, white circle: nearest');

% All data points
output = z>threshold;
data = [x y output];
% Calcualte distance matrix of all data points
distmat = vecdist([x y]);
% Add a big number to the diagonal elements of the distance matrix
distmat = distmat + diag(realmax*ones(data_n,1));
current_data = 1:data_n;
% Editing the data set
for i = 1:10*data_n,
	fprintf('i = %d\n', i);
	% randomly picked a data point
	picked = randelem(current_data);
	% find the nearest data point to the picked
	[junk, nearest] = min(distmat(picked, :));
	% delete a point if the picked and the nearest are in different classes
	if output(picked) ~= output(nearest),
		% dist1 = min. dist. of picked to same-class data
		ind1 = find(output==output(picked));
		ind1(find(ind1==picked)) = [];
		dist1 = min(distmat(picked, ind1));
		% dist2 = min. dist. of nearest to same-class data
		ind2 = find(output==output(nearest));
		ind2(find(ind2==nearest)) = [];
		dist2 = min(distmat(nearest, ind2));
		if dist1 > dist2,
			to_delete = picked;
		else
			to_delete = nearest;
		end
	%	fprintf('deleting point %d ...\n', to_delete);
		set(circle1H, 'xdata', r1*circle_x+x(picked), ...
			'ydata', r1*circle_y+y(picked));
		set(circle2H, 'xdata', r2*circle_x+x(nearest), ...
			'ydata', r2*circle_y+y(nearest));
		if use_pause, fprintf('Hit any key to go on...\n'); pause; end
		distmat(to_delete, :) = realmax*ones(1, data_n);
		distmat(:, to_delete) = realmax*ones(data_n, 1);
		delete(pointH(to_delete));
		delete(textH(to_delete));
		current_data(find(current_data==to_delete)) = [];
		set(circle1H, 'xdata', nan, 'ydata', nan);
		set(circle2H, 'xdata', nan, 'ydata', nan);
		drawnow
	end
end

⌨️ 快捷键说明

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