def rearrange(self, savefig=False): dfs, pool = self.sumxrl() # Change the question: whether it is more plus? so you need to swap 0 and 1 during a minus reference pool_labels = pool['allResponses'].index pool['revResponses'] = pool['allResponses'] for label in pool_labels: if label.endswith('m'): pool['revResponses'][label] = 1 - pool['allResponses'][label] # Combine each two conditions rearranged = pd.DataFrame(columns=[ 'hue', 'intensity', 'response', 'ntrial', 'combinedInten', 'combinedResp', 'combinedN', 'sems', 'fit', 'pse', 'thre' ]) # stupid but straightforward way to combine... for ii in np.arange(0, len(pool_labels) - 1, 2): idx = ii // 2 rearranged.loc[idx, 'hue'] = 'hue_' + str(idx + 1) rearranged.loc[idx, 'intensity'] = np.hstack( [pool['allIntensities'][ii], pool['allIntensities'][ii + 1]]) rearranged.loc[idx, 'response'] = np.hstack( [pool['allResponses'][ii], pool['allResponses'][ii + 1]]) rearranged.loc[idx, 'ntrial'] = pool['ntrial'][0] * 2 rearranged.loc[idx, 'combinedInten'], \ rearranged.loc[idx, 'combinedResp'], \ rearranged.loc[idx, 'combinedN'] = data.functionFromStaircase(rearranged.loc[idx, 'intensity'], rearranged.loc[idx, 'response'], bins='unique') rearranged.loc[idx, 'sems'] = [ sum(rearranged.loc[idx, 'combinedN']) / n for n in rearranged.loc[idx, 'combinedN'] ] # sems is defined as 1/weight in Psychopy guess = [5, 1] rearranged.loc[idx, 'fit'] = FitCumNormal( rearranged.loc[idx, 'combinedInten'], rearranged.loc[idx, 'combinedResp'], sems=rearranged.loc[idx, 'sems'], guess=None, expectedMin=0.0, lapse=0.01) # customized cumulative Gaussian rearranged.loc[idx, 'pse'] = rearranged.loc[idx, 'fit'].inverse(0.5 - .01) rearranged.loc[idx, 'thre'] = rearranged.loc[idx, 'fit'].inverse(0.75 - .01) return rearranged
def fitpf(self): dfs, pool = self.sumxrl() allIntensities = pool['allIntensities'] allResponses = pool['allResponses'] ntrial = pool['ntrial'] # curve fitting and plotting for each condition res = {} # print('label: ' + 'centre, ' + 'std, ' + 'ssq') for idx, label in enumerate(allResponses.index): res[label] = {} res[label]['intensities'] = abs(allIntensities[label]) res[label]['responses'] = allResponses[label] res[label]['combinedInten'], res[label]['combinedResp'], res[label]['combinedN'] = \ data.functionFromStaircase(res[label]['intensities'], res[label]['responses'], bins='unique') # bin data and fit to PF res[label]['sems'] = [ 1.0 / (n / sum(res[label]['combinedN'])) for n in res[label]['combinedN'] ] # sems is defined as 1/weight in Psychopy # res[label]['fit'] = data.FitCumNormal(res[label]['combinedInten'], # res[label]['combinedResp'], # sems=res[label]['sems'], guess=None, # expectedMin=0.5) # cumulative Gaussian guess = [5, 0.5] # if label == 'hue_1p' or label == 'hue_2p': # print('detected') # guess = [8, 0.5] res[label]['fit'] = FitCumNormal( res[label]['combinedInten'], res[label]['combinedResp'], sems=res[label]['sems'], guess=guess, expectedMin=0.5, lapse=0.05) # customized cumulative Gaussian # print(label + ':' + str(res[label]['fit'].params) + ', ' + str( # res[label]['fit'].ssq)) # a list with [centre, sd] for the Gaussian distribution forming the cumulative res[label]['thresh'] = res[label]['fit'].inverse(0.75) # threshold return ntrial, res
allIntensities.append(thisDat.intensities) allResponses.append(thisDat.data) #plot each staircase pylab.subplot(121) colors = 'brgkcmbrgkcm' lines, names = [], [] for fileN, thisStair in enumerate(allIntensities): #lines.extend(pylab.plot(thisStair)) #names = files[fileN] pylab.plot(thisStair, label=files[fileN]) #pylab.legend() #get combined data combinedInten, combinedResp, combinedN = \ data.functionFromStaircase(allIntensities, allResponses, 5) #fit curve - in this case using a Weibull function fit = data.FitFunction('weibullTAFC',combinedInten, combinedResp, \ guess=[0.2, 0.5]) smoothInt = pylab.arange(min(combinedInten), max(combinedInten), 0.001) smoothResp = fit.eval(smoothInt) thresh = fit.inverse(0.8) print thresh #plot curve pylab.subplot(122) pylab.plot(smoothInt, smoothResp, '-') pylab.plot([thresh, thresh], [0, 0.8], '--')pylab.plot([0, thresh],\ [0.8,0.8],'--') pylab.title('threshold = %0.3f' % (thresh)) #plot points
#Act of importing will cause staircase intensities to log transform because that's how intensities are represented in the staircase #staircase internal will be i = log(100-x) #-(10**i)-100 staircase.importData( toStaircase(noiseEachTrial,descendingPsycho), np.array(corrEachTrial) ) printStaircase(staircase, briefTrialUpdate=False, printInternalVal=True, alsoLog=False) #Fit and plot data descendingPsycho = False fit = None intensityForCurveFitting = outOfStaircase(staircase.intensities,staircase,descendingPsycho) #print('intensityForCurveFitting=',intensityForCurveFitting) if descendingPsycho: intensityForCurveFitting = 100-staircase.intensities #because fitWeibull assumes curve is ascending #convert from list of trials to probabilities combinedInten, combinedResp, combinedN = \ data.functionFromStaircase(intensityForCurveFitting, staircase.data, bins='unique') print('combinedInten=',combinedInten,'combinedResp=',combinedResp) try: fit = data.FitWeibull(combinedInten, combinedResp, expectedMin=0, sems = 1.0/len(staircase.intensities)) print('fit=',fit) except: print("Fit failed.") plotDataAndPsychometricCurve(staircase,fit,descendingPsycho,threshVal=0.75) pylab.show() #must call this to actually show plot testNoise = True if testNoise: #Test noise myWin = visual.Window() proportnNoise = 0.9 noiseFieldWidthPix = 200 bgColor = [-.7,-.7,-.7]
for imageName, array in thisIndDat.extraInfo.iteritems(): thisImageName = imageName indIntensities[thisImageName]=[] indResponses[thisImageName]=[] thisIntensity = thisIndDat.reversalIntensities[-10:] thisResponse = thisIndDat.data[-10:] indIntensities[thisImageName].extend(thisIntensity) indResponses[thisImageName].extend(thisResponse) #get individual data thisNewIntensity = indIntensities[thisImageName] thisNewResponse = indResponses[thisImageName] combinedIndInten, combinedIndResp, CombinedN = data.functionFromStaircase(thisIntensity, thisResponse, 'unique') #fit curve combinedIndInten = numpy.array(combinedIndInten)+100 fit = data.FitWeibull(combinedIndInten, combinedIndResp, guess =[105, 10], expectedMin = 0.5) smoothIndInt = pylab.arange(min(combinedIndInten), max(combinedIndInten), 0.001) smoothIndResp = fit.eval(smoothIndInt) Threshold = fit.inverse(0.8)-100 print 'Threshold', Threshold label = thisImageName + (" - %.2f" %Threshold) pylab.subplot(122) pylab.plot(smoothIndInt-100, smoothIndResp, '--', label = label) pylab.legend(loc = 'lower right')
assert isinstance(thisDat, data.StairHandler) allIntensities.append(thisDat.intensities) allResponses.append(thisDat.data) # plot each staircase pylab.subplot(121) colors = "brgkcmbrgkcm" lines, names = [], [] for fileN, thisStair in enumerate(allIntensities): # lines.extend(pylab.plot(thisStair)) # names = files[fileN] pylab.plot(thisStair, label=files[fileN]) # pylab.legend() # get combined data combinedInten, combinedResp, combinedN = data.functionFromStaircase(allIntensities, allResponses, "unique") combinedInten = np.asarray(combinedInten) + 100 # fit curve fit = data.FitWeibull(combinedInten, combinedResp, guess=[100.2, 0.5], expectedMin=0.0) smoothInt = pylab.arange(min(combinedInten), max(combinedInten), 0.001) smoothResp = fit.eval(smoothInt) thresh = fit.inverse(0.5) - 100 # thresh = fit.inverse(0.8)-100 # lower = fit.inverse(0.675) # upper = fit.inverse(0.925) lower = fit.inverse(0.25) - 100 upper = fit.inverse(0.75) - 100 jnd = upper - lower
thisDat = fromFile(thisFileName) assert isinstance(thisDat, data.StairHandler) allIntensities.append( thisDat.intensities ) allResponses.append( thisDat.data ) # plot each staircase pylab.subplot(121) lines, names = [], [] for fileN, thisStair in enumerate(allIntensities): # lines.extend(pylab.plot(thisStair)) # names = files[fileN] pylab.plot(thisStair, label=files[fileN]) # pylab.legend() # get combined data i, r, n = data.functionFromStaircase(allIntensities, allResponses, 'unique') combinedInten, combinedResp, combinedN = i, r, n # fit curve guess =[num.average(combinedInten), num.average(combinedInten)/5] fit = data.FitWeibull(combinedInten, combinedResp, guess=guess, expectedMin=0.0) smoothInt = num.arange(min(combinedInten), max(combinedInten), 0.001) smoothResp = fit.eval(smoothInt) thresh = fit.inverse(0.5) print(thresh) # plot curve pylab.subplot(122) pylab.plot(smoothInt, smoothResp, '-') pylab.plot([thresh, thresh], [0, 0.5], '--')
xlimits=pylab.xlim([0,50]) ylimits=pylab.ylim([140,165]) pylab.subplot(212) for fileN, thisStair in enumerate(allIntensitiesR): pylab.plot(thisStair, '-') pylab.title('%s_right_loc=%0.0f' %(thisOb,thisLocation)) xlimits=pylab.xlim([0,50]) ylimits=pylab.ylim([140,165]) pylab.savefig ('Analysis%s//FIGURES//SampleStaircases.png' %(fileTag), dpi = 600) pylab.savefig ('Analysis%s//FIGURES//SampleStaircases.eps' %(fileTag), dpi = 600) pylab.figure(2, figsize = (5,5)) #left side trials combinedInten, combinedResp, combinedN = data.functionFromStaircase(allIntensitiesL, allResponsesL, 'unique')#fit curve guess= [pylab.mean(combinedInten), 4.0] fit = data.FitWeibull(combinedInten, combinedResp, expectedMin=0.0, guess=guess, display=0) smoothInt = pylab.arange(min(combinedInten), max(combinedInten), 0.001) smoothResp = fit.eval(smoothInt) thresh = fit.inverse(0.5) lower = fit.inverse(0.25) upper = fit.inverse(0.75) jnd = upper - lower #plot curve pylab.plot(smoothInt, smoothResp, '-k') pylab.plot([thresh, thresh],[0,0.5],'--r'); pylab.plot([0, thresh],[0.5,0.5],'--r') #plot points maxN=max(combinedN); minN=min(combinedN) maxMarker=8.0; minMarker=4.0 for pointN in range(len(combinedInten)):
allRTs.append( thisDat.otherData['rt']) #plot each staircase pylab.subplot(131) colors = 'brgkcmbrgkcm' lines, names = [],[] for fileN, thisStair in enumerate(allCoherenceLevels): #lines.extend(pylab.plot(thisStair)) #names = files[fileN] pylab.plot(thisStair, label=files[fileN]) pylab.xlabel('Trial') pylab.ylabel('Coherence') #pylab.legend() #get combined data combinedInten, combinedResp, combinedN =data.functionFromStaircase(allCoherenceLevels, allResponses, 5) #fit curve - in this case using a Weibull function fit = data.FitWeibull(combinedInten, combinedResp, guess=[0.2, 0.5]) #smoothInt = pylab.arange(min(combinedInten), max(combinedInten), 0.001) smoothInt = pylab.arange(0.0, max(combinedInten), 0.001) smoothResp = fit.eval(smoothInt) thresh = fit.inverse(0.8) print thresh #plot curve pylab.subplot(132) pylab.plot(smoothInt, smoothResp, '-') pylab.plot([thresh, thresh],[0,0.8],'--') pylab.plot([0, thresh], [0.8,0.8],'--') pylab.title('threshold = %0.3f' % thresh) #plot points
corrEachTrial = np.zeros( len(noiseEachTrial) ) for i in range( len(noiseEachTrial) ): corrEachTrial[i] = np.random.binomial( 1, pCorrEachTrial[i] ) print('corrEachTrial=',corrEachTrial) print('Importing responses ',np.array(corrEachTrial),' and intensities ',noiseEachTrial) #Act of importing will cause staircase intensities to log transform because that's how intensities are represented in the staircase #staircase internal will be i = log(100-x) #-(10**i)-100 staircase.importData( toStaircase(noiseEachTrial,descendingPsycho), np.array(corrEachTrial) ) printStaircase(staircase, briefTrialUpdate=False, printInternalVal=True, alsoLog=False) #Fit and plot data descendingPsycho = False fit = None intensityForCurveFitting = outOfStaircase(staircase.intensities,staircase,descendingPsycho) #print('intensityForCurveFitting=',intensityForCurveFitting) if descendingPsycho: intensityForCurveFitting = 100-staircase.intensities #because fitWeibull assumes curve is ascending #convert from list of trials to probabilities combinedInten, combinedResp, combinedN = \ data.functionFromStaircase(intensityForCurveFitting, staircase.data, bins='unique') print('combinedInten=',combinedInten,'combinedResp=',combinedResp) try: fit = data.FitWeibull(combinedInten, combinedResp, expectedMin=0, sems = 1.0/len(staircase.intensities)) print('fit=',fit) except: print("Fit failed.") plotDataAndPsychometricCurve(staircase,fit,descendingPsycho,threshVal=0.75) pylab.show() #must call this to actually show plot
def fitpf(self): from psychopy import data import pylab import matplotlib.pyplot as plt dfs, _ = self.sumxrl() allIntensities = dfs.groupby(level=0)['all_intensities'].apply( np.hstack) allResponses = dfs.groupby(level=0)['all_responses'].apply(np.hstack) ntrial = dfs.groupby(level=0)['ntrial'].sum().unique() num = int(len(allIntensities) / 2) colorcodes = np.repeat(color4plot(num), 2, axis=0) # curve fitting and plotting for each condition fig, axes = plt.subplots(4, 4, figsize=(16, 10)) fig.suptitle(self.sub) thresh = [] for idx, label in enumerate(allResponses.index): intensities = abs(allIntensities[label]) responses = allResponses[label] # bin data and fit to PF combinedInten, combinedResp, combinedN = data.functionFromStaircase( intensities, responses, bins='unique') # optimal: bins='unique' fit = data.FitCumNormal(combinedInten, combinedResp, guess=None, expectedMin=0.5) # cumulative Gaussian # fit = data.FitLogistic(combinedInten, combinedResp, guess=None) # logistic # fit = data.FitWeibull(combinedInten, combinedResp, guess=[3, 0.5], display=1, expectedMin=0.5) #< --- somehow errors thresh.append(fit.inverse(0.76)) # threshold print(label + ': % 0.3f' % fit.ssq) # plot ax = axes.flatten()[idx] fontsize = 8 ax.plot(combinedInten, combinedResp, 'o', fillstyle='none', color='grey', alpha=.5, markersize=5) # plot combined data points # ax.plot(intensities, responses, 'o', color='grey', alpha=.5, markersize=3) # plot all data points # smoothInt = pylab.arange(min(combinedInten), max(combinedInten), 0.1) # x for fitted curve # smoothResp = fit.eval(smoothInt) # y for fitted curve smoothResp = pylab.arange(0.5, 1, 0.02) smoothInt = fit.inverse(smoothResp) ax.plot(smoothInt, smoothResp, '-', color=colorcodes[idx]) # plot fitted curve ax.plot([thresh[idx], thresh[idx]], [0, 0.76], '--', color='grey') ax.plot([0, thresh[idx]], [0.76, 0.76], '--', color='grey') ax.set_title(label + ' ' + 'threshold = %0.3f' % thresh[idx], fontsize=fontsize) ax.set_ylim([0.5, 1]) ax.set_xlim([0, 6]) ax.tick_params(axis='both', which='major', labelsize=fontsize - 2) plt.setp(axes[-1, :], xlabel='hue angle') plt.setp(axes[:, 0], ylabel='correctness') plt.savefig('pilot_data_fig/' + self.sub + '_' + self.xstr(self.sel_par) + '_' + self.xstr(self.sel_ses) + '_' + str(ntrial) + 'trl' + '.pdf') plt.show() return allResponses, thresh
def fitnoise(pool): allIntensities = 10 - pool['allIntensities'] allResponses = pool['allResponses'] # reverse the response ntrial = pool['ntrial'] # curve fitting and plotting for each condition res = {} # print('label: ' + 'centre, ' + 'std, ' + 'ssq') fig, axes = plt.subplots(1, len(pool['allIntensities']), figsize=(8, 6)) fig.suptitle(str(ntrial) + 'trials') for idx, label in enumerate(allResponses.index): res[label] = {} res[label]['intensities'] = allIntensities[label] res[label]['responses'] = allResponses[label] # plt.scatter(res[label]['intensities'], res[label]['responses']) res[label]['combinedInten'], res[label]['combinedResp'], res[label]['combinedN'] = \ data.functionFromStaircase(res[label]['intensities'], res[label]['responses'], bins=5) # bin data and fit to PF # plt.scatter(res[label]['combinedInten'], res[label]['combinedResp']) res[label]['sems'] = [ 1.0 / (n / sum(res[label]['combinedN'])) for n in res[label]['combinedN'] ] # sems is defined as 1/weight in Psychopy guess = [3, 0.5] # if label == 'hue_1p' or label == 'hue_2p': # print('detected') # guess = [8, 0.5] res[label]['fit'] = FitCumNormal( res[label]['combinedInten'], res[label]['combinedResp'], sems=res[label]['sems'], guess=None, expectedMin=0.5, lapse=0.01) # customized cumulative Gaussian # print(label + ':' + str(res[label]['fit'].params) + ', ' + str( # res[label]['fit'].ssq)) # a list with [centre, sd] for the Gaussian distribution forming the cumulative res[label]['thresh'] = res[label]['fit'].inverse(0.76) # threshold this_res = res[label] # print(label + ':' + str(this_res['fit'].params) + ', ' + str( # this_res['fit'].ssq)) # a list with [centre, sd] for the Gaussian distribution forming the cumulative if len(pool['allIntensities']) > 1: ax = axes.flatten()[idx] else: ax = axes fontsize = 8 for inten, resp, se in zip( this_res['combinedInten'], this_res['combinedResp'], this_res['sems']): # plot combined data points ax.plot(inten, resp, '.', alpha=0.5, markersize=300 / se) smoothResp = pylab.arange(0.01, 0.99, .02) smoothInt = this_res['fit'].inverse(smoothResp) # smoothInt = pylab.arange(0, 6.0, 0.05) # smoothResp = this_res['fit'].eval(smoothInt) ax.plot(smoothInt, smoothResp, '-') # plot fitted curve ax.plot([this_res['thresh'], this_res['thresh']], [0, 0.75], '--', color='grey') ax.plot([0, this_res['thresh']], [0.75, 0.75], '--', color='grey') ssq = np.round(this_res['fit'].ssq, decimals=3) # sum-squared error thre_std = np.round(np.sqrt(np.diagonal(this_res['fit'].covar))[0], decimals=3) ax.text(3.5, 0.55, 'ssq = ' + str(ssq), fontsize=fontsize) ax.text(3.5, 0.53, 'thre_error = ' + str(thre_std), fontsize=fontsize) ax.set_title(label + ' ' + 'threshold = %0.3f' % this_res['thresh'], fontsize=fontsize) ax.set_ylim([0.5, 1]) # ax.set_xlim([0, 6]) ax.tick_params(axis='both', which='major', labelsize=fontsize - 2) ax.set_xlabel('level of coherence (10 - std)') ax.set_ylabel('correctness') print(this_res['fit'].params[0], ' +/- ', thre_std) plt.show()
allRTs[condition].append(rt) if not coherence in coherence_resp[condition]: coherence_resp[condition][coherence] = [] coherence_resp[condition][coherence].append(float(resp)) if not coherence in coherence_rt[condition]: coherence_rt[condition][coherence] = [] coherence_rt[condition][coherence].append(rt) perf_ax = pylab.subplot(121) rt_ax = pylab.subplot(122) for condition in coherence_resp: # get combined data combinedInten, combinedResp, combinedN = data.functionFromStaircase( allCoherenceLevels[condition], allResponses[condition], 10 ) # combinedInten=coherence_resp.keys() # combinedInten.sort() # combinedResp=[np.mean(coherence_resp[x]) for x in combinedInten] # combinedRT=[np.mean(coherence_rt[x]) for x in combinedInten] # fit curve - in this case using a Weibull function fit = data.FitWeibull(combinedInten, combinedResp, guess=[0.2, 0.5]) # smoothInt = pylab.arange(min(combinedInten), max(combinedInten), 0.001) smoothInt = pylab.arange(0.0, max(combinedInten), 0.001) smoothResp = fit.eval(smoothInt) thresh = fit.inverse(0.8) print thresh # plot curve
allResponses.append(thisDat.data) dataFolder = os.path.split(thisFileName)[0] # just the path, not file name # plot each staircase in left hand panel pylab.subplot(121) colors = 'brgkcmbrgkcm' lines, names = [], [] for fileN, thisStair in enumerate(allIntensities): # lines.extend(pylab.plot(thisStair)) # uncomment for a legend for files # names = files[fileN] pylab.plot(thisStair, label=files[fileN]) # pylab.legend() # get combined data i, r, n = data.functionFromStaircase(allIntensities, allResponses, bins='unique') combinedInten, combinedResp, combinedN = i, r, n combinedN = pylab.array(combinedN) # convert to array so we can do maths # fit curve fit = data.FitWeibull(combinedInten, combinedResp, expectedMin=expectedMin, sems=1.0 / combinedN) smoothInt = pylab.arange(min(combinedInten), max(combinedInten), 0.001) smoothResp = fit.eval(smoothInt) thresh = fit.inverse(threshVal) print(thresh) # plot curve
allResponses.append( thisDat.loops[0].data ) dataFolder = os.path.split(thisFileName)[0] #just the path, excluding file name #plot each staircase in left hand panel pylab.subplot(121) colors = 'brgkcmbrgkcm' lines, names = [],[] for fileN, thisStair in enumerate(allIntensities): #lines.extend(pylab.plot(thisStair)) #uncomment these lines to get a legend for files #names = files[fileN] pylab.plot(thisStair, label=files[fileN]) #pylab.legend() #get combined data combinedInten, combinedResp, combinedN = \ data.functionFromStaircase(allIntensities, allResponses, bins='unique') combinedN = pylab.array(combinedN) #convert to array so we can do maths with them #fit curve fit = data.FitWeibull(combinedInten, combinedResp, expectedMin=expectedMin, sems = 1.0/combinedN) smoothInt = pylab.arange(min(combinedInten), max(combinedInten), 0.001) smoothResp = fit.eval(smoothInt) thresh = fit.inverse(threshVal) print thresh #plot curve pylab.subplot(122) pylab.plot(smoothInt, smoothResp, 'k-') pylab.plot([thresh, thresh],[0,threshVal],'k--') #vertical dashed line pylab.plot([0, thresh],[threshVal,threshVal],'k--') #horizontal dashed line
allIntensities.append( thisDat.intensities ) allResponses.append( thisDat.data ) #plot each staircase pylab.subplot(121) colors = 'brgkcmbrgkcm' lines, names = [],[] for fileN, thisStair in enumerate(allIntensities): #lines.extend(pylab.plot(thisStair)) #names = files[fileN] pylab.plot(thisStair, label=files[fileN]) #pylab.legend() #get combined data combinedInten, combinedResp, combinedN = \ data.functionFromStaircase(allIntensities, allResponses, 5) #fit curve fit = data.FitWeibull(combinedInten, combinedResp, guess=[0.2, 0.5]) smoothInt = pylab.arange(min(combinedInten), max(combinedInten), 0.001) smoothResp = fit.eval(smoothInt) thresh = fit.inverse(0.8) print thresh #plot curve pylab.subplot(122) pylab.plot(smoothInt, smoothResp, 'k-') pylab.plot([thresh, thresh],[0,0.8],'k--'); pylab.plot([0, thresh],[0.8,0.8],'k--') pylab.title('threshold = %0.3f' %(thresh)) #plot points pylab.plot(combinedInten, combinedResp, 'ko') pylab.ylim([0,1])
def fitData(stairs, percent): allIntensities, allResponses = [], [] for s in stairs.staircases: allIntensities.append(s.intensities) allResponses.append(s.data) for s in stairs.staircases: print "Mean for condition ", s.condition['label'], "=", average( s.reversalIntensities), "std=", std(s.reversalIntensities) #plot each condition pylab.subplot(221) #for stairNumber, thisStair in enumerate(allIntensities): pylab.plot(allIntensities[0], 'o-', label=stairs.staircases[0].condition['label']) pylab.xlabel('Trials') pylab.ylabel('Speed [cm/s]') pylab.legend() # Get combined data combinedInten, combinedResp, combinedN = data.functionFromStaircase( allIntensities, allResponses, 10) # Fit curve - in this case using a Weibull function fit = data.FitFunction('weibullTAFC', combinedInten, combinedResp, guess=None) #fit = data.FitCumNormal(combinedInten,combinedResp) intensitiesDomainInterp = pylab.arange(min(allIntensities[0]), max(allIntensities[0]), 0.01) smoothResponses = fit.eval(intensitiesDomainInterp) thresh = fit.inverse(percent) #Plot fitted curve pylab.subplot(222) pylab.axis(xmin=min(allIntensities[0]), xmax=max(allIntensities[0])) pylab.xlabel('Speed [cm/s]') pylab.ylabel('Probability') pylab.plot(intensitiesDomainInterp, smoothResponses, '-') pylab.plot([thresh, thresh], [0, percent], '--') pylab.plot([0, thresh], [percent, percent], '--') pylab.title('Threshold at ' + str(percent) + '= %0.3f' % (thresh)) # Plot points pylab.plot(combinedInten, combinedResp, 'o') pylab.ylim([0, 1]) # SECOND CONDITION, the plots are in a second row, under pylab.subplot(223) #for stairNumber, thisStair in enumerate(allIntensities): pylab.plot(allIntensities[1], 'o-', label=stairs.staircases[1].condition['label']) pylab.xlabel('Trials') pylab.ylabel('Speed [cm/s]') pylab.legend() # Get combined data combinedInten, combinedResp, combinedN = data.functionFromStaircase( allIntensities[1], allResponses[1], 10) #fit curve - in this case using a Weibull function #fit = data.FitFunction('weibullTAFC',combinedInten, combinedResp, guess=None) fit = data.FitCumNormal(combinedInten, combinedResp) intensitiesDomainInterp = pylab.arange(min(allIntensities[1]), max(allIntensities[1]), 0.01) smoothResponses = fit.eval(intensitiesDomainInterp) thresh = fit.inverse(percent) #print "Threshold at " + str(percent) +"% with Cumulative Normal= ",thresh #Plot fitted curve pylab.subplot(224) pylab.axis(xmin=min(allIntensities[1]), xmax=max(allIntensities[1])) pylab.xlabel('Speed [cm/s]') pylab.ylabel('Probability') pylab.plot(intensitiesDomainInterp, smoothResponses, '-') pylab.plot([thresh, thresh], [0, percent], '--') pylab.plot([0, thresh], [percent, percent], '--') pylab.title('Threshold at ' + str(percent) + '= %0.3f' % (thresh)) # Plot points pylab.plot(combinedInten, combinedResp, 'o') pylab.ylim([0, 1]) pylab.show()