Real GeneralizedOrnsteinUhlenbeckProcess::stdDeviation(
                                          Time t, Real x0, Time dt) const {
     return std::sqrt(variance(t,x0,dt));
 }
Esempio n. 2
0
/// std dev
double stdDev(const Vector& vector)
{
    return sqrt(variance(vector));
}
Esempio n. 3
0
int main(int argc,char **argv)
{
  char stdi=0,done;
  long i,j,hdim,actfound;
  unsigned long count=1;
  double *swap,*newcast,maxinterval,*min,*interval,dummy,epsilon0;
  FILE *file=NULL;
  
  if (scan_help(argc,argv))
    show_options(argv[0]);
  
  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif
  
  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stdi=1;
  
  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".lzr");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
      strcpy(outfile,"stdin.lzr");
    }
  }
  if (!onscreen)
    test_outfile(outfile);
  
  hdim=(embed-1)*DELAY+1;
  if (column == NULL)
    series=(double**)get_multi_series(infile,&LENGTH,exclude,&dim,"",dimset,
				      verbosity);
  else
    series=(double**)get_multi_series(infile,&LENGTH,exclude,&dim,column,
				      dimset,verbosity);

  dim1=dim-1;

  check_alloc(min=(double*)malloc(sizeof(double)*dim));
  check_alloc(interval=(double*)malloc(sizeof(double)*dim));
  check_alloc(var=(double*)malloc(sizeof(double)*dim));

  maxinterval=0.0;

  for (i=0;i<dim;i++) {
    rescale_data(series[i],LENGTH,&min[i],&interval[i]);
    variance(series[i],LENGTH,&dummy,&var[i]);
    if (interval[i] > maxinterval)
      maxinterval=interval[i];
  }

  if (epsset)
    EPS0 /= maxinterval;
    
  check_alloc(cast=(double**)malloc(sizeof(double*)*hdim));
  for (i=0;i<hdim;i++)
    check_alloc(cast[i]=(double*)malloc(sizeof(double)*dim));
  check_alloc(newcast=(double*)malloc(sizeof(double)*dim));
  check_alloc(newav=(double*)malloc(sizeof(double)*dim));
    
  check_alloc(list=(long*)malloc(sizeof(long)*LENGTH));
  check_alloc(found=(long*)malloc(sizeof(long)*LENGTH));
  check_alloc(abstand=(double*)malloc(sizeof(double)*LENGTH));
  check_alloc(box=(long**)malloc(sizeof(long*)*NMAX));
  for (i=0;i<NMAX;i++)
    check_alloc(box[i]=(long*)malloc(sizeof(long)*NMAX));
  
  check_alloc(vec=(double*)malloc(sizeof(double)*dim));
  check_alloc(hsum=(double*)malloc(sizeof(double)*dim));
  check_alloc(mat=(double**)malloc(sizeof(double*)*dim));
  for (i=0;i<dim;i++) {
    check_alloc(mat[i]=(double*)malloc(sizeof(double)*dim));
  }

  for (j=0;j<dim;j++)
    for (i=0;i<hdim;i++)
      cast[i][j]=series[j][LENGTH-hdim+i];

  indexes=make_multi_index(dim,embed,DELAY);
  
  if (!onscreen) {
    file=fopen(outfile,"w");
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Opened %s for writing\n",outfile);
  }
  else {
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Writing to stdout\n");
  }

  rnd_init(seed);

  epsilon0=EPS0/EPSF;

  if (setnoise) 
    Q /= 100.0;

  for (i=0;i<FLENGTH;i++) {
    done=0;
    if (setsort)
      epsilon= epsilon0/((double)count*EPSF);
    else
      epsilon=epsilon0;
    while (!done) {
      epsilon*=EPSF;
      put_in_boxes();
      actfound=hfind_neighbors();
      if (actfound >= MINN) {
	if (setsort) {
	  epsilon0 += epsilon;
	  count++;
	  sort(actfound);
	  actfound=MINN;
	}
	make_zeroth(actfound,newcast);
	if (onscreen) {
	  for (j=0;j<dim-1;j++)
	    printf("%e ",newcast[j]*interval[j]+min[j]);
	  printf("%e\n",newcast[dim-1]*interval[dim-1]+min[dim-1]);
	  fflush(stdout);
	}
	else {
	  for (j=0;j<dim-1;j++)
	    fprintf(file,"%e ",newcast[j]*interval[j]+min[j]);
	  fprintf(file,"%e\n",newcast[dim-1]*interval[dim-1]+min[dim-1]);
	  fflush(file);
	}
	done=1;
	swap=cast[0];
	for (j=0;j<hdim-1;j++)
	  cast[j]=cast[j+1];
	cast[hdim-1]=swap;
	for (j=0;j<dim;j++)
	  cast[hdim-1][j]=newcast[j];
      }
    }
  }
  if (!onscreen)
    fclose(file);
  
  if (outfile != NULL)
    free(outfile);
  for (i=0;i<dim;i++)
    free(mat[i]);
  free(mat);
  for (i=0;i<hdim;i++)
    free(cast[i]);
  free(cast);
  free(newcast);
  free(found);
  free(list);
  for (i=0;i<NMAX;i++)
    free(box[i]);
  free(box);
  free(vec);
  free(newav);
  for (i=0;i<dim;i++)
    free(series[i]);
  free(series);

  return 0;
}
Esempio n. 4
0
/** Returns the standard deviation for an array of doubles */
double MUtil::stdDeviation(QArray<double>* values){
  return sqrt(variance(values));
}
Esempio n. 5
0
 /**\brief standard deviation of values */
 double standard_deviation() const { return sqrt(fabs(variance())); }
