def get_matrices(): dv = .001 nsyn_bg = 1 bgfr = 200 we = .1 wi = -.1 nsyn_00, nsyn_01, nsyn_10, nsyn_11 = 5, 5, 2, 20 # Components: b0 = ExternalPopulation(bgfr, record=True) i0 = InternalPopulation(tau_m=.05, v_min=0, v_max=1, dv=dv, update_method='gmres') i1 = InternalPopulation(tau_m=.05, v_min=0, v_max=1, dv=dv, update_method='gmres') b0_i0 = Connection(b0, i0, nsyn_bg, weights=we, delays=0.0) b0_i1 = Connection(b0, i1, nsyn_bg, weights=we, delays=0.0) i0_i0 = Connection(i0, i0, nsyn_00, weights=we, delays=0.0) i0_i1 = Connection(i0, i1, nsyn_01, weights=we, delays=0.0) i1_i0 = Connection(i1, i0, nsyn_10, weights=wi, delays=0.0) i1_i1 = Connection(i1, i1, nsyn_11, weights=wi, delays=0.0) L = get_leak_matrix(i1) Se, te = get_connection_flux_matrices(b0_i0) Si, _ = get_connection_flux_matrices(i1_i0) return L, Se, Si, te
def get_matrices(): dv = .001 nsyn_bg = 1 bgfr = 200 we = .1 wi = -.1 nsyn_00, nsyn_01, nsyn_10, nsyn_11 = 5, 5, 2, 20 # Components: b0 = ExternalPopulation(bgfr, record=True) i0 = InternalPopulation(tau_m=.05, v_min=0, v_max=1, dv=dv, update_method = 'gmres') i1 = InternalPopulation(tau_m=.05, v_min=0, v_max=1, dv=dv, update_method = 'gmres') b0_i0 = Connection(b0, i0, nsyn_bg, weights=we, delays=0.0) b0_i1 = Connection(b0, i1, nsyn_bg, weights=we, delays=0.0) i0_i0 = Connection(i0, i0, nsyn_00, weights=we, delays=0.0) i0_i1 = Connection(i0, i1, nsyn_01, weights=we, delays=0.0) i1_i0 = Connection(i1, i0, nsyn_10, weights=wi, delays=0.0) i1_i1 = Connection(i1, i1, nsyn_11, weights=wi, delays=0.0) L = get_leak_matrix(i1) Se, te = get_connection_flux_matrices(b0_i0) Si, _ = get_connection_flux_matrices(i1_i0) return L, Se, Si, te
def test_access_matrices(): i1 = InternalPopulation(v_min=0, v_max=.02, dv=.0001) c1 = Connection(None, i1, 1, weights=.005) leak_matrix = get_leak_matrix(i1) synaptic_matrix, threshold_vector = get_connection_flux_matrices(c1) assert leak_matrix.shape == synaptic_matrix.shape assert synaptic_matrix.shape[0] == threshold_vector.shape[0]
from dipde.internals.internalpopulation import InternalPopulation from dipde.internals.connection import Connection from dipde.interfaces.access_matrices import get_leak_matrix, get_connection_flux_matrices import numpy as np import numpy.linalg as npla import logging logging.disable(logging.CRITICAL) # Components: i1 = InternalPopulation(tau_m=.02, v_min=0, v_max=.02, dv=.001) c1 = Connection(None, i1, 1, weights=.005) # Get matrices: leak_matrix = get_leak_matrix(i1) synaptic_matrix, threshold_vector = get_connection_flux_matrices(c1) A = leak_matrix + 100 * synaptic_matrix A[0, :] = 1 b = np.zeros(A.shape[0]) b[0] = 1 # Solve for steady state: p_star = npla.solve(A, b) # Steady state firing rate print np.dot(p_star, 100 * threshold_vector) # A2 = leak_matrix + 100./(1-np.dot(p_star, threshold_vector))*synaptic_matrix # w, vl = npla.eig(A2) # # # print w[np.argmin(np.abs(w))]
def cheb(N): x = np.cos(np.pi * np.arange(N + 1) / N) c = np.array([2] + [1] * (N - 1) + [2]) * np.array([(-1)**ii for ii in range(N + 1)]) X = npm.repmat(x, 1, N + 1).reshape(N + 1, N + 1).T dX = X - X.T D = (np.outer(c, 1. / c)) / (dX + (np.eye(N + 1)) ) # % off-diagonal entries return D - np.diag(np.sum( D, axis=1)) #, x#; % diagonal entries leak_matrix = get_leak_matrix(i1, sparse=False) synaptic_matrix_bg, threshold_vector_bg = get_connection_flux_matrices( b1_i1, sparse=False) synaptic_matrix_recc, _ = get_connection_flux_matrices(i1_i1, sparse=False) A = L + (nsyn_bg * bgfr + nsyn_01 * f0_ss) * Se + nsyn_11 * f1_ss * Si A[0, :] = 1 b = np.zeros(A.shape[0]) b[0] = 1 p_star = npla.solve(A, b) A0 = leak_matrix + (nsyn_bg * bgfr + nsyn_01 * f0_ss) * synaptic_matrix_bg + nsyn_11 * ( nsyn_bg * bgfr + nsyn_01 * f0_ss) * np.dot( p_star, threshold_vector_bg) * synaptic_matrix_recc A1 = (nsyn_bg * bgfr + nsyn_01 * f0_ss) * nsyn_11 * np.outer( synaptic_matrix_recc.dot(p_star), threshold_vector_bg) n = A0.shape[0] N = 6 D = -cheb(N - 1) * 2 / delay
from dipde.internals.internalpopulation import InternalPopulation from dipde.internals.connection import Connection from dipde.interfaces.access_matrices import get_leak_matrix, get_connection_flux_matrices import numpy as np import numpy.linalg as npla import logging logging.disable(logging.CRITICAL) # Components: i1 = InternalPopulation(tau_m=.02, v_min=0, v_max=.02, dv=.001) c1 = Connection(None, i1, 1, weights=.005) # Get matrices: leak_matrix = get_leak_matrix(i1) synaptic_matrix, threshold_vector = get_connection_flux_matrices(c1) A = leak_matrix + 100*synaptic_matrix A[0,:] = 1 b = np.zeros(A.shape[0]) b[0]=1 # Solve for steady state: p_star = npla.solve(A,b) # Steady state firing rate print np.dot(p_star, 100*threshold_vector)
nsyn_bg = 1 bgfr = 600 weight = .03 nsyn_recc = 30 # 16 # Components: b1 = ExternalPopulation(bgfr, record=True) i1 = InternalPopulation(tau_m=.05, v_min=0, v_max=1, dv=dv, update_method = 'gmres') b1_i1 = Connection(b1, i1, nsyn_bg, weights=weight, delays=0.0) i1_i1 = Connection(i1, i1, nsyn_recc, weights=weight, delays=0.0) # Get matrices: leak_matrix = get_leak_matrix(i1, sparse=True) # leak_matrix = spsp.csr_matrix(leak_matrix.shape) synaptic_matrix, threshold_vector = get_connection_flux_matrices(b1_i1, sparse=True) def f(ss_fr_guess): A = leak_matrix + (nsyn_bg*bgfr+nsyn_recc*ss_fr_guess)*synaptic_matrix A[0,:] = 1 b = np.zeros(A.shape[0]) b[0]=1 # Solve for steady state: try:
# # Components: b1 = ExternalPopulation(bgfr, record=True) i1 = InternalPopulation(tau_m=.05, v_min=0, v_max=1, dv=dv, update_method = 'gmres') b1_i1 = Connection(b1, i1, nsyn_bg, weights=we, delays=0.0) i1_i1 = Connection(i1, i1, 0, weights=wi, delays=0.0) def cheb(N): x = np.cos(np.pi*np.arange(N+1)/N) c = np.array([2] + [1]*(N-1) + [2])*np.array([(-1)**ii for ii in range(N+1)]) X = npm.repmat(x,1,N+1).reshape(N+1,N+1).T dX = X-X.T D = (np.outer(c,1./c))/(dX+(np.eye(N+1)))# % off-diagonal entries return D - np.diag(np.sum(D, axis=1))#, x#; % diagonal entries leak_matrix = get_leak_matrix(i1, sparse=False) synaptic_matrix_bg, threshold_vector_bg = get_connection_flux_matrices(b1_i1, sparse=False) synaptic_matrix_recc, _ = get_connection_flux_matrices(i1_i1, sparse=False) A = L + (nsyn_bg*bgfr+nsyn_01*f0_ss)*Se + nsyn_11*f1_ss*Si A[0,:] = 1 b = np.zeros(A.shape[0]) b[0]=1 p_star = npla.solve(A,b) A0 = leak_matrix + (nsyn_bg*bgfr+nsyn_01*f0_ss)*synaptic_matrix_bg + nsyn_11*(nsyn_bg*bgfr+nsyn_01*f0_ss)*np.dot(p_star,threshold_vector_bg)*synaptic_matrix_recc A1 = (nsyn_bg*bgfr+nsyn_01*f0_ss)*nsyn_11*np.outer(synaptic_matrix_recc.dot(p_star), threshold_vector_bg) n = A0.shape[0] N=6 D=-cheb(N-1)*2/delay tmp1 = np.kron(D[:N-1,:], np.eye(n)) tmp2 = np.hstack((A1,np.zeros((n,(N-2)*n)), A0)) tmp3 = spsp.csr_matrix(np.vstack((tmp1, tmp2))) t0 = time.time()