Beispiel #1
0
def computeStatsBlocks(subjID):

    with open('BehV3_subjID_' + subjID + '.pkl', "rb") as fin:
        sub = (pickle.load(fin))[0]

    statsDay = np.zeros((5, 8))

    statsBlock = np.zeros((4, 16, 5))
    statsBlock_day2 = np.zeros((48, 5))

    idx_c = 0

    for idx, expDay in enumerate(['1', '2', '3', '4', '5']):

        # Load catFile
        catFile = 'P:\\closed_loop_data\\' + str(
            subjID) + '\\createIndices_' + subjID + '_day_' + expDay + '.csv'

        if subjID == '11' and expDay == '2':
            responseTimes = [np.nan]
            nKeypress = np.nan
        else:
            responseTimes = sub['responseTimes_day' + expDay]
            nKeypress = sub['TOTAL_keypress_day' + expDay]

        if subjID == '11' and expDay == '2':
            CI_lure, NI_lure, I_nlure, NI_nlure, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = [
                np.nan
            ] * 8
        else:
            CI_lure, NI_lure, I_nlure, NI_nlure, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = findRTsBlocks(
                catFile, responseTimes, block=False)

        # Compute stats (for visibility)
        TP = NI_nlure
        FP = NI_lure
        TN = CI_lure
        FN = I_nlure

        sensitivity = TP / (TP + FN)
        specificity = TN / (TN + FP)

        accuracy = (TP + TN) / (TP + TN + FP + FN)
        #        accuracy_all = (TP+TN)/nKeypress # Out of all the keypresses that day

        statsDay[
            idx, :] = sensitivity, specificity, accuracy, lure_RT_mean, nonlure_RT_mean, RT_mean, nKeypress, nNaN

        # Block-wise
        for block in range(1, int(len(responseTimes) / 50) + 1):
            print(block)

            if subjID == '11' and expDay == '2':
                TN, FP, FN, TP, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = [
                    np.nan
                ] * 8
            else:
                TN, FP, FN, TP, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = findRTsBlocks(
                    catFile, responseTimes, block=block)

            sensitivity = TP / (TP + FN)
            specificity = TN / (TN + FP)

            accuracy = (TP + TN) / (TP + TN + FP + FN)

            if expDay == '2':
                statsBlock_day2[
                    block -
                    1, :] = sensitivity, specificity, accuracy, RT_mean, nNaN

            if expDay != '2':
                statsBlock[
                    idx_c, block -
                    1, :] = sensitivity, specificity, accuracy, RT_mean, nNaN

        if expDay != '2':
            idx_c += 1

    return statsDay, statsBlock, statsBlock_day2
def computeHitandFA(subjID):
    '''
    Computes hit and FA based on days (statsDay) 
    '''
    
    with open(saveDir + 'BehV3_subjID_' + subjID + '.pkl', "rb") as fin:
        sub = (pickle.load(fin))[0]
    
    statsDay = np.zeros((5,2))
        
    for idx, expDay in enumerate(['1','2','3','4','5']):
        
        # Load catFile
        catFile = 'P:\\closed_loop_data\\' + str(subjID) + '\\createIndices_'+subjID+'_day_'+expDay+'.csv'
        
        if subjID == '11' and expDay == '2':
            responseTimes = [np.nan]
        else:
            responseTimes = sub['responseTimes_day'+expDay]
        
        if subjID == '11' and expDay == '2':
            CI_lure, NI_lure, I_nlure, NI_nlure, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = [np.nan]*8
        else:
            CI_lure, NI_lure, I_nlure, NI_nlure, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = findRTsBlocks(catFile,responseTimes,block=False)
    
        # Compute stats (for visibility)
        TP = NI_nlure # Hit rate
        FP = NI_lure # False alarm
        TN = CI_lure
        FN = I_nlure
        
        if expDay == '2':
            H = TP/2160
            FA = FP/240
            
        else:
            H = TP/720
            FA = FP/80
        
        statsDay[idx,:] = H, FA

    return statsDay
