How can I get Same Results form multiple networks with same network architecture, network options and training and validation data ?

4 views (last 30 days)
Hi everyone
I want to train the best neural network for my data. for this porpose I compared many parameter that affect the network, for example : number of layers. but for constant layer, every time I run the code, resluts (RMSE and ...) are not same. I guess this problem related to randomness of training, such as Shuffle in training option or initializing of weights ans biases. I set Training ans Validation data manually with out any changing and added this commands to my code :
option = trainingOptions('Shuffle','never');
but it didn't give same RMSE. what should I do ?
best regards

Answers (1)

Ayush Aniket
Ayush Aniket on 9 May 2025
Even if you set Shuffle, never in trainingOptions, the results can vary between runs unless you control all sources of randomness. You should ensure to follow all the below steps:
1. Use rng to set the random number generator seed before training. This ensures that weight initialization and any other random operations are repeatable. Refer to the following documentation link to read about the function: https://www.mathworks.com/help/matlab/ref/rng.html
rng(0); % You can use any fixed integer
2. You have already set Shuffle, never in trainingOptions, which prevents data order from changing.
3. Finally, make sure your training and validation datasets are exactly the same for each run.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!