@@ -452,7 +452,7 @@ def compute_n_trials(trials):
452452 return trials ['choice' ].shape [0 ]
453453
454454
455- def compute_psychometric (trials , signed_contrast = None , block = None ):
455+ def compute_psychometric (trials , signed_contrast = None , block = None , plotting = False ):
456456 """
457457 Compute psychometric fit parameters for trials object
458458
@@ -479,13 +479,22 @@ def compute_psychometric(trials, signed_contrast=None, block=None):
479479 prob_choose_right , contrasts , n_contrasts = compute_performance (trials , signed_contrast = signed_contrast , block = block ,
480480 prob_right = True )
481481
482- psych , _ = psy .mle_fit_psycho (
483- np .vstack ([contrasts , n_contrasts , prob_choose_right ]),
484- P_model = 'erf_psycho_2gammas' ,
485- parstart = np .array ([0. , 40. , 0.1 , 0.1 ]),
486- parmin = np .array ([- 50. , 10. , 0. , 0. ]),
487- parmax = np .array ([50. , 50. , 0.2 , 0.2 ]),
488- nfits = 10 )
482+ if plotting :
483+ psych , _ = psy .mle_fit_psycho (
484+ np .vstack ([contrasts , n_contrasts , prob_choose_right ]),
485+ P_model = 'erf_psycho_2gammas' ,
486+ parstart = np .array ([0. , 40. , 0.1 , 0.1 ]),
487+ parmin = np .array ([- 50. , 10. , 0. , 0. ]),
488+ parmax = np .array ([50. , 50. , 0.2 , 0.2 ]),
489+ nfits = 10 )
490+ else :
491+
492+ psych , _ = psy .mle_fit_psycho (
493+ np .vstack ([contrasts , n_contrasts , prob_choose_right ]),
494+ P_model = 'erf_psycho_2gammas' ,
495+ parstart = np .array ([np .mean (contrasts ), 20. , 0.05 , 0.05 ]),
496+ parmin = np .array ([np .min (contrasts ), 0. , 0. , 0. ]),
497+ parmax = np .array ([np .max (contrasts ), 100. , 1 , 1 ]))
489498
490499 return psych
491500
@@ -596,15 +605,15 @@ def plot_psychometric(trials, ax=None, title=None, **kwargs):
596605 contrasts_fit = np .arange (- 100 , 100 )
597606
598607 prob_right_50 , contrasts_50 , _ = compute_performance (trials , signed_contrast = signed_contrast , block = 0.5 , prob_right = True )
599- pars_50 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.5 )
608+ pars_50 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.5 , plotting = True )
600609 prob_right_fit_50 = psy .erf_psycho_2gammas (pars_50 , contrasts_fit )
601610
602611 prob_right_20 , contrasts_20 , _ = compute_performance (trials , signed_contrast = signed_contrast , block = 0.2 , prob_right = True )
603- pars_20 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.2 )
612+ pars_20 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.2 , plotting = True )
604613 prob_right_fit_20 = psy .erf_psycho_2gammas (pars_20 , contrasts_fit )
605614
606615 prob_right_80 , contrasts_80 , _ = compute_performance (trials , signed_contrast = signed_contrast , block = 0.8 , prob_right = True )
607- pars_80 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.8 )
616+ pars_80 = compute_psychometric (trials , signed_contrast = signed_contrast , block = 0.8 , plotting = True )
608617 prob_right_fit_80 = psy .erf_psycho_2gammas (pars_80 , contrasts_fit )
609618
610619 cmap = sns .diverging_palette (20 , 220 , n = 3 , center = "dark" )
0 commit comments