def computeStats(subjID):
    '''
    Adds A' 
    Computes stats based on days (statsDay) and blocks for each day (both statsBlock: day 1, 3, 4, 5 and statsBlock_day2)
    '''
    
    with open(saveDir + 'BehV3_subjID_' + subjID + '.pkl', "rb") as fin:
        sub = (pickle.load(fin))[0]
    
    statsDay = np.zeros((5,8))
    statsBlock = np.zeros((4,16,7))
    statsBlock_day2 = np.zeros((48,7))
    
    idx_c = 0
    
    for idx, expDay in enumerate(['1','2','3','4','5']):
        
        # Load catFile
        catFile = 'P:\\closed_loop_data\\' + str(subjID) + '\\createIndices_'+subjID+'_day_'+expDay+'.csv'
        
        if subjID == '11' and expDay == '2':
            responseTimes = [np.nan]
        else:
            responseTimes = sub['responseTimes_day'+expDay]
        
        if subjID == '11' and expDay == '2':
            CI_lure, NI_lure, I_nlure, NI_nlure, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = [np.nan]*8
        else:
            CI_lure, NI_lure, I_nlure, NI_nlure, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = findRTsBlocks(catFile,responseTimes,block=False)
    
        # Compute stats (for visibility)
        TP = NI_nlure # Hit rate
        FP = NI_lure # False alarm
        TN = CI_lure
        FN = I_nlure
        
        if expDay == '2':
            H = TP/2160
            FA = FP/240
            
        else:
            H = TP/720
            FA = FP/80
        
        # plt.figure(8)
        # plt.scatter(FA,0.85,color='black',label='(FA,H)')
        # plt.ylim(0,1)
        # plt.xlim(0,1)
        # plt.xticks(np.arange(0,1.1,0.1))
        # plt.yticks(np.arange(0,1.1,0.1))
        # plt.xlabel('False alarm rate (FA)')
        # plt.ylabel('Hit rate (H)')
        # plt.plot([0,FA],[0,0.85],'k-',color='black')
        # plt.plot([1,FA],[1,0.85],'k-',color='black')
        # plt.text(0.05,0.6,s='$A_C$')
        # plt.text(0.28,0.9,s='$A_L$')
        # plt.text(0.5,0.5,s='$I$')
        # plt.text(0.25,0.8,s='(FA,H)')
        # plt.title('A\' behavioral measure')
        # plt.grid(color='gainsboro',linewidth=0.5)
        # plt.savefig('aprime.png',dpi=300)
        
        sensitivity = TP/(TP+FN)
        specificity = TN/(TN+FP)
        FPR = FP/(FP+TN)
        accuracy = (TP+TN)/(TP+TN+FP+FN)
        
        errorrate = 1-accuracy
        RER = accuracy/(1-accuracy)
        
        A = 1/2 + (((H-FA)*(1+H-FA))/((4*H)*(1-FA)))
        
        ARER = A/(1-A)
        
        statsDay[idx,:] = sensitivity, FPR, accuracy, errorrate, RER, A, ARER, RT_mean

        # Block-wise
        for block in range(1,int(len(responseTimes)/50)+1):
            print(block)
            
            if subjID == '11' and expDay == '2': 
                TN, FP, FN, TP, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = [np.nan]*8
            else:
                TN, FP, FN, TP, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = findRTsBlocks(catFile,responseTimes,block=block)
            
            sensitivity = TP/(TP+FN)
            specificity = TN/(TN+FP)
            FPR = FP/(FP+TN)
            accuracy = (TP+TN)/(TP+TN+FP+FN)
            
            H = TP/50
            FA = FP/50
        
            sensitivity = TP/(TP+FN)
            specificity = TN/(TN+FP)
            FPR = FP/(FP+TN)
            accuracy = (TP+TN)/(TP+TN+FP+FN)
            
            errorrate = 1-accuracy
            
            A = 1/2 + (((H-FA)*(1+H-FA))/((4*H)*(1-FA)))
            
            ARER = A/(1-A)
            
            
            if expDay == '2':
                statsBlock_day2[block-1,:] = sensitivity, FPR, accuracy, errorrate, A, ARER, RT_mean
        
            if expDay != '2':
                statsBlock[idx_c,block-1,:] = sensitivity, FPR, accuracy, errorrate, A, ARER, RT_mean
                
        if expDay != '2':            
            idx_c += 1

    return statsDay, statsBlock, statsBlock_day2
Beispiel #4
0
def computeStats(subjID):
    '''
    Adds A' 
    Computes stats based on days (statsDay) and blocks for each day (both statsBlock: day 1, 3, 4, 5 and statsBlock_day2)
    '''

    with open(saveDir + 'BehV3_subjID_' + subjID + '.pkl', "rb") as fin:
        sub = (pickle.load(fin))[0]

    statsDay = np.zeros((5, 9))
    statsBlock = np.zeros((4, 16, 6))
    statsBlock_day2 = np.zeros((48, 6))

    idx_c = 0

    for idx, expDay in enumerate(['1', '2', '3', '4', '5']):

        # Load catFile
        catFile = 'P:\\closed_loop_data\\' + str(
            subjID) + '\\createIndices_' + subjID + '_day_' + expDay + '.csv'

        if subjID == '11' and expDay == '2':
            responseTimes = [np.nan]
        else:
            responseTimes = sub['responseTimes_day' + expDay]

        if subjID == '11' and expDay == '2':
            CI_lure, NI_lure, I_nlure, NI_nlure, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = [
                np.nan
            ] * 8
        else:
            CI_lure, NI_lure, I_nlure, NI_nlure, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = findRTsBlocks(
                catFile, responseTimes, block=False)

        # Compute stats (for visibility)
        TP = NI_nlure
        FP = NI_lure
        TN = CI_lure
        FN = I_nlure

        sensitivity = TP / (TP + FN)
        specificity = TN / (TN + FP)
        FPR = FP / (FP + TN)
        accuracy = (TP + TN) / (TP + TN + FP + FN)

        A

        statsDay[
            idx, :] = sensitivity, specificity, FPR, accuracy, errorrate, A, RT_mean

        # Block-wise
        for block in range(1, int(len(responseTimes) / 50) + 1):
            print(block)

            if subjID == '11' and expDay == '2':
                TN, FP, FN, TP, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = [
                    np.nan
                ] * 8
            else:
                TN, FP, FN, TP, lure_RT_mean, nonlure_RT_mean, RT_mean, nNaN = findRTsBlocks(
                    catFile, responseTimes, block=block)

            sensitivity = TP / (TP + FN)
            specificity = TN / (TN + FP)
            FPR = FP / (FP + TN)
            accuracy = (TP + TN) / (TP + TN + FP + FN)

            if expDay == '2':
                statsBlock_day2[
                    block -
                    1, :] = sensitivity, specificity, FPR, accuracy, RT_mean, nNaN

            if expDay != '2':
                statsBlock[
                    idx_c, block -
                    1, :] = sensitivity, specificity, FPR, accuracy, RT_mean, nNaN

        if expDay != '2':
            idx_c += 1

    return statsDay, statsBlock, statsBlock_day2