资源简介
SPXY 一个用于化学计量学分析中样本选择的方法源代码完整,可直接使用。
代码片段和文件信息
function [mdminmax] = spxy(XYN)
% Algorithm for Sample set Partitioning based on joint X-Y distances
% [mdminmax] = spxy(XYN);
%
% X --> Matrix of instrumental responses
% Y --> Matrix of parameters
% N --> Number of samples to be selected (minimum of 2)
%
% m --> Indexes of the selected samples
%
% dminmax(1) = 0;
% dminmax(2) = Joint XY distance between the two first samples selected by the algorithm
% dminmax(i) = Smallest joint XY distance between the i-th selected sample and the previously selected ones (i > 2)
%
% Reference:
% R. K. H. Galvao M. C. U. Araujo G. E. Jose M. J. C. Pontes E. C. Silva T. C. B. Saldanha
% A method for calibration and validation subset partitioning
% Talanta vol. 67 pp. 736-740 2005.
%
% Web site: www.ele.ita.br/~kawakami/spa/
dminmax = zeros(1N); % Initializes the vector of minimum distances
M = size(X1); % Number of rows in X (samples)
samples = 1:M;
% Auto-scales the Y matrix
for i=1:size(Y2) % For each parameter in Y
yi = Y(:i);
Y(:i) = (yi - mean(yi))/std(yi);
end
D = zeros(MM); % Initializes the matrix of X distances
Dy = zeros(MM); % Initializes the matrix of Y distances
for i=1:M-1
xa = X(i:);
ya = Y(i:);
for j = i+1:M
xb = X(j:);
yb = Y(j:);
D(ij) = norm(xa - xb);
Dy(ij) = norm(ya - yb);
end
end
Dmax = max(max(D));
Dymax = max(max(Dy));
D = D/Dmax + Dy/Dymax; % Combines the distances in X and Y
% D: Upper Triangular Matrix
% D(ij) = Euclidean distance between objects i and j (j > i)
评论
共有 条评论