Ejemplo n.º 1
0
double
statTimer::getAverageTime( size_t id ) const
{
	if( normalize )
		return getMean( id ) / clkFrequency;
	else
		return getMean( id );
}
Ejemplo n.º 2
0
double
StatisticalTimer::getAverageTime( sTimerID id ) const
{
	if( normalize )
		return getMean( id ) / clkFrequency;
	else
		return getMean( id );
}
Ejemplo n.º 3
0
		double Statistics::getCovariance(const vector<double>& v1, const vector<double>& v2, double mean1, double mean2)
		{
			if (mean1 == -1) {mean1 = getMean(v1); }
			if (mean2 == -1) {mean2 = getMean(v2); }
			double sum_of_squares = 0;
			for (unsigned int i = 0; i < v1.size() && i < v2.size(); i++)
			{
				sum_of_squares += (v1[i]-mean1)*(v2[i]-mean2);
			}
			return sum_of_squares/(v1.size()-1);
		}
Ejemplo n.º 4
0
		double Statistics::getCovariance(const Eigen::MatrixXd& m, int col1, int col2, double mean1, double mean2)
		{
			if (mean1 == -1) {mean1 = getMean(m, col1); }
			if (mean2 == -1) {mean2 = getMean(m, col2); }
			double sum_of_squares = 0;
			for (int i = 0; i < m.rows(); i++)
			{
				sum_of_squares += (m(i, col1)-mean1)*(m(i, col2)-mean2);
			}
			return sum_of_squares/(m.rows()-1);
		}
Ejemplo n.º 5
0
double StatVar::getSigmaBigger()
{
  double ss=0;
  int ns=0;
  for(int i=0; i<n; i++)
    if( values[i]>getMean() ) {
      ss+=(values[i]-getMean())*(values[i]-getMean());
      ns++;
    }
  if( ss/ns>0 )
    return sqrt(ss/ns);
  else
    return 0;
}
Ejemplo n.º 6
0
vector<double>* GaussianEstimator::estimatedWeight_LessThan_EqualTo_GreaterThan_Value(double value) {
    double equalToWeight = probabilityDensity(value) * this->m_weightSum;
    double stdDev = getStdDev();
    double lessThanWeight = stdDev > 0.0 ? normalProbability((value - getMean()) / stdDev)
            * this->m_weightSum - equalToWeight
            : (value < getMean() ? this->m_weightSum - equalToWeight : 0.0);
    double greaterThanWeight = this->m_weightSum - equalToWeight
            - lessThanWeight;
    if (greaterThanWeight < 0.0) {
        greaterThanWeight = 0.0;
    }
    vector<double>* retVec = new vector<double>{lessThanWeight, equalToWeight, greaterThanWeight};
    return retVec;
}
Ejemplo n.º 7
0
 /** method to calc standard deviation */
 double getStandardDeviation() const {
     double mi = getMean();
     double variation = std::accumulate( values_.begin(), values_.end(), 0.0,
                                         boost::bind( std::plus<double>(), _1,
                                                      boost::bind(&getVariationTerm, _2, mi) ) );
     return std::sqrt(variation);
 }
Ejemplo n.º 8
0
 void BaseStat::print()
 {
     cout << "[" << getName()
          << "]:" << getMean()
          << "  (Conf[95%]=" << getConfInterval(BaseStat::C95)
          << ")" 
          << endl;
 }
Ejemplo n.º 9
0
 std::string PoissonDeviate::make_repr(bool incl_seed)
 {
     std::ostringstream oss(" ");
     oss << "galsim.PoissonDeviate(";
     if (incl_seed) oss << seedstring(split(serialize(), ' ')) << ", ";
     oss << "mean="<<getMean()<<")";
     return oss.str();
 }
