コード例 #1
0
//for correlation coefficient
double ProfileMatchView::calculateSpearmansCorrelation(const QVector<float>& Demand,const QVector<float>& Supply)
{
	int TimeSteps = (int)Demand.size();
	double SupplyMean = 0.0;
	double DemandMean = 0.0;
	double m_CorrCoeff = 0.0;
	SupplyMean = calculateMean(Supply);
	DemandMean = calculateMean(Demand);
	double SSS,SSD,SSSD;
	SSS=SSD=SSSD=0;
	for (int i=0;i<TimeSteps;++i)
	{
		SSS+=pow(Supply[i]-SupplyMean,2);
		SSD+=pow(Demand[i]-DemandMean,2);
		SSSD+=(Supply[i]-SupplyMean)*(Demand[i]-DemandMean);
	}
	double Denom=pow(SSS*SSD,0.5);
	m_CorrCoeff=SSSD/Denom;
	if ((SSSD==0)&&(Denom==0)&&(SupplyMean<=1.00001f*DemandMean)&&
		(SupplyMean>=0.999999f*DemandMean))
	{
		m_CorrCoeff=1.0f;	
	}
	return m_CorrCoeff;
}
コード例 #2
0
ファイル: Source.cpp プロジェクト: juanvallejo/cpp5
int main() {
	std::vector<measurement> readings, withinOne, notWithinOne;
	stats out_stats;

	//Get information from file
	readFromFile("TestData.txt", readings);

	out_stats.mean = calculateMean(readings);
	out_stats.standard_dev = calculateStdDev(readings);
	out_stats.totalmeasurements = getTotalMeasurements(readings);

	isWithinOne(readings, withinOne, notWithinOne, out_stats.mean, out_stats.standard_dev);

	out_stats.totalMeasurements_withinOneStdDev = withinOne.size();
	out_stats.totalMeasurements_outsideOneStdDev = notWithinOne.size();

	readings.clear(); //no longer need readings

	sort(withinOne);
	sort(notWithinOne);
	
	print_to_file(withinOne, notWithinOne, out_stats);

	withinOne.clear();
	notWithinOne.clear();

	return 0;
}
コード例 #3
0
float Measures::calculateVariance()
{
    double sumDiff = 0.0;
    double mean = calculateMean();
    for (Feature f : featureCol)
        sumDiff += qPow(f - mean, 2);
    return sumDiff / featureCol.size();
}
void Sbs2SourceReconstrucionLoreta::reconstruct()
{

    if (sumType == MEAN)
	calculateMean();
    if (sumType == POWER)
	calculatePower();
}
コード例 #5
0
JNIEXPORT void JNICALL
Java_com_dsp_signalstatistics_NativeStatistics_cov(JNIEnv *env, jclass type,
                                                             jobject guiCallback) {
    float cov = 0;
    float xMean = 0;
    float yMean = 0;
    int i;

    //Calculate both means
    xMean = calculateMean(RND);
    yMean = calculateMean(RND2);

    for(i = 0; i < LENGTH; i++)
        cov += (RND[i] - xMean) * (RND2[i] - yMean);

    //Divide by N - 1
    cov = cov / (LENGTH - 1);

    notify(env, guiCallback,"Covariance: %.12g", cov);
}
コード例 #6
0
ファイル: main.cpp プロジェクト: RDeckers/QIsingSim
//TODO: add timer
void run(int size, double coupling, IsingModel<dimensions>::Algorithms algo, int sweeps){
  QElapsedTimer timer;
  timer.start();
  QVector<int> energies(nModels);
  QVector<int> absoluteMagnetism(nModels);
  QFile file(QString("./%3d_%0_%1_%2.dat").arg(size).arg(coupling).arg(algo).arg(dimensions));
  if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
      std::cout << "Couldn't open file " << file.fileName().toStdString() << std::endl;
      return;
    }
  QTextStream out(&file);
  std::cout << "Starting with " << file.fileName().toStdString() << std::endl;
  IsingModel<dimensions> ising[nModels];
  QVector<double> magnetization, magnetizationVariance;
  QVector<double> energy, energyVariance;
  for(int k = 0; k < nModels; k++){
      ising[k].setSize(size);
      ising[k].setAlgorithm(algo);
      ising[k].setCoupling(coupling);
    }
  out << dimensions << " " << size << " " <<  coupling <<  " " << nModels << "\n\n";
  out << ising[0].getMagnetization() << " " << sqrt(0) << " " << ising[0].getEnergy() << " " << sqrt(0) << "\n";
  for(int i = 0; i < sweeps;i++){
    for(int k = 0; k < nModels;k++){
          ising[k].sweep();
          absoluteMagnetism[k] = abs(ising[k].getMagnetization());
          energies[k] =  ising[k].getEnergy();
        }
      double magneticMean = calculateMean(absoluteMagnetism);
      magnetization.append(magneticMean);
      magnetizationVariance.append(calculateVariance(absoluteMagnetism, magneticMean));
      double energyMean = calculateMean(energies);
      energy.append(energyMean);
      energyVariance.append(calculateVariance(energies, energyMean));
  }
  for(int i = 0; i < magnetization.size();i++)
    out << magnetization[i] << " " << magnetizationVariance[i] << " " << energy[i] << " "  << energyVariance[i] << "\n";
  std::cout << "Finished with " << file.fileName().toStdString() << " in " << timer.elapsed() << "ms" << std::endl;
}
コード例 #7
0
ファイル: Comparator.cpp プロジェクト: brics/brics_3d
double Comparator::calculateVariance(double *values, int sizeOfArray){

	double variance=0.0,mean;

	mean = calculateMean(values,sizeOfArray);

	for (int i =0; i<sizeOfArray; i++){
//		cout<< i<< " : "<<mean << " : "<<values[i]-mean << " : " << (values[i]-mean)*(values[i]-mean)<< "\n";
		variance += (values[i]-mean)*(values[i]-mean);
	}

	variance = variance/sizeOfArray;

	return variance;
}
コード例 #8
0
ファイル: Statistics.cpp プロジェクト: hcmlab/mobileSSI
	void Statistics::calculate(ssi_stream_t &stream_in)
	{
		ssi_real_t * in_ptr = ssi_pcast(ssi_real_t, stream_in.ptr);

		for (ssi_size_t d_i = 0; d_i < _dim; d_i++)
		{
			for (ssi_size_t num_i = 0; num_i < stream_in.num; num_i++){
				_tmp_arr[d_i][num_i] = in_ptr[d_i*stream_in.num + num_i];
			}
		}

		calculate_running_stats(stream_in.num);

		std::vector<stat_fn> stat_fns = _options.getSelection();

		for (ssi_size_t d_i = 0; d_i < _dim; d_i++)
		{
			for (ssi_size_t f_i = 0; f_i < stat_fns.size(); f_i++){

				ssi_size_t r_idx = d_i * ssi_size_t (stat_fns.size()) + f_i;
				switch (stat_fns[f_i])
				{
				case STAT_KURTOSIS:
					_res[r_idx] = calculateKurtosis(d_i);
					break;
				case STAT_SKEWNESS:
					_res[r_idx] = calculateSkewness(d_i);
					break;
				case STAT_MEAN:
					_res[r_idx] = calculateMean(d_i);
					break;
				case STAT_STDDEV:
					_res[r_idx] = calculateStandardDeviation(d_i);
					break;
				case STAT_VARIANCE:
					_res[r_idx] = calculateVariance(d_i);
					break;
				case STAT_NUMBER_VALS:
					_res[r_idx] = calulateNumberVals(d_i);
					break;
				default:
					ssi_err("stat_fn not implemented");
				}
			}
		}
	}
