MATLAB Answers

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

3 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];
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;


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
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.


Show 5 older comments
Mustafa Vural
Mustafa Vural on 21 Jun 2020
I really read your links. But I didnt get it. My english is also not the best, so thats why I dont understand that much, I am sry. I am a student in Germany and need that for my university.
I am really sorry when you tell me the same thing twice. I understand now what you explaining.
My last question is now, you tell that shuffle depends on the clock time? How is " rng('shuffle') " in relation with the clock time?
Sorry I feel very stupid.
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!