Matlab:编辑Latin Hypercube的lhsnorm()函数

时间:2014-03-06 21:38:28

标签: matlab random normal-distribution

我正在尝试编辑lhsnorm函数,以便从常规分布的数据集中获取Latin Hypercube样本。

lhsnorm函数如下:

function [X,z] = lhsnorm(mu,sigma,n,dosmooth)
%LHSNORM Generate a latin hypercube sample with a normal distribution

z1 = mvnrnd(mu,sigma,numel(z));
%%%%%%%%Is it possible for me to change this to a univariate distribution 
% without affecting the rest of the code ?????

% Find the ranks of each column
p = length(mu);
x = zeros(size(z),class(z));
for i=1:p
   x(:,i) = rank(z(:,i));
end

% Get gridded or smoothed-out values on the unit interval
if (nargin<4) || isequal(dosmooth,'on')
   x = x - rand(size(x));
else
   x = x - 0.5;
end
x = x / n;

% Transform each column back to the desired marginal distribution,
% maintaining the ranks (and therefore rank correlations)
for i=1:p
   x(:,i) = norminv(x(:,i),mu(i), sqrt(sigma(i,i)));
end
X = x;

function r=rank(x)

% Similar to tiedrank, but no adjustment for ties here
[sx, rowidx] = sort(x);
r(rowidx) = 1:length(x);
r = r(:);

我正在编辑代码,如下所示:

function [X] = lhsnorm_sid(z,dosmooth)

[muhat,sigmahat] = normfit(z);

z = z';
% Find the ranks of each column
p = length(muhat);
x = zeros(size(z),class(z));
s = size(z);
n = s(1,1);

for i=1:p
   x(:,i) = rank(z(:,i));
end

if (nargin<4) || isequal(dosmooth,'on')
   x = x - rand(size(x));
else
   x = x - 0.5;
end
x = x / n;

for i=1:p
   x(:,i) = norminv(x(:,i),muhat(i), sqrt(sigmahat(i,i)));
end
X = x;

function r=rank(x)

[sx, rowidx] = sort(x);
r(rowidx) = 1:length(x);
r = r(:);

然而,我最终得到的拉丁超立方数值远远超出预期。我也尝试用d(1,:)替换z,其中包含一个正态分布的数据集,但是我获得的拉丁超立方体不包含d(1,:)中的任何值。

由于

0 个答案:

没有答案