コード例 #1
0
ファイル: clientTask.cpp プロジェクト: Shuyoung/cisst
void clientTask::EventWriteHandler(const value_type & data)
{
    if (this->BenchmarkDoneMember == false) {
        if (this->NumberOfskippedElement < confNumberOfSamplesToSkip) {
            this->NumberOfskippedElement++;
        } else {
            double originalTime = data.Timestamp();
            double currentTime = TimeServer->GetRelativeTime();
            this->Samples.Element(this->SamplesCollected) = (currentTime - originalTime);
            this->SamplesCollected++;
        }
    }
    if (this->SamplesCollected == confNumberOfSamples) {
        this->BenchmarkDoneMember = true;
        double average = Samples.SumOfElements() / Samples.size();
        double min = 0.0;
        double max = 0.0;
        Samples.MinAndMaxElement(min, max);
        std::cout << "csc: client->server->client: client write data (queued), server triggers event (queued)" << std::endl
                  << "csc: Client period (ms): " << cmnInternalTo_ms(confClientPeriod) << std::endl
                  << "csc: Server period (ms): " << cmnInternalTo_ms(confServerPeriod) << std::endl
                  << "csc: Size of elements used (in bytes): " << sizeof(value_type) << std::endl
                  << "csc: Number of samples: " << this->SamplesCollected << std::endl
                  << "csc: Average (ms): " << cmnInternalTo_ms(average) << std::endl
                  << "csc: Standard deviation (ms): " << cmnInternalTo_ms(StandardDeviation(this->Samples)) << std::endl
                  << "csc: Min (ms): " << cmnInternalTo_ms(min) << std::endl
                  << "csc: Max (ms): " << cmnInternalTo_ms(max) << std::endl;
        this->SamplesCollected++; // just to avoid printing results again
    }
}
コード例 #2
0
ファイル: Histogram.cpp プロジェクト: lilothar/walle
std::string Histogram::ToString() const {
  std::string r;
  char buf[200];
  snprintf(buf, sizeof(buf),
           "Count: %.0f  Average: %.4f  StdDev: %.2f\n",
           _num, Average(), StandardDeviation());
  r.append(buf);
  snprintf(buf, sizeof(buf),
           "Min: %.4f  Median: %.4f  Max: %.4f\n",
           (_num == 0.0 ? 0.0 : _min), Median(), _max);
  r.append(buf);
  r.append("------------------------------------------------------\n");
  const double mult = 100.0 / _num;
  double sum = 0;
  for (int b = 0; b < kNumBuckets; b++) {
    if (_buckets[b] <= 0.0) continue;
    sum += _buckets[b];
    snprintf(buf, sizeof(buf),
             "[ %7.0f, %7.0f ) %7.0f %7.3f%% %7.3f%% ",
             ((b == 0) ? 0.0 : kBucketLimit[b-1]),      // left
             kBucketLimit[b],                           // right
             _buckets[b],                               // count
             mult * _buckets[b],                        // percentage
             mult * sum);                               // cumulative percentage
    r.append(buf);

    // Add hash marks based on percentage; 20 marks for 100%.
    int marks = static_cast<int>(20*(_buckets[b] / _num) + 0.5);
    r.append(marks, '#');
    r.push_back('\n');
  }
  return r;
}
コード例 #3
0
ファイル: unser_float.c プロジェクト: tiagojc/IBTSFIF
//Histogram *Unser(Image *img)
float *Unser(Image *img)
{
  Histogram *h = NULL;
  float sum[4][511], dif[4][511], *val=NULL;
  float mean, contrast, correlation;
  int i;

  val = (float*) calloc(SIZE,sizeof(float));

  ComputeHistograms(img, sum, dif);

  for (i=0; i<4; i++){
    mean = Mean(sum[i]);
    val[i * 8 + 0] = mean;
    contrast = Contrast(dif[i]);
    val[i * 8 + 1] = contrast;// / 255.0;
    correlation = Correlation(sum[i], mean, contrast);
    val[i * 8 + 2] = (correlation);// + 32512.5) / 255.0;
    val[i * 8 + 3] = Energy(sum[i], dif[i]);// * 255.0 ;
    val[i * 8 + 4] = Entropy(sum[i], dif[i]);// * 255.0 / 5.4168418;
    val[i * 8 + 5] = Homogeneity(dif[i]);// * 255.0;
    val[i * 8 + 6] = MaximalProbability(sum[i]);// * 255.0;
    val[i * 8 + 7] = StandardDeviation(contrast, correlation);// *sqrt(2);
  }

  //h = CreateHistogram(SIZE);
  //LinearNormalizeHistogram(h->v, val, 255.0, SIZE);

  //return(h);
  return(val);
}
コード例 #4
0
/*---------------------------------------------------------------------------*/
void PrintNormMatch(FILE *File,
                    int NumParams,
                    PROTOTYPE *Proto,
                    FEATURE Feature) {
/*
 **	Parameters:
 **		File		open text file to dump match debug info to
 **		NumParams	# of parameters in proto and feature
 **		Proto[]		array of prototype parameters
 **		Feature[]	array of feature parameters
 **	Globals: none
 **	Operation: This routine dumps out detailed normalization match info.
 **	Return: none
 **	Exceptions: none
 **	History: Wed Jan  2 09:49:35 1991, DSJ, Created.
 */
  int i;
  FLOAT32 ParamMatch;
  FLOAT32 TotalMatch;

  for (i = 0, TotalMatch = 0.0; i < NumParams; i++) {
    ParamMatch = ((ParamOf (Feature, i) - Mean (Proto, i)) /
      StandardDeviation (Proto, i));

    fprintf (File, " %6.1f", ParamMatch);

    if (i == CharNormY || i == CharNormRx)
      TotalMatch += ParamMatch * ParamMatch;
  }
  fprintf (File, " --> %6.1f (%4.2f)\n",
    TotalMatch, NormEvidenceOf (TotalMatch));

}                                /* PrintNormMatch */
コード例 #5
0
/*  Calcula a regressao uni-variavel de lag 1.
    Equacao retirada de:
    Goncalves, MF (2009, MT).
    Previsao de chuva com auxilio de radar de tempo visando a um sistema de alerta antecipado de cheias em areas urbanas.
    Equacao 4.12.
    Parametro 1: vetor tipo double com o valor da variavel vec para cada intervalo de tempo.
    Parametro 2: tamanho do vetor. */