void Sbs2SourceReconstructionSparse::doRec(DTU::DtuArray2D<double> *Y_input, DTU::DtuArray2D<double> *S_output, int *isSourceReconstructionReady)
{
    (*isSourceReconstructionReady) = 0;
    S = S_output;

    for (int row=0; row<Y_input->dim1(); ++row)
    {
	for (int column=0; column<Y_input->dim2(); ++column)
	{
	    (*Y)[row][column] = (*Y_input)[row][column];
	}
    }

    preprocessData();
    cross_validation_k_channel(Y,S_temp);
    calculateMean(S_temp, S_output);
    (*isSourceReconstructionReady) = 1;
}
コード例 #10
0
JNIEXPORT void JNICALL
Java_com_dsp_signalstatistics_NativeStatistics_stdDev(JNIEnv *env, jclass type,
                                                             jobject guiCallback) {
    // Example showing how text is sent to the UI from native code
    float std = 0.0;
    float mean;
    int i;

    //Calculate Mean for STD DEV
    mean = calculateMean(RND);

    for(i = 0; i < LENGTH; i++)
        std += pow((RND[i] - mean),2.0);

    //Divide by N and sqrt
    std= std/(float)LENGTH;
    std= sqrt(std);

    notify(env, guiCallback,"STD: %.12g", std);
}
コード例 #11
0
double calculateStdDeviation(int *array, int length)
{
	// Calculate standard deviation of integers
	//   Formula:
	//   sqrt( 1/n * summation(( xi - u )^2), 1 to n ),
	//   where xi = integers entered and u = total arithmetic mean
	//   and n is the size of the array

	double mean = calculateMean(array, length);
	double summation = 0;
	double stdDev = 0;

	//First calculate summation(( xi - u )^2)
	for (int i = 0; i < length; i++)
	{
		summation = summation + (array[i] - mean)*(array[i] - mean);
	}

	//Calculate the standard deviation
	stdDev = summation / (double)length;
	stdDev = sqrt(stdDev);

	return stdDev;
}
コード例 #12
0
int main (void)
{
	FILE *inputStream = NULL,			/* File pointer for input file */
		 *outputStream = NULL;			/* File pointer for output file */

	int studentId1 = 0,
		studentId2 = 0,
		studentId3 = 0,
		studentId4 = 0,
		studentId5 = 0;					/* 5 student IDs */

	int studentClassStanding1 = 0,
		studentClassStanding2 = 0,
		studentClassStanding3 = 0,
		studentClassStanding4 = 0,
		studentClassStanding5 = 0;		/* 5 student class standings */

	double studentGpa1 = 0.0,
		   studentGpa2 = 0.0,
		   studentGpa3 = 0.0,
		   studentGpa4 = 0.0,
		   studentGpa5 = 0.0;			/* 5 student GPAs */

	double studentAge1 = 0.0,
		   studentAge2 = 0.0,
		   studentAge3 = 0.0,
		   studentAge4 = 0.0,
		   studentAge5 = 0.0;			/* 5 student ages */

	double sumGpa = 0.0,				/* sum of the 5 student's GPA */
		   sumClassStanding = 0.0,		/* sum of the 5 student's class standing */
		   sumAge = 0.0;				/* sum of the 5 student's ages */

	double meanGpa = 0.0,				/* mean of the 5 student's GPA */
		   meanClassStanding = 0.0,		/* mean of the 5 student's class standing */
		   meanAge = 0.0;				/* mean of the 5 student's ages */

	double deviationGpa1 = 0.0,		
		   deviationGpa2 = 0.0,
		   deviationGpa3 = 0.0,
		   deviationGpa4 = 0.0,
		   deviationGpa5 = 0.0;			/* deviation of each student's GPA */

	double varianceGpa = 0.0,			/* variance of the 5 student's GPA */
		   standardDeviationGpa = 0.0,	/* standard variance of the 5 student's GPA */
		   maxStudentGpa = 0.0,			/* maximum number out of the 5 student's GPA */
		   minStudentGpa = 0.0;			/* minimum number out of the 5 student's GPA */


	/* Opens an input file "input.dat" for reading; */
	inputStream = openFileStream (INPUT_FILE, INPUT_FILE_MODE);

    /* Opens an output file "output.dat" for writing; */
	outputStream = openFileStream (OUTPUT_FILE, OUTPUT_FILE_MODE);

	/* Checks the condition if files were successfully opened.
	 * If either file didn't open, then an error message is prompted,
	 * otherwise program will continue to execute other operations. */
	if (inputStream == NULL || outputStream == NULL)
	{
		/* Files were not successfully opened and prompts user of the error.
		 * Program will not continue to execute the rest of the program. */
		printf ("Error: Not able to open files!\n");
	}
	else
	{
		/* Reads five records from the input file (input.dat); */
	
		/* Student 1 */
		studentId1 = readInteger (inputStream);
		studentGpa1 = readDouble (inputStream);
		studentClassStanding1 = readInteger (inputStream);
		studentAge1 = readDouble (inputStream);

		/* Student 2 */
		studentId2 = readInteger (inputStream);
		studentGpa2 = readDouble (inputStream);
		studentClassStanding2 = readInteger (inputStream);
		studentAge2 = readDouble (inputStream);

		/* Student 3 */
		studentId3 = readInteger (inputStream);
		studentGpa3 = readDouble (inputStream);
		studentClassStanding3 = readInteger (inputStream);
		studentAge3 = readDouble (inputStream);

		/* Student 4 */
		studentId4 = readInteger (inputStream);
		studentGpa4 = readDouble (inputStream);
		studentClassStanding4 = readInteger (inputStream);
		studentAge4 = readDouble (inputStream);

		/* Student 5 */
		studentId5 = readInteger (inputStream);
		studentGpa5 = readDouble (inputStream);
		studentClassStanding5 = readInteger (inputStream);
		studentAge5 = readDouble (inputStream);

		/* Calculates the sum of the GPAs; */
		sumGpa = calculateSum (studentGpa1, studentGpa2, 
							   studentGpa3, studentGpa4, 
							   studentGpa5);

		/* Calculates the sum of the class standings; */
		sumClassStanding = calculateSum (studentClassStanding1, studentClassStanding2, 
										 studentClassStanding3, studentClassStanding4, 
										 studentClassStanding5);

		/* Calculates the sum of the ages; */
		sumAge = calculateSum (studentAge1, studentAge2,
								studentAge3, studentAge4,
								studentAge5);

		/* Calculates the mean of the GPAs; */
		meanGpa = calculateMean (sumGpa, NUMBER_OF_STUDENTS);

		/* Calculates the mean of the class standings; */
		meanClassStanding = calculateMean (sumClassStanding, NUMBER_OF_STUDENTS);

		/* Calculates the mean of the ages; */
		meanAge = calculateMean (sumAge, NUMBER_OF_STUDENTS);
 
		/* Calculates the deviation of each GPA from the mean */
		deviationGpa1 = calculateDeviation (studentGpa1, meanGpa);
		deviationGpa2 = calculateDeviation (studentGpa2, meanGpa);
		deviationGpa3 = calculateDeviation (studentGpa3, meanGpa);
		deviationGpa4 = calculateDeviation (studentGpa4, meanGpa);
		deviationGpa5 = calculateDeviation (studentGpa5, meanGpa);

		/* Calculates the variance of the GPAs */
		varianceGpa = calculateVariance (deviationGpa1, deviationGpa2,
										 deviationGpa3, deviationGpa4,
										 deviationGpa5, NUMBER_OF_STUDENTS);

		/* Calculates the standard deviation of the GPAs; */
		standardDeviationGpa = calculateStandardDeviation (varianceGpa);
	
		/* Determines the min of the GPAs; */
		minStudentGpa = findMin (studentGpa1, studentGpa2, 
								 studentGpa3, studentGpa4, 
								 studentGpa5);	

		/* Determines the max of the GPAs; */
		maxStudentGpa = findMax (studentGpa1, studentGpa2, 
								 studentGpa3, studentGpa4, 
								 studentGpa5);

		/* Writing the result to the output file (output.dat) */
		printDouble (outputStream, meanGpa);
		printDouble (outputStream, meanClassStanding);
		printDouble (outputStream, meanAge);
		printDouble (outputStream, standardDeviationGpa);
		printDouble (outputStream, minStudentGpa);
		printDouble (outputStream, maxStudentGpa);

		/* Closes the input and output files (i.e. input.dat and output.dat) */
		closeFileStream (inputStream);
		closeFileStream (outputStream);
	}

	return 0;
}
コード例 #13
0
ファイル: Comparator.cpp プロジェクト: brics/brics_3d
void Comparator::generateParametericPlots(vector<string> *vecMetrics, int noOfMetrics, vector<string> vecmetricNames,string nameOfFile){

	int noOfRegions;
	ofstream tempFile;
	vector<string> vecSeperatedMetrics;
	stringstream queryString;
	Gnuplot g1;
	g1.reset_all();
	g1.savetops(nameOfFile);

	vector<string> vecParametersOfComparison;
	vecParametersOfComparison.push_back("Mean");
	vecParametersOfComparison.push_back("Median");
	//vecParametersOfComparison.push_back("Variance");
	vecParametersOfComparison.push_back("Standard deviation");

	for(int i=1; i<noOfMetrics; i++){
		double mean,median,/*variance,*/stdDeviation;
		double *values;
		int yrange=1;
		//create temporary file to create the histogram data
		queryString.str("");
		queryString.clear();
		queryString<<"histData"<<i;
		tempFile.open(queryString.str().c_str());
		tempFile.precision(5);

		//for every method to be compared calculate the values
		for(unsigned int methodCount=0; methodCount<vecMethodNames.size(); methodCount++){
			noOfRegions = vecMetrics[methodCount].size();
			values = new double[noOfRegions];

			for(int j=0; j<noOfRegions;j++){
				boost::split(vecSeperatedMetrics, vecMetrics[methodCount][j], boost::is_any_of(","));
				values[j]= atof(vecSeperatedMetrics[i].c_str());
			}


			//Calculate Mean
			mean = calculateMean(values,noOfRegions);
			//Calculate Median
			median = calculateMedian(values,noOfRegions);
			//Calculate Variance
//			variance = calculateVariance(values,noOfRegions);
			//calculate Standard Deviation
			stdDeviation = calculateStdDeviation(values,noOfRegions);
			//find the yRange of the plot
			int tempRange = (int)(mean+ median+ stdDeviation);
			if(yrange < tempRange ) yrange = tempRange;
			//create histogram file
			tempFile<< vecMethodNames[methodCount] << " "<< fixed <<mean<< " " << fixed <<median<< " " << fixed << stdDeviation << endl;
		}

		tempFile.close();

		//initialise the gnuplot object


		g1.reset_plot();
		g1.set_grid();

		queryString.str("");
		queryString.clear();
		queryString << "[" << vecmetricNames[i]<<"] over all Regions";
		g1.set_title(queryString.str());

		g1.set_xlabel("Method Names");

		queryString.str("");
		queryString.clear();
		queryString << "set yrange [0:" << yrange+1 << "]";
		g1.cmd(queryString.str());

		g1.cmd("set boxwidth 0.30 absolute");
		g1.cmd("set style fill solid 1.00 border -1").cmd("set style histogram rowstacked gap 4");
		g1.cmd("set style data histograms");
		g1.set_legend("outside right top");
		g1.cmd("set xtic rotate by -45 scale 0");

	queryString.str("");
	queryString.clear();
	queryString<<"plot 'histData"<<i << "' using ";

	unsigned int parameterCount=0;
	queryString <<2 <<":xtic(1)t \"" << vecParametersOfComparison[parameterCount] <<"\"";
	for(parameterCount =1; parameterCount<= vecParametersOfComparison.size()-1; parameterCount++){
		queryString<<", '' using "<<(parameterCount+2)<< "t \"" << vecParametersOfComparison[parameterCount]<<"\"";
	}
	queryString<<endl;
	//cout<< "\n\n" <<queryString.str()<<endl;
	g1.cmd(queryString.str());
	g1.reset_plot();
	}

}
コード例 #14
0
Measures::Measures(QVector<Feature> featureCol):featureCol(featureCol),mean(0.0)
{
    this->mean = calculateMean();
}
コード例 #15
0
//-------------------------------------------------------------------------
QSharedPointer<DataBlock> FixedDataBlock::calculateStandardDeviation (std::list<QSharedPointer<DataBlock const> > const &data_blocks)
{
    return calculateStandardDeviationImpl (data_blocks, calculateMean(data_blocks));
}
コード例 #16
0
JNIEXPORT void JNICALL
Java_com_dsp_signalstatistics_NativeStatistics_mean(JNIEnv *env, jclass type,
                                                             jobject guiCallback) {
   notify(env, guiCallback,"Mean: %.12g", calculateMean(RND));
}