What are all the differences between numpy.random.randand numpy.random.randn?
numpy.random.rand
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.
init
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.
random.rand
weights and biases
What difference between two random functions causes this oddity?
-, , numpy.random.randn , numpy.random.rand unifrom ( [0,1)).
-, ? , , . :
, , 0, , . - , "" - . , , , . - . , ( 1) .
- , . Xavier. :
1) . 0, var = sqrt(2./(in + out)), in - , out - .
var = sqrt(2./(in + out))
2) [-sqrt(6./(in + out)), +sqrt(6./(in + out))]
[-sqrt(6./(in + out)), +sqrt(6./(in + out))]
np.random.rand
[0.0, 1.0)
np.random.randn
:
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()
Source: https://habr.com/ru/post/1689124/More articles:Go id for structure in package? - goОшибка android.system.ErrnoException - javaФункциональное программирование: насколько далеко должна идти неизменность? - immutabilityFastest way to find the number of lines in go? - performancehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1689123/naturally-sort-a-list-moving-alphanumeric-values-to-the-end&usg=ALkJrhgrl3X0fYMh5qsKO70rjymWUVcloAHow to run a consolidation request in the console? - sequelize.jsif recursion is still the worst time complexity - cWhy is this endless for the cycle? - javaRough carousel as a navigation for another - javascriptWhat is the difference between using kubectl and replacing kubectl - kubectlAll Articles