rand() gives the same values in each run

1 visualización (últimos 30 días)
Hamza Belm
Hamza Belm el 3 de Ag. de 2020
Comentada: Steven Lord el 4 de Ag. de 2020
Hi
I'm working on the evaluation of metaheuristic algorithms and i need to test each technique in many runs, however the rand() function always generates the same random values in each run, which is not good for the evaluation.
For example, if rand()=0.56 in the 1st run at the 2nd iteration, then rand()=0.56 for all the other runs at the second iteration.
  2 comentarios
Rik
Rik el 3 de Ag. de 2020
Does your code set a random seed anywhere?
Hamza Belm
Hamza Belm el 3 de Ag. de 2020
I didn't use rng anywere in my code, i've just used rand() by default directly.
here is an example
v(u)= w*v(u)+(c1*rand()*(pbest(u)-dcur(u)))+(c2*rand()*(gbest-dcur(u)));
this is the only line where rand() is used

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 3 de Ag. de 2020
Are you initializing the random number generator with rng too frequently or in the wrong place in your code flow?
  2 comentarios
Hamza Belm
Hamza Belm el 3 de Ag. de 2020
I didn't use rng anywere in my code, i've just used rand() by default directly.
here is an example
v(u)= w*v(u)+(c1*rand()*(pbest(u)-dcur(u)))+(c2*rand()*(gbest-dcur(u)));
this is the only line where rand() is used
Steven Lord
Steven Lord el 4 de Ag. de 2020
Show a full (small) segment of code that we can run that demonstrates the behavior you described.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Agriculture en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by