home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / Utilities / Quick3 / LogLikelihood.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-01  |  1002 b   |  42 lines  |  [TEXT/MMCC]

  1. /*
  2. LogLikelihood.c
  3. Copyright (c) 1990-4 Denis G. Pelli
  4. Calculate log likelihood of the data for a given psychometric function.
  5. If the psychometric function indicates that the parameters are out of bounds,
  6. then LogLikelihood() returns the lowest possible log likelihood, minus infinity. 
  7. If your machine doesn't deal in infinities, then replace 1.0/0.0 by DBL_MAX in
  8. the definition of INF.
  9.  
  10. The third argument is a pointer to a psychometric function, e.g. Weibull.c
  11.  
  12. HISTORY:
  13. 4/7/90 dgp wrote it
  14. 8/24/91 dgp cosmetic
  15. */
  16. #include "Quick3.h"
  17.  
  18. #ifndef INF
  19.     #define INF (1.0/0.0)
  20. #endif
  21.  
  22. double LogLikelihood(dataRecord *data,paramRecord *params,
  23.     PsychometricFunctionPtr PsychFun)
  24. {
  25.     double LL,p;
  26.     long n,i;
  27.     contrastRecord *cPtr;
  28.  
  29.     LL=0.0;
  30.     for(i=0;i<data->contrasts;i++){
  31.         cPtr=&data->c[i];
  32.         p = (*PsychFun)(cPtr->contrast, params);
  33.         if(p==ILLEGAL_PARAMETERS)return -INF;
  34.         n=cPtr->correct;
  35.         if(n>0L) LL += n*log(p);
  36.         n=cPtr->trials - cPtr->correct;
  37.         if(n>0L) LL += n*log(1.0-p);
  38.     }
  39.     return LL;
  40. }
  41.  
  42.