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
Example #2
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 
Example #3
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(self):
        """Initialize connection distribution.

        Initialization creates the flux_matrix and threshold_flux_vector.
        Implemented lazily via a try catch when flux matrix is requested, that
        does not exist.
        """
        
        nv = len(self.edges)-1
        self.flux_matrix = np.zeros((nv, nv))
        self.threshold_flux_vector = np.zeros(nv)
        for curr_weight, curr_prob in zip(self.weights, self.probs):
            curr_threshold_flux_vector, curr_flux_matrix = util.flux_matrix(self.edges, curr_weight, curr_prob)
            self.flux_matrix += curr_flux_matrix
            self.threshold_flux_vector += curr_threshold_flux_vector

        # Guarantee zero flux:
        np.testing.assert_almost_equal(np.abs(np.sum(self.flux_matrix, axis=0)).sum(), 0, 12)
Example #5
0
    def initialize(self):
        """Initialize connection distribution.

        Initialization creates the flux_matrix and threshold_flux_vector.
        Implemented lazily via a try catch when flux matrix is requested, that
        does not exist.
        """

        nv = len(self.edges) - 1
        self.flux_matrix = np.zeros((nv, nv))
        self.threshold_flux_vector = np.zeros(nv)
        for curr_weight, curr_prob in zip(self.weights, self.probs):
            curr_threshold_flux_vector, curr_flux_matrix = util.flux_matrix(
                self.edges, curr_weight, curr_prob)
            self.flux_matrix += curr_flux_matrix
            self.threshold_flux_vector += curr_threshold_flux_vector

        # Guarantee zero flux:
        np.testing.assert_almost_equal(
            np.abs(np.sum(self.flux_matrix, axis=0)).sum(), 0, 12)
Example #6
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
    def initialize(self):
        """Initialize connection distribution.

        Initialization creates the flux_matrix and threshold_flux_vector.
        Implemented lazily via a try catch when flux matrix is requested, that
        does not exist.
        """
        
        nv = len(self.edges)-1
        flux_matrix_dense = np.zeros((nv, nv))
        self.threshold_flux_vector = np.zeros(nv)
        for curr_weight, curr_prob in zip(self.weights, self.probs):
            curr_threshold_flux_vector, curr_flux_matrix = util.flux_matrix(self.edges, curr_weight, curr_prob)
            flux_matrix_dense += curr_flux_matrix
            self.threshold_flux_vector += curr_threshold_flux_vector
            
        M_I, M_J = np.where(flux_matrix_dense != 0)
        M_val = flux_matrix_dense[M_I, M_J]
        flux_matrix_sparse = (M_I, M_J, M_val)
        self.flux_matrix_dict = {'dense':flux_matrix_dense, 'sparse':flux_matrix_sparse}

        # Guarantee zero flux:
        np.testing.assert_almost_equal(np.abs(np.sum(self.flux_matrix_dict['dense'], axis=0)).sum(), 0, 12)