Esempio n. 6
0
double stdDeviation(int totnum, double data[])
{
	double stdDev = sqrt(variance(totnum, data));

	return stdDev;
}
double	SimFocuser::radius() {
	double	r = fabs((reference() - current()) / (double)variance());
	return MAXRADIUS * r;
}
 Real IncrementalStatistics::standardDeviation() const {
     return std::sqrt(variance());
 }
 Real IncrementalStatistics::errorEstimate() const {
     return std::sqrt(variance() / (samples()));
 }
Esempio n. 10
0
int main() {

#ifdef _DEBUG
	int dbgFlags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
	dbgFlags |= _CRTDBG_CHECK_ALWAYS_DF;	// check block integrity on every memory call
	dbgFlags |= _CRTDBG_DELAY_FREE_MEM_DF;
	dbgFlags |= _CRTDBG_LEAK_CHECK_DF;		// checks for leaks at process
	_CrtSetDbgFlag(dbgFlags);
#endif

	printf("Stats, (c) 2016 Vasilisa Petrushina\n");
	printf("Enter the number of samples followed by those samples.\n\n");

	int ch = getchar();
	if (ch != EOF)
		ungetc(ch, stdin);
	else {
		printf("N = 0\nEmpty data set!\n");
		return 1;
	}

	ListLength listLength;
	if (!scanf("%llu", &listLength) || listLength < 1) {
		printf("N = 0\nEmpty data set!\n");
		return 1;
	}
	
	double* list = malloc((size_t)listLength * sizeof(double));
	if (list == NULL) {
		printf("Memory allocation failed!");
		return 1;
	}
	for (unsigned i = 0; i < listLength; ++i)
		scanf("%lf", &list[i]);

	heapSort(list, listLength);

	printf("\nResults\n");
	printf("N = %s\n", formatNumber((double)listLength, 0));
	printf("Min = %s\n", formatNumber(minimum(list), 3));
	printf("Max = %s\n", formatNumber(maximum(list, listLength), 3));

	double meanVal = mean(list, listLength);
	printf("Arithmetic mean = %s\n", formatNumber(meanVal, 3));

	double medianVal = median(list, listLength);
	printf("Statistical median = %s\n", formatNumber(medianVal, 3));

	double* modeArray = mode(list, listLength);
	// check the first element in modeArray indicating how many modes
	if (modeArray[0] == 0)
		printf("Mode = no mode.\n\n");
	else if (modeArray[0] == 1)
		printf("Mode = { %s }\n", formatNumber(modeArray[1], 3));
	else {
		printf("Mode = {");
		for (unsigned i = 1; i <= modeArray[0]; ++i) {
			printf(" %s", formatNumber(modeArray[i], 3));
			if (i != modeArray[0])
				printf(", ");
		}
		printf(" }\n");
	}

	printf("Mean absolute deviation = %s\n", formatNumber(absoluteDeviation(list, listLength, meanVal), 3));
	printf("Median absolute deviation = %s\n", formatNumber(absoluteDeviation(list, listLength, medianVal), 3));

	// if first element in mode array (mode count) is not 1, there's no unique mode
	if (modeArray[0] != 1.0) 
		printf("Mode absolute deviation = N/A <no unique mode>\n");
	else
		printf("Mode absolute deviation = %s\n", formatNumber(absoluteDeviation(list, listLength, modeArray[1]), 3));
	free(modeArray);

	double varianceVal = variance(list, listLength, meanVal);
	printf("Variance = %s\n", formatNumber(varianceVal, 3));

	printf("Standard deviation = %s\n\n", formatNumber(deviation(varianceVal), 3));

	// frequency distribution table
	double interval = (list[listLength - 1] - list[0]) / 10;
	// making intervals larger than just range/10 by 1% (to include the higest value) but no more than 0.1
	double offset = 0.01 * interval;
	if (offset > 0.1)
		offset = 0.1;
	interval += offset;

	double lowerLimit = list[0];
	double upperLimit = list[0] + interval;
	unsigned index = 0;

	// calculations for dynamic allign of collumns
	double longestNum = maximum(list, listLength);
	if (fabs(minimum(list)) > maximum(list, listLength) )
		longestNum = fabs(minimum(list));

	int colWidthInterval = countColWidth(longestNum, 2);
	int colWidthsCount = countColWidth((double)listLength, 0);

	// for each of the 10 intervals count how many numbers get in this range
	for (int i = 0; i < 10; ++i) {
		unsigned count = 0;
		while (list[index] < upperLimit && index < listLength) {
			++count;
			++index;
		}
		printf("[%*s..%*s) =%*d : %.2f\n", colWidthInterval, formatNumber(lowerLimit, 2), colWidthInterval, formatNumber(upperLimit, 2), colWidthsCount, count, (double)count / listLength);
		lowerLimit = upperLimit;
		upperLimit += interval;
	}
	free(list);
}
Esempio n. 11
0
 T standardError() const
 {
   return sqrt(variance() / mData.size());
 }
