0

I want to generate lognormally distributed random samples using the quasi monte carlo method such as Halton sequence. I want the numbers within a certain bounds. I have the following code in matlab but it gives me numbers which are out of bounds how can I limit to produce samples within the bounds.

M=1;   
bounds=[2 4];
Ns=20; % number of models 
urnd = haltonset(M,'Skip',1e3,'Leap',1e2);
urnd = scramble(urnd,'RR2');
urnd = qrandstream(urnd);
modelCDF = qrand(urnd,Ns);
models = zeros(Ns,M);
models=logninv(modelCDF,0,3);
Sagar Masuti
  • 1,271
  • 2
  • 11
  • 30

1 Answers1

1

You do not use the bounds in your attempt. You have to squeeze your samples (modelCDF) between the bounds, this can be done by scaling and shifting the [0,1] uniformly distributed sample.

M=1;   
bounds=[2 4];
Ns=1e3; % number of models 

% calculate the probabilities corresponding to the bounds
P_bounds = logncdf(bounds,0,3);

urnd = haltonset(M,'Skip',1e3,'Leap',1e2);
urnd = scramble(urnd,'RR2');
urnd = qrandstream(urnd);
modelCDF = qrand(urnd,Ns);

% scale and shift to cover P_bounds
modelCDF = P_bounds(1) + modelCDF*diff(P_bounds);

% models = zeros(Ns,M); % no need for this
models=logninv(modelCDF,0,3);

% Plot them for visual comparison
[f,c] = hist(models, 30);
f = f./trapz(c,f)*diff(P_bounds); % normalize for comparison with analytical pdf

bar(c, f)
hold on
x = linspace(bounds(1),bounds(2),1e2);
y = lognpdf(x,0,3);
plot(x,y, 'r', 'LineWidth', 2)

enter image description here

rozsasarpi
  • 1,621
  • 20
  • 34