Esempio n. 1
0
def test_leak_matrix():
    
    # Leak example 1:
    v_min = 0
    v_max = .02
    tau = .02
    dv_n = 1    
    dv = .005/dv_n
    v = np.arange(v_min, v_max+dv, dv)
    L = util.leak_matrix(v, tau)
    L_true = np.array([[   0.,  100.,    0.,    0.],
                       [   0., -100.,  150.,    0.],
                       [   0.,    0., -150.,  200.],
                       [   0.,    0.,    0., -200.]])
    
    np.testing.assert_array_almost_equal_nulp(L, L_true)
    
    # Leak example 2:
    v = [-.02, -.015, -.01, -.005, 0, .005, .01, .015, .02]
    L = util.leak_matrix(v, tau)
    L_true = np.array([[-200.,    0.,    0.,    0.,    0.,    0.,    0.,    0.],
                       [ 200., -150.,    0.,    0.,    0.,    0.,    0.,    0.],
                       [   0.,  150., -100.,    0.,    0.,    0.,    0.,    0.],
                       [   0.,    0.,  100.,    0.,    0.,    0.,    0.,    0.],
                       [   0.,    0.,    0.,    0.,    0.,  100.,    0.,    0.],
                       [   0.,    0.,    0.,    0.,    0., -100.,  150.,    0.],
                       [   0.,    0.,    0.,    0.,    0.,    0., -150.,  200.],
                       [   0.,    0.,    0.,    0.,    0.,    0.,    0., -200.]])
    
    np.testing.assert_array_almost_equal_nulp(L, L_true)
Esempio n. 2
0
def test_leak_matrix():

    # Leak example 1:
    v_min = 0
    v_max = .02
    tau = .02
    dv_n = 1
    dv = .005 / dv_n
    v = np.arange(v_min, v_max + dv, dv)
    L = util.leak_matrix(v, tau)
    L_true = np.array([[0., 100., 0., 0.], [0., -100., 150., 0.],
                       [0., 0., -150., 200.], [0., 0., 0., -200.]])

    np.testing.assert_array_almost_equal_nulp(L, L_true)

    # Leak example 2:
    v = [-.02, -.015, -.01, -.005, 0, .005, .01, .015, .02]
    L = util.leak_matrix(v, tau)
    L_true = np.array([[-200., 0., 0., 0., 0., 0., 0., 0.],
                       [200., -150., 0., 0., 0., 0., 0., 0.],
                       [0., 150., -100., 0., 0., 0., 0., 0.],
                       [0., 0., 100., 0., 0., 0., 0., 0.],
                       [0., 0., 0., 0., 0., 100., 0., 0.],
                       [0., 0., 0., 0., 0., -100., 150., 0.],
                       [0., 0., 0., 0., 0., 0., -150., 200.],
                       [0., 0., 0., 0., 0., 0., 0., -200.]])

    np.testing.assert_array_almost_equal_nulp(L, L_true)
Esempio n. 3
0
    def initialize_edges(self):
        '''Initialize self.edges and self.leak_flux_matrix attributes.
        
        This method initializes the self.edges attribute based on the v_min,
        v_max, and dv settings, and creates a corresponding leak flux matrix
        based on this voltage discretization.
        '''

        # Voltage edges and leak matrix construction
        self.tau_m = util.discretize_if_needed(self.tau_m)
        if np.sum(self.tau_m.xk <= 0) > 0:
            raise Exception('Negative tau_m values detected: %s' %
                            self.tau_m.xk)  # pragma: no cover

        # Voltage edges and leak matrix construction
        self.edges = util.get_v_edges(self.v_min, self.v_max, self.dv)

        # Different leak matrices for different solvers:
        self.leak_flux_matrix_dict = {}
        self.leak_flux_matrix_dict['dense'] = util.leak_matrix(
            self.edges, self.tau_m)

        # Backward Euler sparse:
        lfm_csrbe = sps.eye(
            np.shape(self.leak_flux_matrix_dict['dense'])[0], format='csr'
        ) - self.simulation.dt * self.leak_flux_matrix_dict['dense']
        M_I, M_J = np.where(np.array(lfm_csrbe) != 0)
        M_val = lfm_csrbe[M_I, M_J]
        self.leak_flux_matrix_dict['sparse'] = (M_I, M_J, M_val)
Esempio n. 4
0
def test_flux_ex_inh():

    # Flux example 2:
    v_min = -.02
    v_max = .02
    tau = .02
    w = .005
    dv_n = 500
    dv = .005 / dv_n
    v = np.arange(v_min, v_max + dv, dv)

    A = util.leak_matrix(v, tau)
    flux_to_zero_vector = np.zeros_like(A.sum(axis=0))

    flux_to_zero_vector_tmp, A_tmp = util.flux_matrix(v, w, 100)
    A += A_tmp
    flux_to_zero_vector += flux_to_zero_vector_tmp

    flux_to_zero_vector_tmp, A_tmp = util.flux_matrix(v, -w, 100)
    A += A_tmp
    flux_to_zero_vector += flux_to_zero_vector_tmp

    x = spla.solve(A + np.ones_like(A), np.ones_like(v[:-1]))
    FR_ss = np.dot(x, flux_to_zero_vector)

    assert np.abs(FR_ss - .899715510935) < 1e-10