double Regression(double *vec, int length)
{
    double vec_mean, autocor_coeff, std_deviation, rand_num;

    vec_mean = ArithmeticMean(vec, length);
    autocor_coeff = AutocorrelationLag1(vec, length);
    std_deviation = StandardDeviation(vec, length);
    rand_num = (rand() % 10000); /* Gera numero aleatorio entre 0 e 9999. */
    rand_num /= 9999; /* Normaliza entre 0.0000 e 1.0000 o numero aleatorio. */

    return vec_mean + ((vec[length - 1] - vec_mean) * autocor_coeff) + (rand_num * std_deviation * sqrt(1 - (autocor_coeff * autocor_coeff)));
}
コード例 #6
0
void RunningStats::Print(FILE * pFile, const char * header) const
    {
    fprintf (pFile, "\n%s\n", header);
    fprintf (pFile, "NumDataValues:     %ld\n", NumDataValues());
    fprintf (pFile, "Mean:              %f\n", Mean());
    fprintf (pFile, "Variance:          %f\n", Variance());
    fprintf (pFile, "StandardDeviation: %f\n", StandardDeviation());
    fprintf (pFile, "Skewness:          %f\n", Skewness());
    fprintf (pFile, "Kurtosis:          %f\n", Kurtosis());
    fprintf (pFile, "Maximum:           %f\n", Maximum());
    fprintf (pFile, "Minimum:           %f\n", Minimum());
    return;
    }
