shared_ptr<Image3>& ImageStats::getImageVar(int ft, bool normalize){
	if (normalize){
		for (int c = 0 ; c <  COLOR_CHS ; c++){
			m_varMin[ft][c] = std::numeric_limits<float>::max();
			m_varMax[ft][c] = std::numeric_limits<float>::min();
			for (int x = 0 ; x < m_w ; x++){
				for (int y = 0 ; y < m_h ; y++){
					if ( getVariance(x,y,ft,c) < m_varMin[ft][c])  m_varMin[ft][c] = getVariance(x,y,ft,c);
					if ( getVariance(x,y,ft,c) > m_varMax[ft][c])  m_varMax[ft][c] = getVariance(x,y,ft,c);
				}
			}
		}
		for (int x = 0 ; x < m_w ; x++)
			for (int y = 0 ; y < m_h ; y++)
				m_imageVar[ft]->fastSet(x,y,Color3((getVariance(x,y,ft,RED) - m_varMin[ft][RED])/(m_varMax[ft][RED] - m_varMin[ft][RED]),
											       (getVariance(x,y,ft,GREEN) - m_varMin[ft][GREEN])/(m_varMax[ft][GREEN] - m_varMin[ft][GREEN]),
											       (getVariance(x,y,ft,BLUE) - m_varMin[ft][BLUE])/(m_varMax[ft][BLUE] - m_varMin[ft][BLUE])));
	}
	else{
		for (int x = 0 ; x < m_w ; x++)
			for (int y = 0 ; y < m_h ; y++)
				m_imageVar[ft]->fastSet(x,y,Color3(getVariance(x,y,ft,RED),getVariance(x,y,ft,GREEN),getVariance(x,y,ft,BLUE)));
	}
	return m_imageVar[ft];
}
double
StatisticalTimer::getStdDev( sTimerID id ) const
{
	double	variance	= getVariance( id );

	return	sqrt( variance );
}
Exemple #3
0
double
statTimer::getStdDev( size_t id ) const
{
	double	variance	= getVariance( id );

	return	sqrt( variance );
}
Exemple #4
0
float FloatArray::getStandardDeviation(){
  float result;
/// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a>
#ifdef ARM_CORTEX  
  arm_std_f32 (data, size, &result);
#else
  result=sqrtf(getVariance());
#endif
  return result;
}
Exemple #5
0
cv::Rect selectBestRectByVariance(std::vector<cv::Point>& poly, std::vector<cv::Rect>& vrect, cv::Rect cur)
{
    double min=-1;
    int idx=-1;

    for(int i=0; i<vrect.size(); i++){
        if(isRectInPolygon(poly, vrect[i])){
            if(min<0){
                min=getVariance(poly, vrect[i]);
                idx=i;
            }else{
                double var=getVariance(poly, vrect[i]);
                if(var<min){ min=var; idx=i; }
            }
        }
    }

    if(idx>=0) return vrect[idx];
    else return cur;
}
bool RollingValueStore :: getStdDev(char* key,float* result)
{
	bool isVarianceSuccessfullyRetrieved  = getVariance(key,result);
	if(isVarianceSuccessfullyRetrieved) {
		*result = sqrt(*result);
		return true;
	}
	else {
		return false;
	}
}
Exemple #7
0
		void Statistics::scaling(vector<double>& v)
		{
			double std = sqrt(getVariance(v));
	
			// 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] /= std;
			}
		}
