Why is my steady state output different from Coursera's solution?

544 Views Asked by At

I'm taking a Computational Neuroscience class on Coursera and am stuck on one of the quiz problems.

The question is framed as the following:

Suppose that we had a linear recurrent network of 5 input nodes and 5 output nodes. Let us say that our network's weight matrix W is:

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]

(Essentially, all 0.1, besides 0.6 on the diagonals.)

Suppose that we have a static input vector u:

u = [0.6]
    [0.5]
    [0.6]
    [0.2]
    [0.1]

Finally, suppose that we have a recurrent weight matrix 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]

Which of the following is the steady state output v_ss of the network? (Hint: See the lecture on recurrent networks, and consider writing some Octave or Matlab code to handle the eigenvectors/values (you may use the "eig" function))'

The notes for the class can be found here. Specifically, the equation for the steady state formula can be found on slides 5 and 6.

I have the following code:

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

The correct answer is:

[0.616, 0.540, 0.609, 0.471, 0.430]

This is what I am getting:

This is our steady state v_ss
[ 0.64362264  0.5606784   0.56007018  0.50057043  0.40172501]

Why is my output different, and how can I fix it?

1

There are 1 best solutions below

1
On

I tried your solution with my matrices:

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]])

and your code generated the right solution:

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]

Maybe the problem is with the Test on coursera. Have you tried to contact them on the forum?