Ejemplo n.º 10
0
double
BetaRV::getInverseCDFvalue(double probValue)
{
	double result = 0.0;
	// Here we want to solve the nonlinear equation:
	//         probValue = getCDFvalue(x)
	// with respect to x. 
	// A Newton scheme to find roots - f(x)=0 - looks something like:
	//         x(i+1) = x(i) - f(xi)/f'(xi)
	// In our case the function f(x) is: f(x) = probValue - getCDFvalue(x)
	// The derivative of the function can be found approximately by a
	// finite difference scheme where e.g. stdv/200 is used as perturbation.
	double tol = 0.000001;
	double x_old = getMean();   // Start at the mean of the random variable
	double x_new;
	double f;
	double df;
	double h;
	double perturbed_f;
	for (int i=1;  i<=100;  i++ )  {

		// Evaluate function
		f = probValue - getCDFvalue(x_old);
		// Evaluate perturbed function
		h = getStdv()/200.0;
		perturbed_f = probValue - getCDFvalue(x_old+h);

		// Evaluate derivative of function
		df = ( perturbed_f - f ) / h;

		if ( fabs(df) < 1.0e-15) {
			opserr << "WARNING: BetaRV::getInverseCDFvalue() -- zero derivative " << endln
				<< " in Newton algorithm. " << endln;
		}
		else {

			// Take a Newton step
			x_new = x_old - f/df;
			
			// Check convergence; quit or continue
			if (fabs(1.0-fabs(x_old/x_new)) < tol) {
				return x_new;
			}
			else {
				if (i==100) {
					opserr << "WARNING: Did not converge to find inverse CDF!" << endln;
					return 0.0;
				}
				else {
					x_old = x_new;
				}
			
			}
		}
	}

	return result;
}
Ejemplo n.º 11
0
double AnalogSampler::getVariance()
{
    if (_n < 2) {
        return 0;
    } else {
	    double m = getMean();
	    return (_sumOfSquares - (_n * m * m)) / (_n - 1);
    }	    
}
Ejemplo n.º 12
0
 std::string GaussianDeviate::make_repr(bool incl_seed)
 {
     std::ostringstream oss(" ");
     oss << "galsim.GaussianDeviate(";
     if (incl_seed) oss << "seed='"<<serialize()<<"', ";
     oss << "mean="<<getMean()<<", ";
     oss << "sigma="<<getSigma()<<")";
     return oss.str();
 }
Ejemplo n.º 13
0
XC::LaplaceRV::LaplaceRV(int passedTag, 
		 double passedMean,
		 double passedStdv)
:RandomVariable(passedTag, RANDOM_VARIABLE_laplace)
{
	tag = passedTag ;
	alpha = passedMean;
	beta = sqrt(2.0)/passedStdv;
	startValue = getMean();
}
Ejemplo n.º 14
0
XC::ShiftedExponentialRV::ShiftedExponentialRV(int passedTag, 
		 double passedMean,
		 double passedStdv)
:RandomVariable(passedTag, RANDOM_VARIABLE_shiftedexponential)
{
	tag = passedTag ;
	lambda = 1/passedStdv;
	x0 = passedMean - passedStdv;
	startValue = getMean();
}
Ejemplo n.º 15
0
XC::UniformRV::UniformRV(int passedTag, 
		 double passedMean,
		 double passedStdv)
:RandomVariable(passedTag, RANDOM_VARIABLE_uniform)
{
	tag = passedTag;
	a = passedMean - sqrt(3.0)*passedStdv;
	b = passedMean + sqrt(3.0)*passedStdv;
	startValue = getMean();
}
Ejemplo n.º 16
0
		double Statistics::sq(const Eigen::MatrixXd& m, int col, double mean)
		{
			if (mean == -1) {	mean = getMean(m, col); }
			double sum_of_squares = 0;
			for (int i = 0; i < m.rows(); i++)
			{
				sum_of_squares += pow(m(i, col)-mean, 2);
			}
			return sum_of_squares;
		}