Exemple #8
0
void CybMLM::checkVariables()
{
	for(int i=0; i < getVariablesNumber(); i++)
		if(getVariance(i))
			this->variables->insert(i);
	
	this->precisionMatrix = new float[getVariablesNumber()*getVariablesNumber()];
	
	this->determinat = CybMatrixOperator::matrixDeterminant(covariance, variables->size());
	
	CybMatrixOperator::matrixInverse(covariance,this->precisionMatrix,variables->size(),determinat);	
}
std::vector< StatData >
GpuStatTimer::getStdDev( size_t id )
{
	std::vector< StatData > stddev = getVariance( id );

	for( cl_uint v = 0; v < stddev.size( ); ++v )
	{
		stddev[ v ].doubleNanoSec = sqrt( stddev[ v ].doubleNanoSec );
	}

	return stddev;
}
Exemple #10
0
void inline unitTestKMeansRandomly(Group &test, std::ofstream &output) {
    // 数据归一化
    // normaliztion(test);

    // 输出读入的数据
    // puts("Print Input Data:");
    // puts("=====================================");
    // test.display();
    // puts("=====================================\n");

    // k 值
    const unsigned k = 3;

    /** 准备测试数据 */
    // KMeans++
    // std::vector<Group> centroid = buildInitialPointRandomly(k, test);
    // Kmeans + Density initialize
    // std::vector<Group> centroid = buildInitialPointDensity(k, test);
    // KMeans
    // std::vector<Group> centroid = buildInitialPoint(k, test);

    output << "===============================================" << std::endl;
    output << "buildInitialPointRandomly" << std::endl;
    output << "===============================================" << std::endl;
    // 重复运行测试
    std::vector<Group> result;
    std::vector<double> avg(k);
    double SSE = 0;
    // 记录每次的 SSE 值
    std::vector<double> vecSSE;
    time_t start = std::clock();
    // 重复实验的次数
    for (unsigned i = 0; i < TIMES; ++i) {
        printf("running: %d\r", i);
        result = KMeans(test, k, buildInitialPointRandomly(k, test), false);
        SSE = 0;
        for (unsigned j = 0; j < result.size(); ++j) {
            SSE += result[j].getSumOfEuclideanDistance();
            vecSSE.push_back(SSE / result.size());
        }
    }
    time_t end = std::clock();
    output << "The average of SSE = " << getAverage(vecSSE) << std::endl;
    output << "The variance of SSE = " << getVariance(vecSSE) << std::endl;
    output << "The running time is: " << double(end - start) / CLOCKS_PER_SEC << std::endl;
    // printf("The average of SSE = %lf\n", getAverage(vecSSE));
    // printf("The variance of SSE = %lf\n", getVariance(vecSSE));
    printf("the running time is : %f\n", double(end - start) / CLOCKS_PER_SEC);
    output << "===============================================" << std::endl;
    // puts("===============================================");
    // KMedoids(test, k, centroid);
}
void ParticleManager::setVisibleNParticles(int n)
{
	int activatedParticles = 0;
	for (int i = 0; i < MAX_NUMBER_PARTICLES; i++)
	{
		if (!particles[i].getActive()) //found an inactive particle
		{
			particles[i].setActive(true);
			particles[i].setMaxTimeAlive(MAX_PARTICLE_LIFETIME*getVariance());
			float newX = velocity.x * getVariance(); 
			float newY = velocity.y  * getVariance();
			VECTOR2 v = VECTOR2(newX,newY);
			particles[i].setX(position.x);
			particles[i].setY(position.y);
			particles[i].setVelocity(v);
			particles[i].setVisible(true);
			activatedParticles++;
			if (activatedParticles == n)
				return;
		}
	}
}
Exemple #12
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;
    }
Exemple #13
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;
			}
		}
Exemple #14
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;
			}
		}
