Пример #1
0
def setParms(modelParms):
    global alpha, beta
    if 'alpha' in modelParms:
        alpha = modelParms['alpha']
    if 'beta' in modelParms:
        beta = modelParms['beta']
    DMF.setParms(modelParms)
Пример #2
0
def setParms(modelParms):
    global wgaine, wgaini
    if 'S_E' in modelParms:
        wgaine = modelParms['S_E']
    if 'S_I' in modelParms:
        wgaini = modelParms['S_I']
    DMF.setParms(modelParms)
Пример #3
0
 def errorFunc():
     print('starting sim ({}): '.format(n), end=' ', flush=True)
     DMF.resetBookkeeping()
     Tmaxneuronal = int(
         (tmax + dt))  # (tmax+dt)/dt, but with steps of 1 unit...
     integrator.simulate(dt, Tmaxneuronal, C)
     currm = DMF.curr_rn
     err = distTo3Hz(currm)
     print('-> l^2 error = {}'.format(err))
     return err
Пример #4
0
def testMultipleTimes(trials, we, C):
    targetFreq = 3.  # We want the firing rate to be at 3Hz

    def distTo3Hz(curr):
        import functions.Utils.errorMetrics as error
        tmin = 1000 if (tmax > 1000) else int(tmax / 10)
        currm = np.mean(
            curr[tmin:tmax, :],
            0)  # takes the mean of all xn values along dimension 1...
        # return np.abs(np.average(f)-targetFreq)
        return error.l2(currm, targetFreq)

    def errorFunc():
        print('starting sim ({}): '.format(n), end=' ', flush=True)
        DMF.resetBookkeeping()
        Tmaxneuronal = int(
            (tmax + dt))  # (tmax+dt)/dt, but with steps of 1 unit...
        integrator.simulate(dt, Tmaxneuronal, C)
        currm = DMF.curr_rn
        err = distTo3Hz(currm)
        print('-> l^2 error = {}'.format(err))
        return err

    print("Testing, multiple {} times...".format(trials))
    dt = 0.1
    tmax = 10000
    N = C.shape[0]
    DMF.we = we
    DMF.initJ(N)
    DMF.initBookkeeping(N, tmax)
    results = np.zeros(trials)
    for n in range(trials):
        error = errorFunc()
        results[n] = error
    avg = np.average(results)
    std = np.std(results)
    print("Testing, multiple {} times... Finished!!!".format(trials))
    print("Average=", avg, "std=", std)
    print("Min=", np.min(results), "Max=", np.max(results))

    # the histogram of the data...
    binwidth = 0.05
    bins = np.arange(np.min(results), np.max(results) + binwidth, binwidth)
    print('bins:', bins)
    n, bins, patches = plt.hist(results, bins=bins, facecolor='g')
    print('bins:', bins, 'n:', n, 'patches:', patches)
    print('results:', results)
    plt.xlabel('error')
    plt.ylabel('Probability')
    plt.title('Histogram of errors')
    plt.text(60, .025, '$\mu$={}, $\sigma$={}'.format(avg, std))
    #plt.xlim(40, 160)
    #plt.ylim(0, 0.03)
    #plt.grid(True)
    plt.show()
Пример #5
0
def getParm(parmList):
    if 'alpha' in parmList:
        return alpha
    if 'beta' in parmList:
        return beta
    return DMF.getParm(parmList)
Пример #6
0
def numObsVars():  # Returns the number of observation vars used, here xn and rn
    return DMF.numObsVars()
Пример #7
0
def initSim(N):
    return DMF.initSim(N)
Пример #8
0
def recompileSignatures():
    DMF.recompileSignatures()
    dfun.recompile()
Пример #9
0
def dfun(simVars, I_external):
    return DMF.dfun(simVars, I_external)
Пример #10
0
def plotMaxFrecForAllWe(C,
                        wStart=0,
                        wEnd=6 + 0.001,
                        wStep=0.05,
                        extraTitle='',
                        precompute=True,
                        fileName=None):
    # Integration parms...
    dt = 0.1
    tmax = 10000.
    Tmaxneuronal = int((tmax + dt))
    # all tested global couplings (G in the paper):
    wes = np.arange(
        wStart + wStep, wEnd,
        wStep)  # warning: the range of wes depends on the conectome.
    # wes = np.arange(2.0, 2.11, 0.1)  # only for debug purposes...
    # numW = wes.size  # length(wes);
    N = C.shape[0]

    DMF.setParms({'SC': C})

    print("======================================")
    print("=    simulating E-E (no FIC)         =")
    print("======================================")
    maxRateNoFIC = np.zeros(len(wes))
    DMF.setParms({'J': np.ones(N)})  # E-E = Excitatory-Excitatory, no FIC...
    for kk, we in enumerate(
            wes):  # iterate over the weight range (G in the paper, we here)
        print("Processing: {}".format(we), end='')
        DMF.setParms({'we': we})
        integrator.recompileSignatures()
        v = integrator.simulate(
            dt, Tmaxneuronal
        )[:, 1, :]  # [1] is the output from the excitatory pool, in Hz.
        maxRateNoFIC[kk] = np.max(np.mean(v, 0))
        print(" => {}".format(maxRateNoFIC[kk]))
    ee, = plt.plot(wes, maxRateNoFIC)
    ee.set_label("E-E")

    print("======================================")
    print("=    simulating FIC                  =")
    print("======================================")
    # DMF.lambda = 0.  # make sure no long-range feedforward inhibition (FFI) is computed
    maxRateFIC = np.zeros(len(wes))
    if precompute:
        BalanceFIC.Balance_AllJ9(
            C,
            wes,  # wStart, wEnd, wStep,
            baseName=fileName)
    for kk, we in enumerate(
            wes):  # iterate over the weight range (G in the paper, we here)
        print("\nProcessing: {}  ".format(we), end='')
        DMF.setParms({'we': we})
        balancedJ = BalanceFIC.Balance_J9(
            we, C, fileName.format(np.round(we, decimals=2)))['J'].flatten()
        integrator.neuronalModel.setParms({'J': balancedJ})
        integrator.recompileSignatures()
        v = integrator.simulate(
            dt, Tmaxneuronal
        )[:, 1, :]  # [1] is the output from the excitatory pool, in Hz.
        maxRateFIC[kk] = np.max(np.mean(v, 0))
        print("maxRateFIC => {}".format(maxRateFIC[kk]))
    fic, = plt.plot(wes, maxRateFIC)
    fic.set_label("FIC")

    for line, color in zip([1.47, 4.45], ['r', 'b']):
        plt.axvline(x=line, label='line at x = {}'.format(line), c=color)
    plt.title("Large-scale network (DMF)" + extraTitle)
    plt.ylabel("Maximum rate (Hz)")
    plt.xlabel("Global Coupling (G = we)")
    plt.legend()
    plt.show()
Пример #11
0
def getParm(parmList):
    if 'S_E' in parmList:
        return wgaine
    if 'S_I' in parmList:
        return wgaini
    return DMF.getParms(parmList)