Esempio n. 12
0
    bool forward_ocl(InputArrayOfArrays inps, OutputArrayOfArrays outs, OutputArrayOfArrays internals)
    {
        std::vector<UMat> inputs;
        std::vector<UMat> outputs;

        bool use_half = (inps.depth() == CV_16S);
        inps.getUMatVector(inputs);
        outs.getUMatVector(outputs);

        int _layerWidth = inputs[0].size[3];
        int _layerHeight = inputs[0].size[2];

        int _imageWidth = inputs[1].size[3];
        int _imageHeight = inputs[1].size[2];

        if (umat_offsetsX.empty())
        {
            Mat offsetsX(1, _offsetsX.size(), CV_32FC1, &_offsetsX[0]);
            Mat offsetsY(1, _offsetsY.size(), CV_32FC1, &_offsetsY[0]);
            Mat variance(1, _variance.size(), CV_32FC1, &_variance[0]);
            Mat widths(1, _boxWidths.size(), CV_32FC1, &_boxWidths[0]);
            Mat heights(1, _boxHeights.size(), CV_32FC1, &_boxHeights[0]);

            offsetsX.copyTo(umat_offsetsX);
            offsetsY.copyTo(umat_offsetsY);
            variance.copyTo(umat_variance);
            widths.copyTo(umat_widths);
            heights.copyTo(umat_heights);
        }

        String opts;
        if (use_half)
            opts = "-DDtype=half -DDtype4=half4 -Dconvert_T=convert_half4";
        else
            opts = "-DDtype=float -DDtype4=float4 -Dconvert_T=convert_float4";

        size_t nthreads = _layerHeight * _layerWidth;
        ocl::Kernel kernel("prior_box", ocl::dnn::prior_box_oclsrc, opts);

        kernel.set(0, (int)nthreads);
        kernel.set(1, (float)_stepX);
        kernel.set(2, (float)_stepY);
        kernel.set(3, ocl::KernelArg::PtrReadOnly(umat_offsetsX));
        kernel.set(4, ocl::KernelArg::PtrReadOnly(umat_offsetsY));
        kernel.set(5, (int)_offsetsX.size());
        kernel.set(6, ocl::KernelArg::PtrReadOnly(umat_widths));
        kernel.set(7, ocl::KernelArg::PtrReadOnly(umat_heights));
        kernel.set(8, (int)_boxWidths.size());
        kernel.set(9, ocl::KernelArg::PtrWriteOnly(outputs[0]));
        kernel.set(10, (int)_layerHeight);
        kernel.set(11, (int)_layerWidth);
        kernel.set(12, (int)_imageHeight);
        kernel.set(13, (int)_imageWidth);
        kernel.run(1, &nthreads, NULL, false);

        // clip the prior's coordidate such that it is within [0, 1]
        if (_clip)
        {
            Mat mat = outputs[0].getMat(ACCESS_READ);
            int aspect_count = (_maxSize > 0) ? 1 : 0;
            int offset = nthreads * 4 * _offsetsX.size() * (1 + aspect_count + _aspectRatios.size());
            float* outputPtr = mat.ptr<float>() + offset;
            int _outChannelSize = _layerHeight * _layerWidth * _numPriors * 4;
            for (size_t d = 0; d < _outChannelSize; ++d)
            {
                outputPtr[d] = std::min<float>(std::max<float>(outputPtr[d], 0.), 1.);
            }
        }

        // set the variance.
        {
            ocl::Kernel kernel("set_variance", ocl::dnn::prior_box_oclsrc, opts);
            int offset = total(shape(outputs[0]), 2);
            size_t nthreads = _layerHeight * _layerWidth * _numPriors;
            kernel.set(0, (int)nthreads);
            kernel.set(1, (int)offset);
            kernel.set(2, (int)_variance.size());
            kernel.set(3, ocl::KernelArg::PtrReadOnly(umat_variance));
            kernel.set(4, ocl::KernelArg::PtrWriteOnly(outputs[0]));
            if (!kernel.run(1, &nthreads, NULL, false))
                return false;
        }
        return true;
    }
