Esempio n. 1
0
def processBrainAreasBOLDForEpsilon(brainAreaSignal, areas):
    global neuro_act
    simulateActivitySubject(C, N, we)
    epsilons = np.arange(0,2.1,0.1)
    results = [] #np.zeros([len(epsilons), len(areas)])
    minEpsilon=0
    minValue=1e99
    for epsilon in epsilons:
        print("Epsilon:", epsilon, end=' ')
        BOLDHemModel_Stephan2008.epsilon = epsilon
        bds = simulateFCD.computeSubjectBOLD(neuro_act, N, areasToSimulate=areas)
        bdsT = bds.T

        #for area, areaID in enumerate(areas):
        norm_bdsT = normalizeSignal(brainAreaSignal, bdsT)
        #print("sim:  ", np.average(norm_bdsT), "+/-", np.sqrt(np.var(norm_bdsT)))
        #print("fMRFI:", np.average(signal), "+/-", np.sqrt(np.var(signal)))
        error = errorMetrics.l2(brainAreaSignal, norm_bdsT)
        if error < minValue:
            minEpsilon = epsilon
            minValue = error
        results.append([error])
        print("Error:", error)
    print("Minimum:", minValue, "at:", minEpsilon,)
    plt.plot(epsilons, results, 'r-')
    plt.show()

    BOLDHemModel_Stephan2008.epsilon = minEpsilon
    bds = simulateFCD.computeSubjectBOLD(neuro_act, N, areasToSimulate=[0])
    bdsT = bds.T
    norm_bdsT = normalizeSignal(brainAreaSignal, bdsT)
    interval=range(len(brainAreaSignal))
    plt.plot(interval,brainAreaSignal.flatten(), 'b-',   interval,norm_bdsT.flatten(), 'r-')
    plt.suptitle('Area:'+str(areas[0]))
    plt.show()
Esempio n. 2
0
def testSingleSubjectMultipleTimes(signal, times):
    print("Testing single subject, multiple {} times...".format(times))
    results = []
    for t in range(times):
        neuro_act = simulateFCD.computeSubjectSimulation(C, N)
        bds = simulateFCD.computeSubjectBOLD(neuro_act)
        bdsT = bds.T
        sim_filt = BOLDFilters.filterBrainArea(bdsT, 0)
        sim_filt /= np.std(sim_filt)
        error = errorMetrics.l2(signal, sim_filt)
        print("Trial: {} ({}) of {}".format(t+1, t, times), "Error:", error)
        results.append([error])
    avg = np.average(results)
    std = np.std(results)
    print("Average:", avg, "std:", std)

    # the histogram of the data
    n, bins, patches = plt.hist(results/avg*10, bins=10, facecolor='g', alpha=0.75)
    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()
Esempio n. 3
0
def simBrainAreaForOptimVars(N, area, keysAndValues):
    global neuro_act
    simulateActivitySubject(C, N, we)
    for key, value in keysAndValues.items():
        exec('BOLDHemModel2.'+key+' = '+str(value))
    bds = simulateFCD.computeSubjectBOLD(neuro_act, areasToSimulate=[area])
    bdsT = bds.T
    sim_filt = BOLDFilters.filterBrainArea(bdsT, 0)
    sim_filt /= np.std(sim_filt)
    return sim_filt
Esempio n. 4
0
def pltSubjectSimulatedBOLD(BOLDSignal):
    global neuro_act
    simulateActivitySubject(C, N, we)
    bds = simulateFCD.computeSubjectBOLD(neuro_act, N)
    bdsT = bds.T
    norm_bdsT = normalizeSignal(BOLDSignal, bdsT)
    interval=range(Tmax)
    for area in range(N):
        plt.plot(interval,norm_bdsT[area].flatten())
    plt.suptitle('BOLD simulation for single subject')
    plt.show()