Exemple #15
0
PRFloat64 getStdDev(VarianceState* inVariance)
/*
**  Determine the standard deviation based on the given state.
*/
{
    PRFloat64 retval = 0.0;
    PRFloat64 variance;

    variance = getVariance(inVariance);
    retval = sqrt(variance);

    return retval;
}
    std::unique_ptr<Image> intensityPatch(const std::unique_ptr<Image>& image,
            float mean, float stdev)
    {
        if (image->getChannelNum() != 1)
            return std::unique_ptr<Image>();

        const auto orig_data_ptr = image->getValues(0);
        const auto w = image->getWidth();
        const auto h = image->getHeight();

        float current_mean = 0;
        for (size_t j = 0; j < h; j++)
        {
            for (size_t i = 0; i < w; i++)
            {
                current_mean += orig_data_ptr[j*w + i];
            }
        }
        current_mean /= (w*h);

        float current_var = getVariance(image);
        if (std::isfinite(current_var) && !std::isnormal(current_var))
        {
            // if the sum of squares of errors is equal to zero or is subnormal,
            // then just fill the result image with (0.5) in order to aviod
            // divide-by-zero exception
            auto newImage = std::make_unique<Image>(w, h, 1);
            for (size_t j = 0; j < h; j++)
            {
                for (size_t i = 0; i < w; i++)
                {
                    (newImage->getValues(0))[j*w + i] = 0.5;
                }
            }
            return newImage;
        }

        float alpha = stdev * std::sqrt(1.0 / current_var);

        auto newImage = std::make_unique<Image>(w, h, 1);
        for (size_t j = 0; j < h; j++)
        {
            for (size_t i = 0; i < w; i++)
            {
                (newImage->getValues(0))[j*w + i] = alpha * (orig_data_ptr[j*w + i]
                        - current_mean) + mean;
            }
        }
        return newImage;
    }
Exemple #17
0
double GROUP::calculateUCB(int total)
{
    //ucb_tuned1
    double v = getVariance() + sqrt(2*log(total) / AllUsedNumber);
    double V = (v>0.25) ? 0.25 : v;
    double max = getmax() , min = getmin();
    double newMean;
    if(max == min)
	newMean = 1.0;
    else
	newMean = (getMean() - min ) / (max - min);
    double tmp = newMean - sqrt(log(total) / AllUsedNumber *V);
    return tmp;
}
Exemple #18
0
  virtual int selectNextArm(){
    double n = vectorSum(Ni);
    std::vector<double> indices = std::vector<double>(K, 0.0);
    for(uint k=0;k<K;++k){
      if(Ni[k]==0){
        return k;
      }
      double variance = getVariance(k);
      //UCB-V index
      indices[k] = (Gi[k]/Ni[k]) + sqrt( (2 * zeta * variance * log(n)) / (double)Ni[k] ) + 3 * amp * zeta * log(n)/(double)Ni[k];
    }

    int targetArm = vectorMaxIndex(indices);

    return targetArm;
  }
    PriorBoxLayerImpl(const LayerParams &params)
    {
        setParamsFrom(params);
        _minSize = getParameter<unsigned>(params, "min_size");
        CV_Assert(_minSize > 0);

        _flip = getParameter<bool>(params, "flip");
        _clip = getParameter<bool>(params, "clip");

        _aspectRatios.clear();
        _aspectRatios.push_back(1.);

        getAspectRatios(params);
        getVariance(params);

        _numPriors = _aspectRatios.size();

        _maxSize = -1;
        if (params.has("max_size"))
        {
            _maxSize = params.get("max_size").get<float>(0);
            CV_Assert(_maxSize > _minSize);

            _numPriors += 1;
        }

        if (params.has("step_h") || params.has("step_w")) {
          CV_Assert(!params.has("step"));
          _stepY = getParameter<float>(params, "step_h");
          CV_Assert(_stepY > 0.);
          _stepX = getParameter<float>(params, "step_w");
          CV_Assert(_stepX > 0.);
        } else if (params.has("step")) {
          const float step = getParameter<float>(params, "step");
          CV_Assert(step > 0);
          _stepY = step;
          _stepX = step;
        } else {
          _stepY = 0;
          _stepX = 0;
        }
    }
    PriorBoxLayerImpl(const LayerParams &params)
        : _boxWidth(0), _boxHeight(0)
    {
        setParamsFrom(params);
        _minSize = getParameter<float>(params, "min_size", 0, false, 0);
        _flip = getParameter<bool>(params, "flip", 0, false, true);
        _clip = getParameter<bool>(params, "clip", 0, false, true);
        _bboxesNormalized = getParameter<bool>(params, "normalized_bbox", 0, false, true);

        _scales.clear();
        _aspectRatios.clear();

        getAspectRatios(params);
        getVariance(params);
        getParams("scales", params, &_scales);
        getParams("width", params, &_widths);
        getParams("height", params, &_heights);
        _explicitSizes = !_widths.empty();
        CV_Assert(_widths.size() == _heights.size());

        if (_explicitSizes)
        {
            CV_Assert(_aspectRatios.empty(), !params.has("min_size"), !params.has("max_size"));
            _numPriors = _widths.size();
        }
        else
        {
            CV_Assert(!_aspectRatios.empty(), _minSize > 0);
            _numPriors = _aspectRatios.size() + 1;  // + 1 for an aspect ratio 1.0
        }

        _maxSize = -1;
        if (params.has("max_size"))
        {
            _maxSize = params.get("max_size").get<float>(0);
            CV_Assert(_maxSize > _minSize);

            _numPriors += 1;
        }

        if (params.has("step_h") || params.has("step_w")) {
          CV_Assert(!params.has("step"));
          _stepY = getParameter<float>(params, "step_h");
          CV_Assert(_stepY > 0.);
          _stepX = getParameter<float>(params, "step_w");
          CV_Assert(_stepX > 0.);
        } else if (params.has("step")) {
          const float step = getParameter<float>(params, "step");
          CV_Assert(step > 0);
          _stepY = step;
          _stepX = step;
        } else {
          _stepY = 0;
          _stepX = 0;
        }
        if (params.has("offset_h") || params.has("offset_w"))
        {
            CV_Assert(!params.has("offset"), params.has("offset_h"), params.has("offset_w"));
            getParams("offset_h", params, &_offsetsY);
            getParams("offset_w", params, &_offsetsX);
            CV_Assert(_offsetsX.size() == _offsetsY.size());
            _numPriors *= std::max((size_t)1, 2 * (_offsetsX.size() - 1));
        }
        else
        {
            float offset = getParameter<float>(params, "offset", 0, false, 0.5);
            _offsetsX.assign(1, offset);
            _offsetsY.assign(1, offset);
        }
    }
