Difference between rng('shuffle') and NO rng for estimating with MLE

18 views (last 30 days)
I am trying to estimate a 3-parameter weibul distribution with random numbers. But I dont understand the difference between rng('shuffle') and NO rng('shuffle'), I mean deleting the line. Both lines estimates random numbers in my code. Can someone tell me the difference?
And if you can give me any advice for my code for estimating a 3-parameter weibul estimation, I would appreciate that.
clear all
n = 1000;
t0 = 0.5;
b_A = 1:5;
T_A = 1:5;
LowerBound= [0 0 0];
rng('shuffle');
data = zeros(n,length(b_A),length(T_A));
params = zeros(length(b_A),length(T_A));
data2P = zeros(n,length(b_A),length(T_A));
params2p = zeros(length(b_A),4,length(T_A));
for k= T_A
for i= b_A
data(:,i,k) = wblrnd(i,k, [n,1]) + t0;
data2P(:,i,k) = wblrnd(b_A(i),T_A(k), [n,1]);
start = [i k t0];
custompdf = @(x,a,b,c) (x>c).*(b/a).*(((x-c)/a).^(b-1)).*exp(-((x-c)/a).^b);
opt = statset('MaxIter',1e5,'MaxFunEvals',1e5,'FunValCheck','off');
params(i,1:3,k) = mle(data(:,i,k),'pdf',custompdf,'start',start,'Options',opt,'LowerBound',LowerBound,'UpperBound',[Inf Inf min(data(:,i,k))])
params(i,4,k) = i;
params(i,5,k) = k;
params(i,6,k) = t0;
params2p(i,1:2,k) = wblfit(data2P(:,i,k));
params2p(i,3,k) = i;
params2p(i,4,k) = k;
end
end
  1 Comment
Rik
Rik on 7 Dec 2020
Please do not delete your question. If you feel this is a beginner question: there are many beginners, so be nice to them. They might come across your question and learn from it.
I made a capture so people can revert your edit if you attempt to vandalize your question.

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 21 Jun 2020
If you start a fresh instance of MATLAB, and generate a sequence of pseudorandom numbers, it will always be the same sequence. (Try it!)
If you do not use the
rng('shuffle')
then you will get the numbers from that sequence. If you do use it, then instead of traveling along that predetermined sequence of numbers, you will leap to a different point on that sequence, based on the time when you make the call to the function.
  8 Comments
the cyclist
the cyclist on 21 Jun 2020
Sorry, I did not mean to make you feel bad.
In the Input Arguments section of the rng documentation, it explains that 'shuffle" ...
--------
"Initializes generator based on the current time, resulting in a different sequence of random numbers after each call to rng."
--------

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!