lhspoint.m

来自「遗传算法工具包」· M 代码 · 共 26 行

M
26
字号
function x = lhspoint(n,p)
%LHSPOINT Generates latin hypercube points.
%  	X = LHSPOINT(N,P) Generates a latin hypercube sample X containing N
%  	values on each of P variables.  For each column, the N values are
% 	 randomly distributed with one from each interval (0,1/N), (1/N,2/N),
% 	 ..., (N-1/N,1), and they are randomly permuted.

%   Copyright 2004 The MathWorks, Inc.
%   $Revision: 1.7 $  $Date: 2004/01/16 16:52:05 $

x = rand(n,p);
for i=1:p
    x(:,i) = rank(x(:,i));
end
x = x - rand(size(x));
x = x / n;
x = x';
%Safegaurd which should not occur in LHS
x(:,(~any(x))) = [];

%------------RANK function used by lhspoint
function r=rank(x)
[sx, rowidx] = sort(x);
r(rowidx) = 1:length(x);
r = r(:);

⌨️ 快捷键说明

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