Exemple #21
0
double Variable::getStddev() const
{
    return std::sqrt(getVariance());
}
Exemple #22
0
 void Accumulator::getStdDev(double &val) const 
 {
   getVariance(val);
   val = sqrt(val);
 }
void makeTree(node* root, int* aSet, int rows, int cols)
{
	int* vector = NULL;
	double* varianceVector;
	double* varianceVectorCpy;
	int* maxVarianceVector;
	double maxVariance;
	int maxVarianceIdx;
	double* median;
	int i;
	int leftSize = 0;
	int rightSize = 0;
	double vectorVal;
	int* leftSet;
	int* rightSet;
	node* leftNode;
	node* rightNode;
	int j = 0;
	int a = 0;

	leftNode = (node*) malloc(sizeof(node));
	leftNode->dimNumber = -1;
	leftNode->dimVal = -1;
	leftNode->left = NULL;
	leftNode->right = NULL;
	leftNode->isLeaf = 0;
	leftNode->leafVector = NULL;
	leftNode->id = NULL;

	rightNode = (node*) malloc(sizeof(node));
	rightNode->dimNumber = -1;
	rightNode->dimVal = -1;
	rightNode->left = NULL;
	rightNode->right = NULL;
	rightNode->isLeaf = 0;
	rightNode->leafVector = NULL;
	rightNode->id = NULL;

	//printf("nodes left: %d\n", nodes);
	//vector = getDimensionVector(1, aSet, rows, cols);

	varianceVector = (double*) malloc(cols * sizeof(double) );
	median = (double*) malloc(sizeof(double));

	if (median == NULL)
	{
		a = 1; 
	}

	for (i = 0; i < cols; i++)
	{
		vector = getDimensionVector(i, aSet, rows, cols);
		getVariance(&varianceVector[i], vector, rows);
		free(vector);
	}

	varianceVectorCpy = (double*) malloc(cols*sizeof(double));

	varianceVectorCpy = (double*) memcpy(varianceVectorCpy, varianceVector, cols*sizeof(double));

	qsort(varianceVectorCpy, cols, sizeof(double), dCmpfunc);

	//for (i = 0; i < cols; i++)
	//{
	//	printf("%f ", varianceVectorCpy[i]);
	//}

	for (i = 0; i < cols; i++)
	{
		maxVariance = varianceVectorCpy[cols-1-i];

		if (maxVariance != 0.0)
		{
			break;
		}
	}
	
	//if (maxVariance == 0.0)
	//{
	//	for (i = 0; i < cols; i++)
	//	{
	//		printf("%f ", varianceVectorCpy[i]);
	//	}

	//	printf("\n");
	//	printf("\n");
	//	printf("------------------------");



	//	for (i = 0; i < cols; i++)
	//	{
	//		printf("%f ", varianceVector[i]);
	//	}

	//	printf("\n");
	//	printf("\n");
	//	printf("\n");
	//	for (i =0; i < rows; i++)
	//	{
	//		for (j = 0; j < cols; j++)
	//		{
	//			printf("%d ", aSet[i+j]);
	//		}
	//		printf("\n");
	//	}
	//	a = 1;
	//}

	// find dimension number with max variance
	for (i = 0; i < cols; i++)
	{
		if (varianceVector[i] == maxVariance )
		{
			maxVarianceIdx = i;
		}
	}

	// get max variance axe
	maxVarianceVector = getDimensionVector(maxVarianceIdx, aSet, rows, cols);
	getMedian(median, maxVarianceVector, rows);

	
	// create two arrays
	// determine array sizes
	for (i = 0; i < rows; i++)
	{
		vectorVal = (double) maxVarianceVector[i];

		if (vectorVal <= *median)
		{ leftSize++; }
		else
		{ rightSize++; }
	}

	// set root values
	root->dimNumber = maxVarianceIdx;
	root->dimVal = *median;

	// get memory from branches
	leftSet = (int*) malloc(cols * leftSize * sizeof(int));
	rightSet = (int*) malloc(cols * rightSize * sizeof(int));

	// reset counters
	leftSize = 0;
	rightSize = 0;

	

	// split aSet into two parts according to median value 
	for (i = 0; i < rows; i++)
	{

		vectorVal = (double) maxVarianceVector[i];

		if (vectorVal <= *median)
		{ 
			memcpy(&leftSet[leftSize * cols], &aSet[i * cols], cols * sizeof(int)); 
			leftSize++;
		}
		else
		{ 
			memcpy(&rightSet[rightSize * cols], &aSet[i * cols], cols * sizeof(int));
			rightSize++; 
		}
	}

	//free(vector);
	free(varianceVector);
	free(varianceVectorCpy);
	free(maxVarianceVector);
	free(aSet); // delete input set (matrix) to store some memory. In futher calculation it is not used. Used only its split version
	free(median);
	
	// making a leaf or node for right and left root branches
	if (leftSize > 1)
	{
		root->left = leftNode;
		makeTree(leftNode, leftSet, leftSize, cols);
	}
	else
	{
		leftNode->isLeaf = 1;
		leftNode->leafVector = leftSet;
		root->left = leftNode;
		nodes--;
	}

	if (rightSize > 1)
	{
		root->right = rightNode;
		makeTree(rightNode, rightSet, rightSize, cols );
	}
	else
	{
		rightNode->isLeaf = 1;
		rightNode->leafVector = rightSet;
		root->right = rightNode;
		nodes--;
	}
}
Exemple #24
0
double CSimpleStat::getStdev() const
{
  return sqrt(std::max(0.0, getVariance()));
}
Exemple #25
0
		double Statistics::getStddev(const vector<double>& v, double mean)
		{
			double var = getVariance(v, mean);
			return sqrt(var);
		}