Ejemplo n.º 17
0
		double Statistics::getVariance(const vector<double>& v, double mean)
		{
			if (mean == -1) {	mean = getMean(v); }
			double sum_of_squares = 0;
			for (unsigned int i = 0; i < v.size(); i++)
			{
				sum_of_squares += (v[i]-mean)*(v[i]-mean);
			}
			return sum_of_squares/(v.size()-1);
		}
Ejemplo n.º 18
0
    void DataFromNexus::printLatencyData(const std::string& filename) const {

        std::ofstream outF(filename);
        for (auto& e : latencyData_) {
            outF << "Name     : " << e.first << endl;
            outF << "#frames  : " << e.second.size() << std::endl;
            outF << "mean (s) : " << getMean(e.second) << std::endl;
            outF << "std (s)  : " << getStd(e.second) << std::endl;
        }
        outF.close();
    }
Ejemplo n.º 19
0
ExecutionState *MergeHandler::getPrioritizeState(){
  for (ExecutionState *cur_state : openStates) {
    bool stateIsClosed = (executor->inCloseMerge.find(cur_state) !=
                          executor->inCloseMerge.end());

    if (!stateIsClosed && (getInstructionDistance(cur_state) < 2 * getMean())) {
      return cur_state;
    }
  }
  return 0;
}
Ejemplo n.º 20
0
XC::LaplaceRV::LaplaceRV(int passedTag, 
		 double passedParameter1,
		 double passedParameter2,
		 double passedParameter3,
		 double passedParameter4)
:RandomVariable(passedTag, RANDOM_VARIABLE_laplace)
{
	tag = passedTag ;
	alpha = passedParameter1;
	beta = passedParameter2;
	startValue = getMean();
}
Ejemplo n.º 21
0
XC::ShiftedExponentialRV::ShiftedExponentialRV(int passedTag, 
		 double passedParameter1,
		 double passedParameter2,
		 double passedParameter3,
		 double passedParameter4)
:RandomVariable(passedTag, RANDOM_VARIABLE_shiftedexponential)
{
	tag = passedTag ;
	lambda = passedParameter1;
	x0 = passedParameter2;
	startValue = getMean();
}
Ejemplo n.º 22
0
XC::UniformRV::UniformRV(int passedTag, 
		 double passedParameter1,
		 double passedParameter2,
		 double passedParameter3,
		 double passedParameter4)
