home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / autopsp.zip / REGRESS / RFIND.CPP < prev    next >
C/C++ Source or Header  |  1995-07-23  |  3KB  |  106 lines

  1. // RangeFinder
  2. //  RangeFinder method definitions
  3.  
  4. #include "rfind.h"
  5.  
  6.  
  7. RangeFinder::RangeFinder(void)
  8. {
  9.   NumValues=0;
  10.   StdDev=0;
  11.   Average=0;
  12.   Range=0;
  13.   UPI=0;
  14.   LPI=0;
  15.  
  16. }
  17.  
  18. void RangeFinder::CalcStdDev(void)
  19. {
  20.   double sum=0;
  21.   double ave_sum=0;
  22.   double holding=0;
  23.   DataPoint *temp;
  24.  
  25.  
  26.  
  27.   Restart();
  28.   NumValues=*(int *)(Retrieve(LL_NUM_NODES));
  29.  
  30.   do{
  31.     temp=(DataPoint*)Retrieve(LL_DATA);
  32.  
  33.     holding=temp->y - B0 - (B1*temp->x);
  34.     sum+=(holding * holding);
  35.     ave_sum+=temp->x;
  36.  
  37.     Next();
  38.   } while (AtEnd == FALSE);       // Count objects until out of objects
  39.  
  40.   Average=ave_sum/NumValues;      // Save the average for later use.
  41.  
  42.   sum*=(1/(NumValues-2));         // Make the variance.
  43.  
  44.   StdDev=sqrt(sum);               // Make the StdDev.
  45. }
  46.  
  47. void RangeFinder::CalcRange(double percent, char *filename, double cur_estimate)
  48. {
  49.   double desired_area=0;          // Desired answer from simpsons.
  50.   double found_area=0;            // Area found in last integration.
  51.   double cur_guess_r=3.2;         // 3.2 > than table value for .95 with n=3
  52.   double cur_guess_l=0;           // cur_guess'es are the bounds for the search.
  53.   double guess=0;                 // current guess for integration
  54.   double sum=0;                   // For the summation.
  55.   double thingy=0;                // Thing to the left of the other two things.  (Yeah, OK.)
  56.   double holding;                 // temporary value.
  57.  
  58.   DataPoint *temp;
  59.  
  60.   AddFile(filename);              // Then add the file requested.
  61.  
  62.   CalcLR();                       // Then figure out the LR parameters.
  63.  
  64.   CalcStdDev();                   // Then figure out the StdDev
  65.  
  66.   SetN(NumValues - 2);            // Set the nuber for T distribution.
  67.  
  68.                                   // Finds the value we want returned from T dist.
  69.   desired_area+=(100-percent)/2;  //Hmmmm  Seems odd.
  70.   desired_area=(1-(desired_area * .01));
  71.  
  72.                                   // Now calculate the right hand thingy.
  73.                                   // First to the summation.
  74.   do{
  75.     temp=(DataPoint*)Retrieve(LL_DATA);
  76.  
  77.     holding=(temp->x - Average);
  78.     sum+=(holding * holding);
  79.  
  80.     Next();
  81.   } while (AtEnd == FALSE);       // Count objects until out of objects
  82.  
  83.   thingy=1 + (1/NumValues) + ((cur_estimate-Average)*(cur_estimate-Average))/sum;
  84.   thingy=sqrt(thingy);            // Thingy calculated.
  85.  
  86.   while(.00005 < fabs(found_area - desired_area)){
  87.     guess=cur_guess_l + ((cur_guess_r - cur_guess_l)/2);
  88.                                   // Integrate from -INF to guess on CTD curve.
  89.     found_area=DoMath(INFINITY,guess,1);
  90.     if(found_area>desired_area) cur_guess_r=guess;
  91.     if(found_area<desired_area) cur_guess_l=guess;
  92.   }
  93.  
  94.                                   // My favorite line of code:
  95.  
  96.   Range = guess * StdDev * thingy;// Yes, I'm a programmer.
  97.  
  98.   PLOC=B0 + (B1 * cur_estimate);
  99.  
  100.   UPI = PLOC + Range;             // Upper calculation.
  101.   LPI = PLOC - Range;             // Lower calculation.
  102.   if (LPI<1) LPI=1;               // Range checking.
  103. }
  104.  
  105.  
  106.