Esempio n. 13
0
double HrPwWindow::pente(QVector<double> &Xi,QVector<double> &Yi,int n)
{
	double a = covariance(Xi,Yi,n)/variance(Xi,n);

	return (a);
}
Esempio n. 14
0
double HrPwWindow::ecarttype(QVector<double> &val,int n)
{
	double ect= sqrt(variance(val,n));

	return (ect);
}
Esempio n. 15
0
 /**
  * Returns the standard deviation of all recorded values.
  */    
 double stddev() const 
 {
     if (count_ > 0) 
         return std::sqrt(variance());
     return 0.0;
 }
Esempio n. 16
0
/*********************
*
*	FUNCTION: standard_deviation
*
*	DESCRIPTION:
*		Calculate the standard deviation of the input array
*
***********************/
FLOAT standard_deviation(const void *in, const UINT32 Nelements, const int in_type)
{
	FLOAT mean;
	return (FLOAT) sqrt(variance(in,Nelements,in_type,&mean));
}
Esempio n. 17
0
 double stddev(const double* data, int n)
 {
   return ::sqrt(variance(data, n));
 }
Esempio n. 18
0
/*! @brief Returns the standard deviation of the specified state.

    @param stateNumber the number of the desired state.
 */
float Moment::sd(unsigned int stateNumber) const
{
    return sqrt(variance(stateNumber));
}
void	SimFocuser::randomposition() {
	_value = reference() + (random() % variance());
	target = _value;
	lastset = 0;
}
Esempio n. 20
0
 double stddev() const {
   return sqrt( variance() );
 }