Exemple #26
0
 double
 Statistic::getStandardDeviation() const {
     return sqrt(getVariance());
 }
Exemple #27
0
		double Statistics::getStddev(const Eigen::MatrixXd& m, int col, double mean)
		{
			double d = getVariance(m, col, mean);
			return sqrt(d);
		}
Exemple #28
0
 double getStddev() const { return sqrt(getVariance()); }
    PriorBoxLayerImpl(const LayerParams &params)
    {
        setParamsFrom(params);
        _minSize = getParameter<float>(params, "min_size", 0, false, 0);
        _flip = getParameter<bool>(params, "flip", 0, false, true);
        _clip = getParameter<bool>(params, "clip", 0, false, true);
        _bboxesNormalized = getParameter<bool>(params, "normalized_bbox", 0, false, true);

        _aspectRatios.clear();

        getAspectRatios(params);
        getVariance(params);

        _maxSize = -1;
        if (params.has("max_size"))
        {
            _maxSize = params.get("max_size").get<float>(0);
            CV_Assert(_maxSize > _minSize);
        }

        std::vector<float> widths, heights;
        getParams("width", params, &widths);
        getParams("height", params, &heights);
        _explicitSizes = !widths.empty();
        CV_Assert(widths.size() == heights.size());

        if (_explicitSizes)
        {
            CV_Assert(_aspectRatios.empty());
            CV_Assert(!params.has("min_size"));
            CV_Assert(!params.has("max_size"));
            _boxWidths = widths;
            _boxHeights = heights;
        }
        else
        {
            CV_Assert(_minSize > 0);
            _boxWidths.resize(1 + (_maxSize > 0 ? 1 : 0) + _aspectRatios.size());
            _boxHeights.resize(_boxWidths.size());
            _boxWidths[0] = _boxHeights[0] = _minSize;

            int i = 1;
            if (_maxSize > 0)
            {
                // second prior: aspect_ratio = 1, size = sqrt(min_size * max_size)
                _boxWidths[i] = _boxHeights[i] = sqrt(_minSize * _maxSize);
                i += 1;
            }

            // rest of priors
            for (size_t r = 0; r < _aspectRatios.size(); ++r)
            {
                float arSqrt = sqrt(_aspectRatios[r]);
                _boxWidths[i + r] = _minSize * arSqrt;
                _boxHeights[i + r] = _minSize / arSqrt;
            }
        }
        CV_Assert(_boxWidths.size() == _boxHeights.size());
        _numPriors = _boxWidths.size();

        if (params.has("step_h") || params.has("step_w")) {
          CV_Assert(!params.has("step"));
          _stepY = getParameter<float>(params, "step_h");
          CV_Assert(_stepY > 0.);
          _stepX = getParameter<float>(params, "step_w");
          CV_Assert(_stepX > 0.);
        } else if (params.has("step")) {
          const float step = getParameter<float>(params, "step");
          CV_Assert(step > 0);
          _stepY = step;
          _stepX = step;
        } else {
          _stepY = 0;
          _stepX = 0;
        }
        if (params.has("offset_h") || params.has("offset_w"))
        {
            CV_Assert(!params.has("offset"), params.has("offset_h"), params.has("offset_w"));
            getParams("offset_h", params, &_offsetsY);
            getParams("offset_w", params, &_offsetsX);
            CV_Assert(_offsetsX.size() == _offsetsY.size());
            _numPriors *= std::max((size_t)1, 2 * (_offsetsX.size() - 1));
        }
        else
        {
            float offset = getParameter<float>(params, "offset", 0, false, 0.5);
            _offsetsX.assign(1, offset);
            _offsetsY.assign(1, offset);
        }
    }
void ExperimentalTrajectory::getDesiredValues(double time, Eigen::MatrixXd& desiredValues, Eigen::VectorXd& variance)
{
    desiredValues = getDesiredValues(time);
    variance = getVariance(time);

}