Skip to main content
 首页 » 编程设计

python之np.random.seed(1) 和 np.random.seed(0) 之间的区别

2024年10月01日8thcjp

我正在寻找网络。我发现这个话题https://iamtrask.github.io/2015/07/12/basic-python-network/

一切顺利,但我无法理解那部分:

# seed random numbers to make calculation 
# deterministic (just a good practice) 
 
np.random.seed(1) 
 
# initialize weights randomly with mean 0 
syn0 = 2 * np.random.random((3, 1)) - 1 

那么 np.random.seed(1) 是什么意思?为什么不是(0)? (1)) 的意思是什么 页面作者说“用均值 0 随机初始化权重”

syn0 = 2 * np.random.random((3, 1)) - 1 

ann 权重是什么意思?

请您参考如下方法:

问题 #1:

出于实际目的,没有区别,这只是每次运行程序时获得相同随机数的一种方法。欢迎阅读维基百科的更多详细信息:https://en.wikipedia.org/wiki/Random_seed

问题 #2:

使用零均值权重初始化 ANN 是一种很好的做法,通常会显示出良好的收敛行为。查看此页面了解更多详情:http://cs231n.github.io/neural-networks-2/#init

Therefore, we still want the weights to be very close to zero, but as we have argued above, not identically zero. As a solution, it is common to initialize the weights of the neurons to small numbers and refer to doing so as symmetry breaking. The idea is that the neurons are all random and unique in the beginning, so they will compute distinct updates and integrate themselves as diverse parts of the full network.

Quora 线程中有更多关于该主题的讨论:https://www.quora.com/Why-does-it-work-to-initialize-weights-of-a-deep-Neural-Network-to-zero-plus-some-noise-N-0-epsilon-and-not-anything-else