matlab program of Latin hypercube sampling method (LHS), including normal distribution, lognormal distribution, etc.

Keywords: MATLAB

For LHS introduction, please refer to: https://blog.csdn.net/Together_CZ/article/details/90076271
The following are four kinds of distribution matlab programs, including normal distribution, uniform distribution, lognormal distribution, extreme type 1.
1. Latin hypercube sampling of normal (Gaussian) distribution variables
Reference resources: https://blog.csdn.net/chichuhe/article/details/89890720#commentsedit
There are also LHS sampling procedures with uniform distribution in the original text.

% Latin hypercube sampling of normal (Gaussian) distribution variables
% The effect is not good. You can run it several times more
clc;clear;close all
%Set mean and variance, sampling points
Mu=[3.6e7;3.6e7]; %mean value
Sigma=[3.6e6,3.6e6]; %variance
N = 30; % Number of sample points
D = size(Mu,1); % dimension
Covariance_Matrix = zeros(D,D);
for i = 1:D
    Covariance_Matrix(i,i) = Sigma(i)^2;
end
 
UB = Mu + 3*Sigma;
LB = Mu - 3*Sigma; % Range of values
 
X = lhsnorm(Mu, Covariance_Matrix, N);
%  X = lhsnorm(Mu, Sigma, N);
figure(1)
plot(X(:,1),X(:,2),'*');grid on
title('Normally distributed LHS sampling')

2. LHS sampling of lognormal distribution

clc;close all; clearvars;
%   Parameter setting of lognormal distribution
    m=20;dist=[3,3];mu=[3.6e7,1.98e8];sigma=[3.6e6,9.9e6];lowb=[mu-3*sigma];upb=[mu+3*sigma];

n=length(mu);
if length(dist)~=n|length(sigma)~=n|length(lowb)~=n|length(upb)~=n
    error('dist,mu,sigma,lowb,upb must have the same length');
end
rvcom=[];
for j=1:n
    rv=[];
if dist(j)==3  %Lognormal distribution
    p_low(j)=logncdf(lowb(j),mu(j),sigma(j));
    p_up(j)=logncdf(upb(j),mu(j),sigma(j));
    p_bound(j)=p_up(j)-p_low(j);
    p_subbound(j)=p_bound(j)./(m-1);
      for i=0:m-1
        rv=[rv;logninv(p_low(j)+i.*p_subbound(j),mu(j),sigma(j))];
      end
elseif dist(j)==4 %for extreme type 1
    p_low(j)=evcdf(lowb(j),mu(j),sigma(j));
    p_up(j)=evcdf(upb(j),mu(j),sigma(j));
    p_bound(j)=p_up(j)-p_low(j);
    p_subbound(j)=p_bound(j)./(m-1);
    for i=0:m-1
       rv=[rv;evinv(p_low(j)+i.*p_subbound(j),mu(j),sigma(j))];
    end
end
rvcom=[rvcom rv];
end
S=[];
for i=1:n
    S=[S randsample(rvcom(:,i),m)];
end
if n==2
  figure
  plot(S(:,1),S(:,2),'r*');grid on
  title('Lognormal distribution LHS sampling')
elseif n==3
  figure
  plot3(S(:,1),S(:,2),S(:,3),'lc.');grid on
end

Changing the distvia variable parameter in the above program to 4 is LHS sampling of extreme type 1 distribution.
Welcome to exchange if you have any questions~

Posted by misslilbit02 on Thu, 31 Oct 2019 12:48:42 -0700