plt.subplot(1,1,1) plt.plot(StimLevels, pObs,'*r') # Plot a smoother fitted function smoothrang = np.linspace(StimLevels[0], StimLevels[-1], 100 ) LogLikX, smoothprob=ProbitLogit(params0, smoothrang, NumPos, Ntrials, LowerAsymptote, ProbitOrLogit,0) plt.plot(smoothrang, smoothprob, '--b', label='init conds'); #plt.plot(StimLevels,p0,'.--b', label='initial conditions') plt.title('Fit data'); plt.xlabel('Stimulus Intensity'); plt.ylabel('Probability Correct') ## now do the search #[params,chisqLL]=fminsearch('ProbitLogit',params0,[], StimLevels, NumPos, Ntrials, # LowerAsymptote, ProbitOrLogit,1) out = fitpf(params0, StimLevels, NumPos, Ntrials, LowerAsymptote, ProbitOrLogit, output_param_search=True) pfinal = out[0] # Y params0 = out[0] searched_params = np.array( out[1] ) LogLikf, probExpect=ProbitLogit(pfinal, StimLevels, NumPos, Ntrials, LowerAsymptote, ProbitOrLogit,1) if plot_opt in ('both','pf'): # Plot a smoother fitted function smoothrang = np.linspace(StimLevels[0], StimLevels[-1], 100 ) LogLikX, smoothprob=ProbitLogit(pfinal, smoothrang, NumPos, Ntrials, LowerAsymptote, ProbitOrLogit,0) plt.plot(smoothrang, smoothprob, '-b', label='LL search'); error=np.sqrt(probExpect*(1-probExpect)/Ntrials); plt.errorbar(StimLevels,probExpect,error, fmt=None, ecolor='b');
plt.figure() StimLevels=np.arange(6) Ntrials=np.ones(6) ProbitOrLogit=2 LowerAsymptote=0.5 plt.plot(StimLevels,hw2res[3],'b*', label='$Pc$') plt.plot(StimLevels,unb[0],'rx', label='$Pc_{max}$') smoothrang = np.linspace(StimLevels[0], StimLevels[-1], 100 ) # Fit to Pc # 2 = normal slope (Palamedes way) # [3,2.0] = guess paramsfit = pf.fitpf( [3,2.0], StimLevels, hw2res[3], Ntrials, LowerAsymptote, ProbitOrLogit) # Plot a smoother fitted function LogLikX, smoothprob=pf.ProbitLogit(paramsfit, smoothrang, hw2res[3], Ntrials, LowerAsymptote, ProbitOrLogit,0) plt.plot(smoothrang, smoothprob, 'b--', label='Fit to $Pc$'); print "Fit to Pc: %s" % str(paramsfit) # Fit to Pc_max paramsfit2 = pf.fitpf( [3,2.0], StimLevels, unb[0], Ntrials, LowerAsymptote, ProbitOrLogit) LogLikX, smoothprob=pf.ProbitLogit(paramsfit2, smoothrang, hw2res[3], Ntrials, LowerAsymptote, ProbitOrLogit,0) plt.plot(smoothrang, smoothprob, 'r--', label='Fit to $Pc_{max}$'); print "Fit to Pc_max: %s" % str(paramsfit2) plt.legend(loc='best') plt.show() #fake_dprime = fake_dprime( prins_tab62_h, prins_tab62_f )