:RandomVariable(passedTag,RANDOM_VARIABLE_uniform)
{
	tag = passedTag ;
	a = passedParameter1;
	b = passedParameter2;
	startValue = getMean();
}
Ejemplo n.º 23
0
// return the standard deviation
double KeyListOpsMethods::getSampleStddev() {
	if (empty()) return NAN;

	double avg = getMean();
	double squareDiffSum = 0.0;
	for (begin(); !end(); next()) {
		double val = getColValNum();
		double diff = val - avg;
		squareDiffSum += diff * diff;
	}
	return  squareDiffSum / ((float)getCount() - 1.0);
}
Ejemplo n.º 24
0
void Background::computeBasicModel() {
//  std::cout << "Computing basic background model.." << std::endl;
  assert(video.isOpened());

  cv::Mat frame, gray;

  // read frame by frame and process
  while(video.read(frame)) {
      // convert to grayscale and apply Gaussian blur
      cv::cvtColor(frame, gray, CV_RGB2GRAY);
      grayscaleGaussianBlur(gray, gray, 5);

      for (int row = 0; row < gray.rows; ++row) {
#pragma omp parallel for
          for (int col = 0; col < gray.cols; ++col) {
              pixels[row * width + col].push_back((int)gray.at<uchar>(row, col));
            }
        }

      frames.push_back(gray.clone());

    }

  // compute medians and get background model
  for (int row = 0; row < backgroundModel.rows; ++row) {
#pragma omp parallel for
      for (int col = 0; col < backgroundModel.cols; ++col) {
          backgroundModel.at<uchar>(row, col) = getMean(pixels[row * width + col]);
        }
    }

  cv::Mat hist;
  cv::Mat centralBgModel = cv::Mat(backgroundModel, cv::Range(0, backgroundModel.rows*(1.0 - MARGIN_BOTTOM)), cv::Range(backgroundModel.cols * MARGIN_SIDE, backgroundModel.cols*(1.0 - MARGIN_SIDE)));
  bgModelHist = computeHistogram(centralBgModel);
  drawHistogram(bgModelHist, hist);

//  cv::namedWindow( "Background", CV_WINDOW_AUTOSIZE );
//  cv::imshow( "Background", backgroundModel );
//  cv::namedWindow( "Histogram", CV_WINDOW_AUTOSIZE );
//  cv::imshow( "Histogram", hist );

  adjustBackgroundModel();
  drawHistogram(bgModelHist, hist);

//  cv::namedWindow( "Adjusted background", CV_WINDOW_AUTOSIZE );
//  cv::imshow( "Adjusted background", backgroundModel );
//  cv::namedWindow( "Adjusted histogram", CV_WINDOW_AUTOSIZE );
//  cv::imshow( "Adjusted histogram", hist );
//  cv::waitKey(0);

//  exit(0);
}
Ejemplo n.º 25
0
VectorDouble MatrixDouble::getStdDev() const{
    
    VectorDouble mean = getMean();
	VectorDouble stdDev(cols,0);
	
	for(unsigned int j=0; j<cols; j++){
		for(unsigned int i=0; i<rows; i++){
			stdDev[j] += (dataPtr[i][j]-mean[j])*(dataPtr[i][j]-mean[j]);
		}
		stdDev[j] = sqrt( stdDev[j] / double(rows-1) );
	}
    return stdDev;
}
Ejemplo n.º 26
0
		void Statistics::centering(vector<double>& v, double& mean, double& std)
		{
			mean = getMean(v);
			std = sqrt(getVariance(v, mean));

			// standard deviation = 0, i.e. all values of this vector are identical, so do nothing!
			if (std < 5*std::numeric_limits < double > ::epsilon()) return; 

			for (unsigned int i = 0; i < v.size(); i++)
			{
				v[i] = (v[i]-mean)/std;
			}
		}
Ejemplo n.º 27
0
		void Statistics::centering(Eigen::MatrixXd& m, int col)
		{
			double mean = getMean(m, col);
			double std = sqrt(getVariance(m, col, mean));
	
			// standard deviation = 0, i.e. all values of this column are identical, so do nothing!
			if (std < 5*std::numeric_limits < double > ::epsilon()) return; 
	
			for (int i = 0; i < m.rows(); i++)
			{
				m(i, col) = (m(i, col)-mean)/std;
			}
		}
	/**
	* @return standard deviation of the buffer
	*/
	const double getStandardDeviation()
	{
		double standardDeviation=0;
		double meanValue=getMean();

		type *bufferPTR=Buffer();
		for (unsigned int i=0;i<this->size();++i)
		{
			double diff=(*(bufferPTR++)-meanValue);
			standardDeviation+=diff*diff;
		}
		return sqrt(standardDeviation/this->size());
	};
Ejemplo n.º 29
0
int MedianFilter::getStDev()  // Arduino run time [us]: filterSize * 2 + 131
{
   int32_t diffSquareSum = 0;
   int mean = getMean();

   for( int i = 0; i < medFilterWin; i++ )
   {
      int diff = data[i] - mean;
      diffSquareSum += diff * diff;
   }

   return int( sqrtf( float(diffSquareSum) / float(medFilterWin - 1) ) + 0.5f );
}
Ejemplo n.º 30
0
    double BaseStat::getConfInterval(CONFIDENCE_INTERVAL c)
    {
        double mu;		// the mean
        double s;		// the variance
  
        if (!_endOfSim) throw Exc(GET);
        if (!_initFlag) throw Exc(NO_INIT);
        if (_expNum < 3) throw Exc(NEED_3);

        mu = getMean();
        s = getVariance();
        return t_student(c, (unsigned int) _expNum - 1) * s;
    }