2017-01-05 48 views
1

我在参加Coursera的计算神经科学课。到目前为止,它一直很棒!但是,我遇到了一个测验问题。寻找线性复发网络的稳态输出

我没有参加这个课程的证书或任何东西。纯粹是为了好玩。我已经参加了测验,过了一段时间,我猜对了答案,所以这甚至不会回答测验。

问题的框架如下: 假设我们有一个包含5个输入节点和5个输出节点的线性递归网络。让我们说,我们的网络的权重矩阵W是:(。从本质上讲,所有0.1,除了0​​.6对角线上)

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] 

假设我们有一个静态的输入向量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? (提示:见复发网络讲座,并考虑写一些八度或Matlab代码来处理特征向量/值(您可以使用“EIG”功能))”

该类可将笔记发现here。具体而言,可以在幻灯片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。

回答

1

我tryied我的矩阵解决方案:

W = np.array([[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]]) 
u = np.array([.6, .5, .6, .2, .1]) 

M = np.array([[-0.75 , 0 , 0.75 , 0.75 , 0], 
       [0 , -0.75 , 0 , 0.75 , 0.75], 
       [0.75 , 0 , -0.75 , 0 , 0.75], 
       [0.75 , 0.75 , 0.0 , -0.75 , 0], 
       [0 , 0.75 , 0.75 , 0 , -0.75]]) 

和代码生成正确的解决方案:

This is h 
[ 0.5 0.45 0.5 0.3 0.25] 
This is our steady state v_ss 
[ 1.663354 1.5762684 1.66344153 1.56488258 1.53205348] 

也许问题是与coursera测试。你有没有试过在论坛上联系他们?

+0

我不知道该联系谁。你有信心在我的程序中正确回答这个问题吗?我怀疑Coursera会为一群人提出错误的解决方案。我觉得我的代码必须有错误,或者我必须在逻辑中存在缺陷。 – jlarks32