我正在Coursera上上计算神经科学课程。到目前为止,进展顺利!但是,我有点卡在一个测验问题上。
我上这门课不是为了证书或任何东西。纯粹为了好玩。我已经参加了测验,过了一会儿,我猜到了答案,所以这甚至不会回答测验。
问题的框架如下: 假设我们有一个由 5 个输入节点和 5 个输出节点组成的线性循环网络。假设我们网络的权重矩阵 W 为:
W = [0.6 0.1 0.1 0.1 0.1]
[0.1 0.6 0.1 0.1 0.1]
[0.1 0.1 0.6 0.1 0.1]
[0.1 0.1 0.1 0.6 0.1]
[0.1 0.1 0.1 0.1 0.6]
(基本上都是 0.1,除了对角线上的 0.6。)
假设我们有一个静态输入向量 u:
u = [0.6]
[0.5]
[0.6]
[0.2]
[0.1]
最后,假设我们有一个循环权重矩阵 M:
M = [-0.25, 0, 0.25, 0.25, 0]
[0, -0.25, 0, 0.25, 0.25]
[0.25, 0, -0.25, 0, 0.25]
[0.25, 0.25, 0, -0.25, 0]
[0, 0.25, 0.25, 0, -0.25]
以下哪一项是网络的稳态输出 v_ss?(提示:参见关于循环网络的讲座,并考虑编写一些 Octave 或 Matlab 代码来处理特征向量/值(您可以使用“eig”函数))
课堂笔记可以在这里找到。具体来说,可以在幻灯片 5 和 6 上找到稳态公式的方程。
我有以下代码。
import numpy as np
# Construct W, the network weight matrix
W = np.ones((5,5))
W = W / 10.
np.fill_diagonal(W, 0.6)
# Construct u, the static input vector
u = np.zeros(5)
u[0] = 0.6
u[1] = 0.5
u[2] = 0.6
u[3] = 0.2
u[4] = 0.1
# Connstruct M, the recurrent weight matrix
M = np.zeros((5,5))
np.fill_diagonal(M, -0.25)
for i in range(3):
M[2+i][i] = 0.25
M[i][2+i] = 0.25
for i in range(2):
M[3+i][i] = 0.25
M[i][3+i] = 0.25
# We need to matrix multiply W and u together to get h
# NOTE: cannot use W * u, that's going to do a scalar multiply
# it's element wise otherwise
h = W.dot(u)
print 'This is h'
print h
# Ok then the big deal is:
# h dot e_i
# v_ss = sum_(over all eigens) ------------ e_i
# 1 - lambda_i
eigs = np.linalg.eig(M)
eigenvalues = eigs[0]
eigenvectors = eigs[1]
v_ss = np.zeros(5)
for i in range(5):
v_ss += (np.dot(h,eigenvectors[:, i]))/((1.0-eigenvalues[i])) * eigenvectors[:,i]
print 'This is our steady state v_ss'
print v_ss
正确答案是:
[0.616, 0.540, 0.609, 0.471, 0.430]
这就是我得到的:
This is our steady state v_ss
[ 0.64362264 0.5606784 0.56007018 0.50057043 0.40172501]
任何人都可以发现我的错误吗?太感谢了!我非常感谢它并为长篇博文道歉。本质上,您只需要查看该顶部链接上的幻灯片 5 和 6。