Differences between numpy.random.rand vs numpy.random.randn in Python

What are all the differences between numpy.random.randand numpy.random.randn?

From the documents, I know that the only difference between them is the probability distribution, from which all numbers are taken, but the general structure (dimension) and the data type used (floating point) are the same. It’s hard for me to debug a neural network because of the belief in this.

In particular, I am trying to reimplement the neural network presented in the book " Neural Network and Deep Learning" by Michael Nielson . The original code can be found here . My implementation was the same as the original one, except that I defined and initialized the weights and offsets with the help numpy.random.randin the function init, and not numpy.random.randnlike in the original.

However, my code, which is used random.randfor initialization weights and biases, does not work, because the network will not learn, and the weights and offsets will not change.

What difference between two random functions causes this oddity?

+28
source share
2 answers

-, , numpy.random.randn , numpy.random.rand unifrom ( [0,1)).

-, ? , , . :

enter image description here

, , 0, , . - , "" - . , , , . - . , ( 1) .

- , . Xavier. :

1) . 0, var = sqrt(2./(in + out)), in - , out - .

2) [-sqrt(6./(in + out)), +sqrt(6./(in + out))]

+46
  • np.random.rand ( [0.0, 1.0))
  • np.random.randn ( ) ( 0 1).

:

import numpy as np
import matplotlib.pyplot as plt

sample_size = 100000
uniform = np.random.rand(sample_size)
normal = np.random.randn(sample_size)

pdf, bins, patches = plt.hist(uniform, bins=20, range=(0, 1), density=True)
plt.title('rand: uniform')
plt.show()

pdf, bins, patches = plt.hist(normal, bins=20, range=(-4, 4), density=True)
plt.title('randn: normal')
plt.show()

:

enter image description here

enter image description here

0

Source: https://habr.com/ru/post/1689124/


All Articles