Esempio n. 5
0
def test_flux_ex_inh():
    
    # Flux example 2:
    v_min = -.02
    v_max = .02
    tau=.02
    w = .005
    dv_n = 500
    dv = .005/dv_n
    v = np.arange(v_min, v_max+dv, dv)
    
    A = util.leak_matrix(v, tau)
    flux_to_zero_vector = np.zeros_like(A.sum(axis=0))
    
    flux_to_zero_vector_tmp, A_tmp = util.flux_matrix(v, w, 100)
    A += A_tmp    
    flux_to_zero_vector += flux_to_zero_vector_tmp
        
    flux_to_zero_vector_tmp, A_tmp = util.flux_matrix(v, -w, 100)
    A += A_tmp
    flux_to_zero_vector += flux_to_zero_vector_tmp 
    
    x = spla.solve(A+np.ones_like(A), np.ones_like(v[:-1]))
    FR_ss = np.dot(x, flux_to_zero_vector)
    
    assert np.abs(FR_ss - .899715510935) < 1e-10 
Esempio n. 6
0
    def initialize_edges(self):
        '''Initialize self.edges and self.leak_flux_matrix attributes.
        
        This method initializes the self.edges attribute based on the v_min,
        v_max, and dv settings, and creates a corresponding leak flux matrix
        based on this voltage discretization.
        '''

        # Voltage edges and leak matrix construction
        self.tau_m = util.discretize_if_needed(self.tau_m)
        if np.sum(self.tau_m.xk <= 0) > 0:
            raise Exception('Negative tau_m values detected: %s' % self.tau_m.xk) # pragma: no cover
        
        
        
        
        
        
        # Voltage edges and leak matrix construction
        self.edges = util.get_v_edges(self.v_min, self.v_max, self.dv)
 
        # Different leak matrices for different solvers:
        self.leak_flux_matrix_dict = {}
        self.leak_flux_matrix_dict['dense'] = util.leak_matrix(self.edges, self.tau_m) 
        
        # Backward Euler sparse:
        lfm_csrbe = sps.eye(np.shape(self.leak_flux_matrix_dict['dense'])[0], format='csr') - self.simulation.dt*self.leak_flux_matrix_dict['dense']
        M_I, M_J = np.where(np.array(lfm_csrbe) != 0) 
        M_val = lfm_csrbe[M_I, M_J]
        self.leak_flux_matrix_dict['sparse'] = (M_I, M_J, M_val)
Esempio n. 7
0
def test_flux_ex_inh_border():
    
    # Flux example 2:
    v_min = 0
    v_max = .02
    tau=sps.rv_discrete(values=([.02],[1]))
    w = .005
    dv_n = 500
    dv = .005/dv_n
    v = np.arange(v_min, v_max+dv, dv)
    
    A = util.leak_matrix(v, tau)
    flux_to_zero_vector = np.zeros_like(A.sum(axis=0))
    
    flux_to_zero_vector_tmp, A_tmp = util.flux_matrix(v, w, 100)
    A += A_tmp    
    flux_to_zero_vector += flux_to_zero_vector_tmp
        
    flux_to_zero_vector_tmp, A_tmp = util.flux_matrix(v, -w, 100)
    A += A_tmp
    flux_to_zero_vector += flux_to_zero_vector_tmp 
    
    x = spla.solve(A+np.ones_like(A), np.ones_like(v[:-1]))
    FR_ss = np.dot(x, flux_to_zero_vector)
    
    assert np.abs(FR_ss - 1.47243297098) < 1e-10 
    def initialize_edges(self):
        '''Initialize self.edges and self.leak_flux_matrix attributes.
        
        This method initializes the self.edges attribute based on the v_min,
        v_max, and dv settings, and creates a corresponding leak flux matrix
        based on this voltage discretization.
        '''

        # Voltage edges and leak matrix construction
        self.edges = util.get_v_edges(self.v_min, self.v_max, self.dv)
        self.leak_flux_matrix = util.leak_matrix(self.edges, self.tau_m)
Esempio n. 9
0
    def initialize_edges(self):
        '''Initialize self.edges and self.leak_flux_matrix attributes.
        
        This method initializes the self.edges attribute based on the v_min,
        v_max, and dv settings, and creates a corresponding leak flux matrix
        based on this voltage discretization.
        '''

        # Voltage edges and leak matrix construction
        self.edges = util.get_v_edges(self.v_min, self.v_max, self.dv)
        self.leak_flux_matrix = util.leak_matrix(self.edges, self.tau_m)
    def initialize_edges(self):
        '''Initialize self.edges and self.leak_flux_matrix attributes.
        
        This method initializes the self.edges attribute based on the v_min,
        v_max, and dv settings, and creates a corresponding leak flux matrix
        based on this voltage discretization.
        '''

        # Voltage edges and leak matrix construction
        self.tau_m = util.discretize_if_needed(self.tau_m)
        if np.sum(self.tau_m.xk <= 0) > 0:
            raise Exception('Negative tau_m values detected: %s' % self.tau_m.xk) # pragma: no cover
        self.edges = util.get_v_edges(self.v_min, self.v_max, self.dv)
        self.leak_flux_matrix = util.leak_matrix(self.edges, self.tau_m)
Esempio n. 11
0
def test_flux_ex():

    # Flux example 1:
    v_min = 0
    v_max = .02
    tau = sps.rv_discrete(values=(.02, 1))
    w = .005
    dv_n = 500
    dv = .005 / dv_n
    v = np.arange(v_min, v_max + dv, dv)

    A = util.leak_matrix(v, tau)
    flux_to_zero_vector = np.zeros_like(A.sum(axis=0))

    flux_to_zero_vector_tmp, A_tmp = util.flux_matrix(v, w, 100)
    A += A_tmp
    flux_to_zero_vector += flux_to_zero_vector_tmp

    x = spla.solve(A + np.ones_like(A), np.ones_like(v[:-1]))
    FR_ss = np.dot(x, flux_to_zero_vector)

    assert np.abs(FR_ss - 5.28031853301) < 1e-10