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

📄 inputnormalize.m

📁 一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有用,谢谢支持
💻 M
字号:
function [data2, mu1, sigma1] = inputNormalize(data, plotOpt, mu, sigma)
% inputNormalize: Input (feature) normalization to have zero mean and unity variance for each feature
%	Usage:
%	[data2, MU1, SIGMA1] = inputNormalize(data, plotOpt, MU, SIGMA)
%		data: Input feature matrix, where each column is a data point
%			and each column being the values for a specific feature.
%		data2: Output feature matrix with zero mean and unity variance for each feature.
%
%	If the function has three inputs, then the normalization is performed
%	using the supplied MU and SIGMA. If the function has only one inputs,
%	MU1 and SIGMA1 are calculated (and returned) based on data.

%	Roger Jang, 20040925

if nargin<1, selfdemo; return; end
if nargin<2, plotOpt=0; end

dim = size(data, 1);
dataNum = size(data, 2);

if nargin<=2
	mu1 = mean(data, 2);
	sigma1 = sqrt(diag(cov(data')));
	data2 = data-mu1*ones(1,dataNum,1);
	data2 = diag(1./sigma1)*data2;
else
	data2 = data-mu(:)*ones(1,dataNum,1);
	data2 = diag(1./sigma)*data2;
end

if plotOpt
	subplot(1,2,1);
	plot(data(1,:), data(2,:), '.'); axis image
	title('Original data');
	subplot(1,2,2);
	plot(data2(1,:), data2(2,:), '.'); axis image
	title('Normalized data');
end

% ====== Self demo
function selfdemo
dataNum=100;
x=8*randn(1, dataNum);
y=randn(1, dataNum)+100;
data=[x; y];
plotOpt=1;
feval(mfilename, data, plotOpt);

⌨️ 快捷键说明

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