Esempio n. 21
0
/**
 * This function trains one of the classes of the given machine with the given data.
 * It computes either BIC projection matrices, or IEC mean and variance.
 *
 * @param  clazz    false for the intrapersonal class, true for the extrapersonal one.
 * @param  machine  The machine to be trained.
 * @param  differences  A set of (intra/extra)-personal difference vectors that should be trained.
 */
void bob::learn::em::BICTrainer::train_single(bool clazz, bob::learn::em::BICMachine& machine, const blitz::Array<double,2>& differences) const {
  int subspace_dim = clazz ? m_M_E : m_M_I;
  int input_dim = differences.extent(1);
  int data_count = differences.extent(0);
  blitz::Range a = blitz::Range::all();

  if (subspace_dim){
    // train the class using BIC

    // Compute PCA on the given dataset
    bob::learn::linear::PCATrainer trainer;
    const int n_eigs = trainer.output_size(differences);
    bob::learn::linear::Machine pca(input_dim, n_eigs);
    blitz::Array<double,1> variances(n_eigs);
    trainer.train(pca, variances, differences);

    // compute rho
    double rho = 0.;
    int non_zero_eigenvalues = std::min(input_dim, data_count-1);
    // assert that the number of kept eigenvalues is not chosen to big
    if (subspace_dim >= non_zero_eigenvalues)
      throw std::runtime_error((boost::format("The chosen subspace dimension %d is larger than the theoretical number of nonzero eigenvalues %d")%subspace_dim%non_zero_eigenvalues).str());
    // compute the average of the reminding eigenvalues
    for (int i = subspace_dim; i < non_zero_eigenvalues; ++i){
      rho += variances(i);
    }
    rho /= non_zero_eigenvalues - subspace_dim;

    // limit dimensionalities
    pca.resize(input_dim, subspace_dim);
    variances.resizeAndPreserve(subspace_dim);

    // check that all variances are meaningful
    for (int i = 0; i < subspace_dim; ++i){
      if (variances(i) < 1e-12)
        throw std::runtime_error((boost::format("The chosen subspace dimension is %d, but the %dth eigenvalue is already to small")%subspace_dim%i).str());
    }

    // initialize the machine
    blitz::Array<double, 2> projection = pca.getWeights();
    blitz::Array<double, 1> mean = pca.getInputSubtraction();
    machine.setBIC(clazz, mean, variances, projection, rho);
  } else {
    // train the class using IEC
    // => compute mean and variance only
    blitz::Array<double,1> mean(input_dim), variance(input_dim);

    // compute mean and variance
    mean = 0.;
    variance = 0.;
    for (int n = data_count; n--;){
      const blitz::Array<double,1>& diff = differences(n,a);
      assert(diff.shape()[0] == input_dim);
      for (int i = input_dim; i--;){
        mean(i) += diff(i);
        variance(i) += sqr(diff(i));
      }
    }
    // normalize mean and variances
    for (int i = 0; i < input_dim; ++i){
      // intrapersonal
      variance(i) = (variance(i) - sqr(mean(i)) / data_count) / (data_count - 1.);
      mean(i) /= data_count;
      if (variance(i) < 1e-12)
        throw std::runtime_error((boost::format("The variance of the %dth dimension is too small. Check your data!")%i).str());
    }

    // set the results to the machine
    machine.setIEC(clazz, mean, variance);
  }
}
Esempio n. 22
0
extern double stdDeviation(int totnum, double data[]){
	return sqrt(variance(totnum, data));
}
Esempio n. 23
0
double AbsSeq::sd() const {
    double var = variance();
    guarantee( var >= 0.0, "variance should not be negative" );
    return sqrt(var);
}
Esempio n. 24
0
 Real AbcdFunction::volatility(Time tMin, Time tMax, Time T) const {
     if (tMax==tMin)
         return instantaneousVolatility(tMax, T);
     QL_REQUIRE(tMax>tMin, "tMax must be > tMin");
     return std::sqrt(variance(tMin, tMax, T)/(tMax-tMin));
 }