Esempio n. 5
0
 def errorFunc(neuro_act, epsilon, alpha, tau, gamma, kappa):
     if Verbose:
         global evalCounter
         evalCounter += 1
         print("Test:", evalCounter)
     BOLDModel.epsilon = epsilon
     BOLDModel.alpha = alpha
     BOLDModel.tau = tau
     BOLDModel.gamma = gamma
     BOLDModel.kappa = kappa
     bds = simulateFCD.computeSubjectBOLD(neuro_act, areasToSimulate=[area])
     bdsT = bds.T
     sim_filt = BOLDFilters.filterBrainArea(bdsT, 0)
     sim_filt /= np.std(sim_filt)
     return sim_filt
Esempio n. 6
0
def pltSubjectBOLDForEpsilon(signal):
    global neuro_act
    simulateActivitySubject(C, N, we)
    results = []
    epsilons = np.arange(0,2.1,0.2)
    for epsilon in epsilons:
        print("Epsilon:", epsilon, end=' ')
        BOLDHemModel_Stephan2008.epsilon = epsilon
        bds = simulateFCD.computeSubjectBOLD(neuro_act, N)
        bdsT = bds.T

        norm_bdsT = normalizeSignal(signal, bdsT)
        #print("sim:  ", np.average(norm_bdsT), "+/-", np.sqrt(np.var(norm_bdsT)))
        #print("fMRFI:", np.average(signal), "+/-", np.sqrt(np.var(signal)))
        error = errorMetrics.l2(signal, norm_bdsT)
        results = np.append(results, [error])
        print("Error:", error)
    plt.plot(epsilons, results, 'r-')
    plt.show()
Esempio n. 7
0
def computeValues(
        NumSimSubjects,
        SCnorm,  # fullBOLDSeries,
        processedBOLDemp,
        distanceSettings,
        parmPos,
        value):  # analyzeSignals = False):
    print(
        f"========== computeValues for ad[{parmPos}]={value}  (with {NumSimSubjects} subjects)"
    )
    N = SCnorm.shape[0]
    neuronalModel.ad = np.ones(N)
    neuronalModel.ad[parmPos] = value
    integrator.recompileSignatures()

    print("   --- BEGIN TIME ---")
    simulatedBOLDs = {}
    start_time = time.clock()
    for nsub in range(NumSimSubjects):  # trials. Originally it was 20.
        print("   Simulating subject {}/{}!!!".format(nsub, NumSimSubjects))

        # bds = simulateFCD.simulateSingleSubject(AvgHC, warmup=False).T
        # --- Simple test to check the max rate at the nodes during simulation... ---
        neuro_act = simulateFCD.computeSubjectSimulation(SCnorm,
                                                         N,
                                                         warmup=False)
        bds = simulateFCD.computeSubjectBOLD(neuro_act)

        # if analyzeSignals: analyzeSignals(neuro_act.T, bds.T, fullBOLDSeries)

        simulatedBOLDs[nsub] = bds
    simMeasures = processBOLDSignals(simulatedBOLDs, distanceSettings)
    print("   --- TOTAL TIME: {} seconds ---".format(time.clock() -
                                                     start_time))

    # ---- and now compute the final FC, FCD, ... distances !!! ----
    fitting = {}
    for ds in distanceSettings:
        fitting[ds] = distanceSettings[ds][0].distance(simMeasures[ds],
                                                       processedBOLDemp[ds])

    return fitting
Esempio n. 8
0
def processSubjectForEpsilon(signal):
    global neuro_act
    if doIndividualSim:  # each subject goes with his/her own sim...
        simulateActivitySubject(C, N, we)
    results = []
    epsilons = np.arange(0,1.5,0.1)
    for epsilon in epsilons:
        print("Epsilon:", epsilon, end=' ')
        BOLDHemModel_Stephan2008.epsilon = epsilon
        bds = simulateFCD.computeSubjectBOLD(neuro_act)
        bdsT = bds.T

        norm_bdsT = normalizeSignal(signal, bdsT)
        #print("sim:  ", np.average(norm_bdsT), "+/-", np.sqrt(np.var(norm_bdsT)))
        #print("fMRFI:", np.average(signal), "+/-", np.sqrt(np.var(signal)))
        error = errorMetrics.l2(signal, norm_bdsT)
        np.append(results, [error])
        print("Error:", error)
    plt.plot(epsilons, results, 'r-')
    plt.show()