0

My question is why when I train the same algorithm twice, it gives different results each time I train it? Is it normal or there might be a problem in data or code?

The algorithm is deep deterministic policy gradient.

Anubhav Singh
  • 8,321
  • 4
  • 25
  • 43
J. Ali
  • 33
  • 1
  • 5
  • You need to give more details in your question, including code snippets and data examples. see the guide on how to make an [MCVE](https://stackoverflow.com/help/minimal-reproducible-example) – nickyfot Jun 25 '19 at 11:33
  • Generally speaking, most models, balancing methods etc have a random seed you can set to a fixed value to get reproducible results – nickyfot Jun 25 '19 at 11:34

2 Answers2

4

It's absolutely normal. There is no problem with either data or code.

The algorithm may be initialized to a random state, such as the initial weights in an artificial neural network. Try setting numpy seed for result reproducibility as below:

import numpy as np
np.random.seed(42)

Learn more about this from here.

Anubhav Singh
  • 8,321
  • 4
  • 25
  • 43
  • thank you so much for your response. i have `w_init=tf.random_uniform_initializer(-0.003,0.003)` . Shall i replace it with `np.random.seed(42)` – J. Ali Jun 25 '19 at 14:53
  • check this as well: https://stackoverflow.com/questions/32419510/how-to-get-reproducible-results-in-keras – Anubhav Singh Jun 25 '19 at 15:22
2

When you initialize weights to your model, they are often initialized randomly by whatever you use, most likely np.random.rand(), and therefore yields different results every time.

If you do not want to randomize weights, use np.random.seed(10) to always get the same results. If using any other library, I'm sure there are equal commands.

Edit: i saw you used tensorflow, in that case:

tf.random.set_random_seed(10)
Gabriel Petersson
  • 8,434
  • 4
  • 32
  • 41
  • thank you so much for your response. i have `w_init=tf.random_uniform_initializer(-0.003,0.003)` . Shall i replace it with `tf.random.set_random_seed(10)` – J. Ali Jun 25 '19 at 14:53