# FitWeibTAFCT

**URL:** <https://psychtoolbox.discourse.group/t/fitweibtafct/981>\
**Category:** Uncategorized\
**Created:** [October 13, 2000, 3:44am UTC](https://psychtoolbox.discourse.group/t/fitweibtafct/981 "2000-10-13T03:44:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [October 13, 2000, 3:44am UTC](https://psychtoolbox.discourse.group/t/fitweibtafct/981/1 "2000-10-13T03:44:56Z")

</div>

Hi,  
I tried to fit some of my data with FitWeibTAFCT and I keep getting   
this:   
  
Warning: Divide by zero.  

> \> In Macintosh HD:MATLAB 5:Toolbox:optim:fminu.m at line 134

 In Macintosh HD:MATLAB   
5:Toolbox:PsychToolbox:Psychometric:FitWeibTAFC.m at line 59  
 In Macintosh HD:Desktop Folder:FitWeibullTAFCTest.m at line 17  
  
  
This only happens for some input numbers. Below is an example of   
input levels that don't work [4 5 6 7 8] and input levels that work  
[1 2 3 4 5]. Does anybody know why is this happening?  
  
Duje Tadin  
  
  
% FitWeibTAFCTest  
  
% Set up some input levels  
 inputs = [4 5 6 7 8]'; % THIS DOESN'T WORK  
% inputs = [1 2 3 4 5]'; % THESE NUMBERS WORK JUST FINE  
  
% Cook some data  
nCorrect = [52 60 75 90 98]';  
nError = 100-nCorrect;  
  
% Do the fit  
[alpha,beta,thresh] = FitWeibTAFC(inputs,nCorrect,nError);  
  
% Compute predicted psychometric function  
pInputs = 1:0.1:9;  
predict = ComputeWeibTAFC(pInputs,alpha,beta);  
  
% Make a plot  
hold off  
plot(inputs,nCorrect./(nCorrect+nError),'+');  
hold on  
plot(pInputs,predict,'

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [October 13, 2000, 9:42pm UTC](https://psychtoolbox.discourse.group/t/fitweibtafct/981/2 "2000-10-13T21:42:08Z")

</div>

Dear Duje,  
  
The problem was that FitWeibTAFC (also FitWeibAlphaTAFC, FitWeibAlphaYN)  
were making a pretty dumb guess about the initial value of parameter alpha  
when such was not supplied initially. The routines were always starting  
their search at a value of alpha = 1, and in the second case of input  
levels you used, this value was so far off that the numerical search never  
converged.  
  
I modified all three functions to initialize alpha to the mean value of the  
input levels. This seems like a smarter guess and works for both test  
cases you provided. You can also supply a guess based on your knowledge  
of the particular data you are trying to fit, but I'm guessing this won't  
be necessary with the modified versions.  
  
Thanks for identifying this bug. I've attached the fixed routines, they  
will propagate in the next version of the toolbox.  
  
Best,  
  
David

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [October 16, 2000, 4:01pm UTC](https://psychtoolbox.discourse.group/t/fitweibtafct/981/3 "2000-10-16T16:01:38Z")

</div>

I noticed that the CopyWindow routine seems to wait for a screen refresh   
before returning when it is copying to the onscreen window (but not to   
offscreen windows). Is there some way to disable this? I want to draw   
multiple small stimuli to the screen as quickly as possible, and one way   
to do this is to copy from an offscreen window to an onscreen window   
multiple times rather than redrawing the individual components of each   
stimulus multiple times.  
  
I am using:  
  
 SCREEN('CopyWindow', w2, w1, rect2, rect1, 'srcCopyQuickly');  
  
Where w2 is an offscreen window and w1 is an onscreen window. This takes   
about 11 ms (1 screen refresh), but coping the same image to an offscreen   
window takes 3 ms or less.  
  
Is CopyWindow always faster than the SCREEN drawing commands (FillRect,   
etc.)?  
  
keith
