diff --git a/neurolib/models/aln/loadDefaultParams.py b/neurolib/models/aln/loadDefaultParams.py index c5c8d4b4..9ed09519 100644 --- a/neurolib/models/aln/loadDefaultParams.py +++ b/neurolib/models/aln/loadDefaultParams.py @@ -187,27 +187,6 @@ def loadDefaultParams(Cmat=None, Dmat=None, lookupTableFileName=None, seed=None) return params -def computeDelayMatrix(lengthMat, signalV, segmentLength=1): - """ - Compute the delay matrix from the fiber length matrix and the signal - velocity - - :param lengthMat: A matrix containing the connection length in - segment - :param signalV: Signal velocity in m/s - :param segmentLength: Length of a single segment in mm - - :returns: A matrix of connexion delay in ms - """ - - normalizedLenMat = lengthMat * segmentLength - if signalV > 0: - Dmat = normalizedLenMat / signalV # Interareal delays in ms - else: - Dmat = lengthMat * 0.0 - return Dmat - - def generateRandomICs(N, seed=None): """Generates random Initial Conditions for the interareal network diff --git a/neurolib/models/aln/timeIntegration.py b/neurolib/models/aln/timeIntegration.py index c5b7346a..124dd0eb 100644 --- a/neurolib/models/aln/timeIntegration.py +++ b/neurolib/models/aln/timeIntegration.py @@ -1,13 +1,12 @@ import numpy as np import numba -from . import loadDefaultParams as dp from ...utils import model_utils as mu def timeIntegration(params): """Sets up the parameters for time integration - + Return: rates_exc: N*L array : containing the exc. neuron rates in kHz time series of the N nodes rates_inh: N*L array : containing the inh. neuron rates in kHz time series of the N nodes @@ -53,7 +52,7 @@ def timeIntegration(params): if N == 1: Dmat = np.ones((N, N)) * params["de"] else: - Dmat = dp.computeDelayMatrix( + Dmat = mu.computeDelayMatrix( lengthMat, signalV ) # Interareal connection delays, Dmat(i,j) Connnection from jth node to ith (ms) Dmat[np.eye(len(Dmat)) == 1] = np.ones(len(Dmat)) * params["de"] @@ -399,10 +398,10 @@ def timeIntegration_njit_elementwise( ): # squared Jee_max - sq_Jee_max = Jee_max ** 2 - sq_Jei_max = Jei_max ** 2 - sq_Jie_max = Jie_max ** 2 - sq_Jii_max = Jii_max ** 2 + sq_Jee_max = Jee_max**2 + sq_Jei_max = Jei_max**2 + sq_Jie_max = Jie_max**2 + sq_Jii_max = Jii_max**2 # initialize so we don't get an error when returning rd_exc_rhs = 0.0 @@ -456,24 +455,24 @@ def timeIntegration_njit_elementwise( z1ii = cii * Ki * rd_inh[no] # z2: weighted sum of delayed rates, weights=c^2*K (see thesis last ch.) z2ee = ( - cee ** 2 * Ke * rd_exc[no, no] + c_gl ** 2 * Ke_gl * rowsumsq + c_gl ** 2 * Ke_gl * ext_exc_rate[no, i] + cee**2 * Ke * rd_exc[no, no] + c_gl**2 * Ke_gl * rowsumsq + c_gl**2 * Ke_gl * ext_exc_rate[no, i] ) - z2ei = cei ** 2 * Ki * rd_inh[no] + z2ei = cei**2 * Ki * rd_inh[no] z2ie = ( - cie ** 2 * Ke * rd_exc[no, no] + c_gl ** 2 * Ke_gl * ext_inh_rate[no, i] + cie**2 * Ke * rd_exc[no, no] + c_gl**2 * Ke_gl * ext_inh_rate[no, i] ) # external rate input to inh. population - z2ii = cii ** 2 * Ki * rd_inh[no] + z2ii = cii**2 * Ki * rd_inh[no] sigmae = np.sqrt( 2 * sq_Jee_max * seev[no] * tau_se * taum / ((1 + z1ee) * taum + tau_se) + 2 * sq_Jei_max * seiv[no] * tau_si * taum / ((1 + z1ei) * taum + tau_si) - + sigmae_ext ** 2 + + sigmae_ext**2 ) # mV/sqrt(ms) sigmai = np.sqrt( 2 * sq_Jie_max * siev[no] * tau_se * taum / ((1 + z1ie) * taum + tau_se) + 2 * sq_Jii_max * siiv[no] * tau_si * taum / ((1 + z1ii) * taum + tau_si) - + sigmai_ext ** 2 + + sigmai_ext**2 ) # mV/sqrt(ms) if not filter_sigma: @@ -531,10 +530,10 @@ def timeIntegration_njit_elementwise( seim_rhs = ((1 - seim[no]) * z1ei - seim[no]) / tau_si siem_rhs = ((1 - siem[no]) * z1ie - siem[no]) / tau_se siim_rhs = ((1 - siim[no]) * z1ii - siim[no]) / tau_si - seev_rhs = ((1 - seem[no]) ** 2 * z2ee + (z2ee - 2 * tau_se * (z1ee + 1)) * seev[no]) / tau_se ** 2 - seiv_rhs = ((1 - seim[no]) ** 2 * z2ei + (z2ei - 2 * tau_si * (z1ei + 1)) * seiv[no]) / tau_si ** 2 - siev_rhs = ((1 - siem[no]) ** 2 * z2ie + (z2ie - 2 * tau_se * (z1ie + 1)) * siev[no]) / tau_se ** 2 - siiv_rhs = ((1 - siim[no]) ** 2 * z2ii + (z2ii - 2 * tau_si * (z1ii + 1)) * siiv[no]) / tau_si ** 2 + seev_rhs = ((1 - seem[no]) ** 2 * z2ee + (z2ee - 2 * tau_se * (z1ee + 1)) * seev[no]) / tau_se**2 + seiv_rhs = ((1 - seim[no]) ** 2 * z2ei + (z2ei - 2 * tau_si * (z1ei + 1)) * seiv[no]) / tau_si**2 + siev_rhs = ((1 - siem[no]) ** 2 * z2ie + (z2ie - 2 * tau_se * (z1ie + 1)) * siev[no]) / tau_se**2 + siiv_rhs = ((1 - siim[no]) ** 2 * z2ii + (z2ii - 2 * tau_si * (z1ii + 1)) * siiv[no]) / tau_si**2 # -------------- integration -------------- @@ -636,6 +635,7 @@ def lookup_no_interp(x, dx, xi, y, dy, yi): return idxX, idxY + @numba.njit(locals={"xid1": numba.int64, "yid1": numba.int64, "dxid": numba.float64, "dyid": numba.float64}) def fast_interp2_opt(x, dx, xi, y, dy, yi): diff --git a/neurolib/models/fhn/loadDefaultParams.py b/neurolib/models/fhn/loadDefaultParams.py index 9f06d65a..98016cb2 100644 --- a/neurolib/models/fhn/loadDefaultParams.py +++ b/neurolib/models/fhn/loadDefaultParams.py @@ -79,22 +79,3 @@ def loadDefaultParams(Cmat=None, Dmat=None, seed=None): params.y_ext = np.zeros((params.N,)) return params - - -def computeDelayMatrix(lengthMat, signalV, segmentLength=1): - """Compute the delay matrix from the fiber length matrix and the signal velocity - - :param lengthMat: A matrix containing the connection length in segment - :param signalV: Signal velocity in m/s - :param segmentLength: Length of a single segment in mm - - :returns: A matrix of connexion delay in ms - """ - - normalizedLenMat = lengthMat * segmentLength - # Interareal connection delays, Dmat(i,j) in ms - if signalV > 0: - Dmat = normalizedLenMat / signalV - else: - Dmat = lengthMat * 0.0 - return Dmat diff --git a/neurolib/models/fhn/timeIntegration.py b/neurolib/models/fhn/timeIntegration.py index f3be5874..74f9d921 100644 --- a/neurolib/models/fhn/timeIntegration.py +++ b/neurolib/models/fhn/timeIntegration.py @@ -1,7 +1,6 @@ import numpy as np import numba -from . import loadDefaultParams as dp from ...utils import model_utils as mu @@ -53,7 +52,7 @@ def timeIntegration(params): Dmat = np.zeros((N, N)) else: # Interareal connection delays, Dmat(i,j) Connnection from jth node to ith (ms) - Dmat = dp.computeDelayMatrix(lengthMat, signalV) + Dmat = mu.computeDelayMatrix(lengthMat, signalV) # no self-feedback delay Dmat[np.eye(len(Dmat)) == 1] = np.zeros(len(Dmat)) Dmat_ndt = np.around(Dmat / dt).astype(int) # delay matrix in multiples of dt diff --git a/neurolib/models/hopf/loadDefaultParams.py b/neurolib/models/hopf/loadDefaultParams.py index c5d6a50b..4f03b0be 100644 --- a/neurolib/models/hopf/loadDefaultParams.py +++ b/neurolib/models/hopf/loadDefaultParams.py @@ -77,22 +77,3 @@ def loadDefaultParams(Cmat=None, Dmat=None, seed=None): params.y_ext = np.zeros((params.N,)) return params - - -def computeDelayMatrix(lengthMat, signalV, segmentLength=1): - """Compute the delay matrix from the fiber length matrix and the signal velocity - - :param lengthMat: A matrix containing the connection length in segment - :param signalV: Signal velocity in m/s - :param segmentLength: Length of a single segment in mm - - :returns: A matrix of connexion delay in ms - """ - - normalizedLenMat = lengthMat * segmentLength - # Interareal connection delays, Dmat(i,j) in ms - if signalV > 0: - Dmat = normalizedLenMat / signalV - else: - Dmat = lengthMat * 0.0 - return Dmat diff --git a/neurolib/models/hopf/timeIntegration.py b/neurolib/models/hopf/timeIntegration.py index 20e4fe60..8d393124 100644 --- a/neurolib/models/hopf/timeIntegration.py +++ b/neurolib/models/hopf/timeIntegration.py @@ -1,7 +1,6 @@ import numpy as np import numba -from . import loadDefaultParams as dp from ...utils import model_utils as mu @@ -59,7 +58,7 @@ def timeIntegration(params): Dmat = np.zeros((N, N)) else: # Interareal connection delays, Dmat(i,j) Connnection from jth node to ith (ms) - Dmat = dp.computeDelayMatrix(lengthMat, signalV) + Dmat = mu.computeDelayMatrix(lengthMat, signalV) Dmat[np.eye(len(Dmat)) == 1] = np.zeros(len(Dmat)) Dmat_ndt = np.around(Dmat / dt).astype(int) # delay matrix in multiples of dt # ------------------------------------------------------------------------ diff --git a/neurolib/models/wc/loadDefaultParams.py b/neurolib/models/wc/loadDefaultParams.py index 788dfe0d..8bf95383 100644 --- a/neurolib/models/wc/loadDefaultParams.py +++ b/neurolib/models/wc/loadDefaultParams.py @@ -80,22 +80,3 @@ def loadDefaultParams(Cmat=None, Dmat=None, seed=None): params.inh_ou = np.zeros((params.N,)) return params - - -def computeDelayMatrix(lengthMat, signalV, segmentLength=1): - """Compute the delay matrix from the fiber length matrix and the signal velocity - - :param lengthMat: A matrix containing the connection length in segment - :param signalV: Signal velocity in m/s - :param segmentLength: Length of a single segment in mm - - :returns: A matrix of connexion delay in ms - """ - - normalizedLenMat = lengthMat * segmentLength - # Interareal connection delays, Dmat(i,j) in ms - if signalV > 0: - Dmat = normalizedLenMat / signalV - else: - Dmat = lengthMat * 0.0 - return Dmat diff --git a/neurolib/models/wc/timeIntegration.py b/neurolib/models/wc/timeIntegration.py index 0c83d55f..b1be0bde 100644 --- a/neurolib/models/wc/timeIntegration.py +++ b/neurolib/models/wc/timeIntegration.py @@ -1,7 +1,6 @@ import numpy as np import numba -from . import loadDefaultParams as dp from ...utils import model_utils as mu @@ -59,7 +58,7 @@ def timeIntegration(params): Dmat = np.zeros((N, N)) else: # Interareal connection delays, Dmat(i,j) Connnection from jth node to ith (ms) - Dmat = dp.computeDelayMatrix(lengthMat, signalV) + Dmat = mu.computeDelayMatrix(lengthMat, signalV) Dmat[np.eye(len(Dmat)) == 1] = np.zeros(len(Dmat)) Dmat_ndt = np.around(Dmat / dt).astype(int) # delay matrix in multiples of dt # ------------------------------------------------------------------------ diff --git a/neurolib/models/ww/loadDefaultParams.py b/neurolib/models/ww/loadDefaultParams.py index 05d68108..e2e030b6 100644 --- a/neurolib/models/ww/loadDefaultParams.py +++ b/neurolib/models/ww/loadDefaultParams.py @@ -88,22 +88,3 @@ def loadDefaultParams(Cmat=None, Dmat=None, seed=None): params.inh_ou = np.zeros((params.N,)) return params - - -def computeDelayMatrix(lengthMat, signalV, segmentLength=1): - """Compute the delay matrix from the fiber length matrix and the signal velocity - - :param lengthMat: A matrix containing the connection length in segment - :param signalV: Signal velocity in m/s - :param segmentLength: Length of a single segment in mm - - :returns: A matrix of connexion delay in ms - """ - - normalizedLenMat = lengthMat * segmentLength - # Interareal connection delays, Dmat(i,j) in ms - if signalV > 0: - Dmat = normalizedLenMat / signalV - else: - Dmat = lengthMat * 0.0 - return Dmat diff --git a/neurolib/models/ww/timeIntegration.py b/neurolib/models/ww/timeIntegration.py index 5142e965..4d35d6a8 100644 --- a/neurolib/models/ww/timeIntegration.py +++ b/neurolib/models/ww/timeIntegration.py @@ -1,7 +1,7 @@ import numpy as np import numba -from . import loadDefaultParams as dp +from ...utils import model_utils as mu def timeIntegration(params): @@ -63,7 +63,7 @@ def timeIntegration(params): Dmat = np.zeros((N, N)) else: # Interareal connection delays, Dmat(i,j) Connnection from jth node to ith (ms) - Dmat = dp.computeDelayMatrix(lengthMat, signalV) + Dmat = mu.computeDelayMatrix(lengthMat, signalV) # no self-feedback delay Dmat[np.eye(len(Dmat)) == 1] = np.zeros(len(Dmat)) Dmat_ndt = np.around(Dmat / dt).astype(int) # delay matrix in multiples of dt diff --git a/neurolib/utils/model_utils.py b/neurolib/utils/model_utils.py index 7b530808..e18ee104 100644 --- a/neurolib/utils/model_utils.py +++ b/neurolib/utils/model_utils.py @@ -42,3 +42,24 @@ def adjustArrayShape(original, target): original = original[: target.shape[0], -target.shape[1] :] return original + + +def computeDelayMatrix(lengthMat, signalV, segmentLength=1): + """ + Compute the delay matrix from the fiber length matrix and the signal + velocity + + :param lengthMat: A matrix containing the connection length in + segment + :param signalV: Signal velocity in m/s + :param segmentLength: Length of a single segment in mm + + :returns: A matrix of connexion delay in ms + """ + + normalizedLenMat = lengthMat * segmentLength + if signalV > 0: + Dmat = normalizedLenMat / signalV # Interareal delays in ms + else: + Dmat = lengthMat * 0.0 + return Dmat