コード例 #7
0
ファイル: clientTask.cpp プロジェクト: Shuyoung/cisst
void clientTask::ShowResults()
{
    double average = Results.SumOfElements() / Results.size();
    double min = 0.0;
    double max = 0.0;
    Results.MinAndMaxElement(min, max);

    std::cout << std::endl << std::endl
              << "--------------------------------------------------------------------" << std::endl
              << "Size of elements used (in bytes) : " << sizeof(mtsDouble) << std::endl
              << "Number of samples: " << NumberOfSamplesCollected << std::endl
              << "avg (ms) : " << cmnInternalTo_ms(average) << std::endl
              << "std (ms) : " << cmnInternalTo_ms(StandardDeviation(Results)) << std::endl
              << "min (ms) : " << cmnInternalTo_ms(min) << std::endl
              << "max (ms) : " << cmnInternalTo_ms(max) << std::endl;
}
コード例 #8
0
ファイル: bootstrap_errors.cpp プロジェクト: streeto/imfit
void BootstrapErrors( double *bestfitParams, mp_par *parameterLimits, bool paramLimitsExist, 
					ModelObject *theModel, double ftol, int nIterations, int nFreeParams,
					bool usingCashStatistic )
{
  double  *paramsVect, *paramSigmas;
  double  **paramArray;
  double  lower, upper, plus, minus, halfwidth;
  int  i, status, nIter;
  int  nParams = theModel->GetNParams();
  int  nValidPixels = theModel->GetNValidPixels();
  int  verboseLevel = -1;
  
  /* seed random number generators with current time */
  init_genrand((unsigned long)time((time_t *)NULL));

  paramsVect = (double *) malloc(nParams * sizeof(double));
  // Allocate 2D array to hold bootstrap results for each parameter
  paramArray = (double **)calloc( (size_t)nParams, sizeof(double *) );
  for (i = 0; i < nParams; i++)
    paramArray[i] = (double *)calloc( (size_t)nIterations, sizeof(double) );
  // vector to hold estimated sigmas for each parameter
  paramSigmas = (double *)calloc( (size_t)nParams, sizeof(double) );


  theModel->UseBootstrap();

  if (! usingCashStatistic)
    printf("\nStarting bootstrap iterations (L-M solver): ");
  else
#ifndef NO_NLOPT
    printf("\nStarting bootstrap iterations (N-M simplex solver): ");
#else
    printf("\nStarting bootstrap iterations (DE solver): ");
#endif

  for (nIter = 0; nIter < nIterations; nIter++) {
    printf("%d...  ", nIter + 1);
    fflush(stdout);
    theModel->MakeBootstrapSample();
    for (i = 0; i < nParams; i++)
      paramsVect[i] = bestfitParams[i];
    if (! usingCashStatistic) {
      status = LevMarFit(nParams, nFreeParams, nValidPixels, paramsVect, parameterLimits, 
      					theModel, ftol, paramLimitsExist, verboseLevel);
    } else {
#ifndef NO_NLOPT
      status = NMSimplexFit(nParams, paramsVect, parameterLimits, theModel, ftol,
      						verboseLevel);
#else
      status = DiffEvolnFit(nParams, paramsVect, parameterLimits, theModel, ftol,
      						verboseLevel);
#endif
    }
    for (i = 0; i < nParams; i++) {
      paramArray[i][nIter] = paramsVect[i];
    }
  }


  /* Determine dispersions for parameter values */
  for (i = 0; i < nParams; i++) {
    paramSigmas[i] = StandardDeviation(paramArray[i], nIterations);
  }
  
  /* Print parameter values + standard deviations: */
  /* (note that calling ConfidenceInterval() sorts the vectors in place!) */
  printf("\nStatistics for parameter values from bootstrap resampling");
  printf(" (%d rounds):\n", nIterations);
  printf("Best-fit\t\t Bootstrap      [68%% conf.int., half-width]; (mean +/- standard deviation)\n");
  for (i = 0; i < nParams; i++) {
    if ((paramLimitsExist) && (parameterLimits[i].fixed == 0)) {
      // OK, this parameter was not fixed
      ConfidenceInterval(paramArray[i], nIterations, &lower, &upper);
      plus = upper - bestfitParams[i];
      minus = bestfitParams[i] - lower;
      halfwidth = (upper - lower)/2.0;
      printf("%s = %g  +%g, -%g    [%g -- %g, %g];  (%g +/- %g)\n", 
             theModel->GetParameterName(i).c_str(), 
             bestfitParams[i], plus, minus, lower, upper, halfwidth,
             Mean(paramArray[i], nIterations), paramSigmas[i]);
    }
    else {
      printf("%s = %g     [fixed parameter]\n", theModel->GetParameterName(i).c_str(),
                  bestfitParams[i]);
    
    }
  }


  free(paramsVect);
  free(paramSigmas);
  for (i = 0; i < nParams; i++)
    free(paramArray[i]);
  free(paramArray);

}
コード例 #9
0
ファイル: SignalUtility.cpp プロジェクト: vincentvillani/DSP
float CoefficientOfVariation(const RunningStats* runningStat)
{
	return (StandardDeviation(runningStat) / Mean(runningStat) ) * 100.0f;
}
コード例 #10
0
ファイル: SignalUtility.cpp プロジェクト: vincentvillani/DSP
float CoefficientOfVariation(const Histogram* histogram)
{
	return (StandardDeviation(histogram) / Mean(histogram) ) * 100.0f;
}
コード例 #11
0
ファイル: SignalUtility.cpp プロジェクト: vincentvillani/DSP
float SignalToNoiseRatio(const RunningStats* runningStat)
{
	return Mean(runningStat) / StandardDeviation(runningStat);
}
コード例 #12
0
ファイル: SignalUtility.cpp プロジェクト: vincentvillani/DSP
float SignalToNoiseRatio(const Histogram* histogram)
{
	return Mean(histogram) / StandardDeviation(histogram);
}
コード例 #13
0
ファイル: HillClimbing.cpp プロジェクト: Chuyu-Team/VC-LTL
 /// <summary>
 ///     Computes the mean of standard deviations for a given history.
 /// </summary>
 /// <returns>
 ///     The mean of standard deviations.
 /// </returns>
 double HillClimbing::MeasuredHistory::StandardDeviationMean()
 {
     return (m_count == 0) ? 0.0 : (StandardDeviation() / sqrt(m_count * 1.0));
 }
