Esempio n. 1
0
  /********************
  ** seek_confidence **
  *********************
  ** Pass this routine an array of 5 scores PLUS a new score.
  ** This routine tries the new score in place of each of
  ** the other five scores to determine if the new score,
  ** when replacing one of the others, improves the confidence
  ** half-interval.
  ** Return 0 if failure.  Original 5 scores unchanged.
  ** Return -1 if success.  Also returns new half-interval,
  ** mean, and standard deviation of the sample.
  */
  static int seek_confidence( double scores[5],
  		double *newscore,
  		double *c_half_interval,
  		double *smean,
  		double *sdev)
  {
  double sdev_to_beat;    /* Original sdev to be beaten */
  double temp;            /* For doing a swap */
  int is_beaten;          /* Indicates original was beaten */
  int i;                  /* Index */

  /*
  ** First calculate original standard deviation
  */
  calc_confidence(scores,c_half_interval,smean,sdev);
  sdev_to_beat=*sdev;
  is_beaten=-1;

  /*
  ** Try to beat original score.  We'll come out of this
  ** loop with a flag.
  */
  for(i=0;i<5;i++)
  {
  	temp=scores[i];
  	scores[i]=*newscore;
  	calc_confidence(scores,c_half_interval,smean,sdev);
  	scores[i]=temp;
  	if(sdev_to_beat>*sdev)
  	{       is_beaten=i;
  		sdev_to_beat=*sdev;
  	}
  }

  if(is_beaten!=-1)
  {       scores[is_beaten]=*newscore;
  	return(-1);
  }
  return(0);
  }
Esempio n. 2
0
/**************************
** bench_with_confidence **
***************************
** Given a benchmark id that indicates a function, this routine
** repeatedly calls that benchmark, seeking to collect and replace
** scores to get 5 that meet the confidence criteria.
**
** The above is mathematically questionable, as the statistical theory
** depends on independent observations, and if we exchange data points
** depending on what we already have then this certainly violates
** independence of the observations. Hence I changed this so that at
** most 30 observations are done, but none are deleted as we go
** along. We simply do more runs and hope to get a big enough sample
** size so that things stabilize. Uwe F. Mayer
**
** Return 0 if ok, -1 if failure.  Returns mean
** and std. deviation of results if successful.
*/
static int bench_with_confidence(int fid,       /* Function id */
        double *mean,                   /* Mean of scores */
        double *stdev,                  /* Standard deviation */
        ulong *numtries)                /* # of attempts */
{
double myscores[30];            /* Need at least 5 scores, use at most 30 */
double c_half_interval;         /* Confidence half interval */
int i;                          /* Index */
/* double newscore; */          /* For improving confidence interval */

/*
** Get first 5 scores.  Then begin confidence testing.
*/
for (i=0;i<5;i++)
{       (*funcpointer[fid])();
        myscores[i]=getscore(fid);
#ifdef DEBUG
	printf("score # %d = %g\n", i, myscores[i]);
#endif
}
*numtries=5;            /* Show 5 attempts */

/*
** The system allows a maximum of 30 tries before it gives
** up.  Since we've done 5 already, we'll allow 25 more.
*/

/*
** Enter loop to test for confidence criteria.
*/
while(1)
{
        /*
        ** Calculate confidence. Should always return 0.
        */
        if (0!=calc_confidence(myscores,
		*numtries,
                &c_half_interval,
                mean,
                stdev)) return(-1);

        /*
        ** Is the length of the half interval 5% or less of mean?
        ** If so, we can go home.  Otherwise, we have to continue.
        */
        if(c_half_interval/ (*mean) <= (double)0.05)
                break;

#ifdef OLDCODE
#undef OLDCODE
#endif
#ifdef OLDCODE
/* this code is no longer valid, we now do not replace but add new scores */
/* Uwe F. Mayer */
	      /*
	      ** Go get a new score and see if it
	      ** improves existing scores.
	      */
	      do {
		      if(*numtries==10)
			      return(-1);
		      (*funcpointer[fid])();
		      *numtries+=1;
		      newscore=getscore(fid);
	      } while(seek_confidence(myscores,&newscore,
		      &c_half_interval,mean,stdev)==0);
#endif
	/* We now simply add a new test run and hope that the runs
           finally stabilize, Uwe F. Mayer */
	if(*numtries==30) return(-1);
	(*funcpointer[fid])();
	myscores[*numtries]=getscore(fid);
#ifdef DEBUG
	printf("score # %ld = %g\n", *numtries, myscores[*numtries]);
#endif
	*numtries+=1;
}

return(0);
}
Esempio n. 3
0
/**************************
** bench_with_confidence **
***************************
** Given a benchmark id that indicates a function, this
** routine repeatedly calls that benchmark, seeking
** to collect enough scores to get 5 that meet the confidence
** criteria.  Return 0 if ok, -1 if failure.
** Returns mean ans std. deviation of results if successful.
*/
static int bench_with_confidence(int fid,       /* Function id */
        double *mean,                   /* Mean of scores */
        double *stdev,                  /* Standard deviation */
        ulong *numtries)                /* # of attempts */
{
double myscores[5];             /* Need at least 5 scores */
double c_half_interval;         /* Confidence half interval */
int i;                          /* Index */
double newscore;                /* For improving confidence interval */


/*
** Get first 5 scores.  Then begin confidence testing.
*/
TotalTime = (double)0.0;
for (i=0;i<5;i++)
{       (*funcpointer[fid])();
        myscores[i]=getscore(fid);
	TotalTime += CurrTime;
}
*numtries=5;            /* Show 5 attempts */

/*
** The system allows a maximum of 10 tries before it gives
** up.  Since we've done 5 already, we'll allow 5 more.
*/

/*
** Enter loop to test for confidence criteria.
*/
while(1)
{
        /*
        ** Calculate confidence.
        */
        calc_confidence(myscores,
                &c_half_interval,
                mean,
                stdev);

        /*
        ** Is half interval 5% or less of mean?
        ** If so, we can go home.  Otherwise,
        ** we have to continue.
        */
        if(c_half_interval/ (*mean) <= (double)0.05)
                break;

        /*
        ** Go get a new score and see if it
        ** improves existing scores.
        */
        do {
                if(*numtries==10)
                        return(-1);
                (*funcpointer[fid])();
                *numtries+=1;
                newscore=getscore(fid);
        } while(seek_confidence(myscores,&newscore,
                &c_half_interval,mean,stdev)==0);
}

return(0);
}