Esempio n. 25
0
int main(int argc,char **argv)
{
  char stdi=0;
  FILE *file=NULL;
  double min,inter=0.0,ind_inter,epsilon,av,ind_var;
  char *nearest,alldone;
  long i;
  unsigned int dim,emb;
  unsigned long donesofar;

  if (scan_help(argc,argv))
    show_options(argv[0]);
  
  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif

  infile=search_datafile(argc,argv,NULL,verbosity);
  if (infile == NULL)
    stdi=1;

  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,(size_t)1));
      strcpy(outfile,infile);
      strcat(outfile,".fnn");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,(size_t)1));
      strcpy(outfile,"stdin.fnn");
    }
  }
  if (!stdo)
    test_outfile(outfile);

  if (column == NULL)
    series=(double**)get_multi_series(infile,&length,exclude,&comp,"",dimset,
				      verbosity);
  else
    series=(double**)get_multi_series(infile,&length,exclude,&comp,column,
				      dimset,verbosity);

  for (i=0;i<comp;i++) {
    rescale_data(series[i],length,&min,&ind_inter);
    variance(series[i],length,&av,&ind_var);
    if (i == 0) {
      varianz=ind_var;
      inter=ind_inter;
    }
    else {
      varianz=(varianz>ind_var)?ind_var:varianz;
      inter=(inter<ind_inter)?ind_inter:inter;
    }
  }

  check_alloc(list=(long*)malloc(sizeof(long)*length));
  check_alloc(nearest=(char*)malloc(length));
  check_alloc(box=(long**)malloc(sizeof(long*)*BOX));
  for (i=0;i<BOX;i++)
    check_alloc(box[i]=(long*)malloc(sizeof(long)*BOX));

  if (!stdo) {
    file=fopen(outfile,"w");
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Opened %s for writing\n",outfile);
  }
  else {
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Writing to stdout\n");
  }
  check_alloc(vcomp=(unsigned int*)malloc(sizeof(int)*(maxdim)));
  check_alloc(vemb=(unsigned int*)malloc(sizeof(int)*(maxdim)));
  for (i=0;i<maxdim;i++) {
    if (comp == 1) {
      vcomp[i]=0;
      vemb[i]=i;
    }
    else {
      vcomp[i]=i%comp;
      vemb[i]=(i/comp)*delay;
    }
  }
  for (emb=minemb;emb<=maxemb;emb++) {
    dim=emb*comp-1;
    epsilon=eps0;
    toolarge=0;
    alldone=0;
    donesofar=0;
    aveps=0.0;
    vareps=0.0;
    for (i=0;i<length;i++)
      nearest[i]=0;
    if (verbosity&VER_USR1)
      fprintf(stderr,"Start for dimension=%u\n",dim+1);
    while (!alldone && (epsilon < 2.*varianz/rt)) {
      alldone=1;
      mmb(vcomp[dim],vemb[dim],epsilon);
      for (i=0;i<length-maxemb*delay;i++)
	if (!nearest[i]) {
	  nearest[i]=find_nearest(i,dim,epsilon);
	  alldone &= nearest[i];
	  donesofar += (unsigned long)nearest[i];
	}
      if (verbosity&VER_USR1)
	fprintf(stderr,"Found %lu up to epsilon=%e\n",donesofar,epsilon*inter);
      epsilon*=sqrt(2.0);
      if (!donesofar)
	eps0=epsilon;
    }
    if (donesofar == 0) {
      fprintf(stderr,"Not enough points found!\n");
      exit(FALSE_NEAREST_NOT_ENOUGH_POINTS);
    }
    aveps *= (1./(double)donesofar);
    vareps *= (1./(double)donesofar);
    if (stdo) {
      fprintf(stdout,"%u %e %e %e\n",dim+1,(double)toolarge/(double)donesofar,
	      aveps*inter,sqrt(vareps)*inter);
      fflush(stdout);
    }
    else {
      fprintf(file,"%u %e %e %e\n",dim+1,(double)toolarge/(double)donesofar,
	      aveps*inter,sqrt(vareps)*inter);
      fflush(file);
    }
  }
  if (!stdo)
    fclose(file);

  if (infile != NULL)
    free(infile);
  if (outfile != NULL)
    free(outfile);
  free(series);
  free(list);
  free(nearest);
  for (i=0;i<BOX;i++)
    free(box[i]);
  free(box);

  return 0;
}
Esempio n. 26
0
double sd(const VEC v){
	return sqrt(variance(v));
}
Esempio n. 27
0
int main(int argc, char *argv[])
{
#ifdef MISSING_VRPN
	printf("This program requires VRPN.");
	exit(EXIT_FAILURE);
#else

	if(argc != 3)
	{
		printf("Usage: %s vrpnObjectName numRecords\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	int numRecords = 0;
	if(sscanf(argv[2], "%d", &numRecords) != 1)
	{
		msg(MSG_FATAL, "Error parsing numRecords parameter.\n");
		exit(EXIT_FAILURE);
	}

	const char *vrpnObject = argv[1];

	
	msg(MSG_BLUE, "Collecting %d samples from tracker...please wait...\n", numRecords);
	float *data = vrpn_get_raw(vrpnObject, NULL, numRecords);
	if(data == NULL)
	{
		msg(MSG_FATAL, "Failed to collect data.");
		exit(EXIT_FAILURE);
	}

	printf("First record (x,y,z, quat): \n");
	for(int i=0; i<7; i++)
		printf("%f\n", data[i]);

	float x[numRecords], y[numRecords], z[numRecords];

	filter(data, numRecords, 0, x);
	filter(data, numRecords, 1, y);
	filter(data, numRecords, 2, z);
	msg(MSG_BLUE, "--- XYZ ---\n");
	
	msg(MSG_INFO, "Means: %f %f %f\n",
	    mean(x, numRecords),
	    mean(y, numRecords),
	    mean(z, numRecords));
	msg(MSG_INFO, "Variance: %20.20f %20.20f %20.20f\n",
	    variance(x, numRecords),
	    variance(y, numRecords),
	    variance(z, numRecords));

	msg(MSG_INFO, "  Stddev: %20.20f %20.20f %20.20f\n",
	    sqrt(variance(x, numRecords)),
	    sqrt(variance(y, numRecords)),
	    sqrt(variance(z, numRecords)));

	float q1[numRecords], q2[numRecords], q3[numRecords], q4[numRecords];
	filter(data, numRecords, 3, q1);
	filter(data, numRecords, 4, q2);
	filter(data, numRecords, 5, q3);
	filter(data, numRecords, 6, q4);

	msg(MSG_BLUE, "--- Quat ---\n");
	
	msg(MSG_INFO, "Means: %f %f %f %f\n",
	    mean(q1, numRecords),
	    mean(q2, numRecords),
	    mean(q3, numRecords),
	    mean(q4, numRecords));
	
	msg(MSG_INFO, "Variance: %20.20f %20.20f %20.20f %20.20f\n",
	    variance(q1, numRecords),
	    variance(q2, numRecords),
	    variance(q3, numRecords),
	    variance(q4, numRecords));
	msg(MSG_INFO, "   Stddev: %20.20f %20.20f %20.20f %20.20f\n",
	    sqrt(variance(q1, numRecords)),
	    sqrt(variance(q2, numRecords)),
	    sqrt(variance(q3, numRecords)),
	    sqrt(variance(q4, numRecords)));

	free(data);
	
	return 0;
#endif
}
Esempio n. 28
0
int main(int argc,char **argv)
{
  char stdi=0;
  unsigned long i,j;
  double x,norm,size=1.0,size2=1.0;
  double min,max;
  double *series;
  double average,var;
  long *box;
  FILE *fout;

  if (scan_help(argc,argv))
    show_options(argv[0]);
  
  scan_options(argc,argv);
#ifndef OMIT_WHAT_I_DO
  if (verbosity&VER_INPUT)
    what_i_do(argv[0],WID_STR);
#endif

  infile=search_datafile(argc,argv,&column,verbosity);
  if (infile == NULL)
    stdi=1;

  if (outfile == NULL) {
    if (!stdi) {
      check_alloc(outfile=(char*)calloc(strlen(infile)+5,1));
      strcpy(outfile,infile);
      strcat(outfile,".his");
    }
    else {
      check_alloc(outfile=(char*)calloc((size_t)10,1));
      strcpy(outfile,"stdin.his");
    }
  }
  if (!my_stdout)
    test_outfile(outfile);

  series=(double*)get_series(infile,&length,exclude,column,verbosity);
  variance(series,length,&average,&var);

  min=max=series[0];
  for (i=1;i<length;i++) {
    if (series[i] < min) min=series[i];
    else if (series[i] > max) max=series[i];
  }
  max -= min;

  for (i=0;i<length;i++)
    series[i]=(series[i]-min);

  if (base > 0) {
    check_alloc(box=(long*)malloc(sizeof(long)*base));
    for (i=0;i<base;i++)
      box[i]=0;
    size=1./base;
    size2=(1.0-size/2.0)*max;
    for (i=0;i<length;i++) {
      if (series[i] > size2)
	series[i]=size2;
      j=(long)(series[i]*base/max);
      box[j]++;
    }
  }

  if (!density)
    norm=1.0/(double)length;
  else
    norm=1.0/(double)length*(double)base/max;

  if (!my_stdout) {
    fout=fopen(outfile,"w");
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Opened %s for writing\n",outfile);
    fprintf(fout,"#interval of data: [%e:%e]\n",min,max+min);
    fprintf(fout,"#average= %e\n",average);
    fprintf(fout,"#standard deviation= %e\n",var);
    for (i=0;i<base;i++) {
      x=(double)(i*size);
      fprintf(fout,"%e %e\n",(x+size/2.0)*max+min,(double)box[i]*norm);
    }
    fclose(fout);
  }
  else {
    if (verbosity&VER_INPUT)
      fprintf(stderr,"Writing to stdout\n");
    fprintf(stdout,"#interval of data: [%e:%e]\n",min,max+min);
    fprintf(stdout,"#average= %e\n",average);
    fprintf(stdout,"#standard deviation= %e\n",var);
    for (i=0;i<base;i++) {
      x=(double)(i*size);
      fprintf(stdout,"%e %e\n",(x+size/2.0)*max+min,(double)box[i]*norm);
      fflush(stdout);
    }
  }
  return 0;
}
Esempio n. 29
0
 double ZIGM::sd() const { return sqrt(variance()); }
Esempio n. 30
0
void vp9_get_sse_sum_8x8_c(const uint8_t *src_ptr, int source_stride,
                       const uint8_t *ref_ptr, int ref_stride,
                       unsigned int *sse, int *sum) {
  variance(src_ptr, source_stride, ref_ptr, ref_stride, 8, 8, sse, sum);
}