コード例 #14
0
ファイル: HillClimbing.cpp プロジェクト: Chuyu-Team/VC-LTL
 /// <summary>
 ///     Computes the mean of coefficients of variation for a given history.
 /// </summary>
 /// <returns>
 ///     The mean of coefficients of variation.
 /// </returns>
 double HillClimbing::MeasuredHistory::CoefficientOfVariationMean()
 {
     return (StandardDeviation() / sqrt(1.0 * m_count)) / Mean();
 }
コード例 #15
0
ファイル: HillClimbing.cpp プロジェクト: Chuyu-Team/VC-LTL
 /// <summary>
 ///     Computes the coefficient of variation for a given history.
 /// </summary>
 /// <returns>
 ///     The coefficient of variation.
 /// </returns>
 double HillClimbing::MeasuredHistory::CoefficientOfVariation()
 {
     double mean = Mean();
     return (mean <= 0.0) ? 0.0 : (StandardDeviation() / mean);
 }
コード例 #16
0
ファイル: Histogram.cpp プロジェクト: assutech/isis3
 /**
  * Computes and returns the skew. If there are no valid pixels then NULL8 is
  * returned. Recognize that because of the binning which occurs, in order to
  * generate the histogram, the skew may not be precise but will be very close.
  *
  * @return The skew.
  */
 double Histogram::Skew() const {
   if (ValidPixels() < 1) return Isis::NULL8;
   double sdev = StandardDeviation();
   if (sdev == 0.0) return 0.0;
   return 3.0 * (Average() - Median()) / sdev;
 }