/** * \brief Calculates the pooled variance of two vectors of numbers. * \param[in] values1 The first vector of numbers. * \param[in] values2 The second vector of numbers * \return The pooled sample variance. */ double StatisticalTesting::pooledVariance(const std::vector<double>& values1, const std::vector<double>& values2) { double pv = 0.0; // TODO double s1 = standardDeviation(values1); double s2 = standardDeviation(values2); int n1 = values1.size(); int n2 = values2.size(); /* int Mean =mean(values1); std::vector<double>::const_iterator it; for (it=values1.begin();it!=values1.end();it++) { s1 += pow(Mean-(*it),2); } s1 /= n1; Mean =mean(values2); for (it=values2.begin();it!=values2.end();it++) { s2 += pow(Mean-(*it),2); } s2 /= n2; */ //pv =(double) (((n1-1) * s1*s1 )+((n2-1) * s2*s2 ))/(n1+n2-2); pv = (double)(n1*s1*s1+n2*s2*s2)/(n1+n2-2); return pv; }
int main() { int size, rank; double startTime, endTime; double *arrayA = (double *) malloc(sizeof(double) * 1000000); double *arrayB = (double *) malloc(sizeof(double) * 1000000); double pearsonCCoefficient = 0.0; long n = 1000000; double standardDeviationA, standardDeviationB; double meanA, meanB; // call to initializer function for initializing arrays with sin(i) and sin(i+1) values, // and calculating mean for both the arrays initializer(arrayA, arrayB, n, &meanA, &meanB); // call to Standard Deviation function,with arrays and mean calculated previously standardDeviation(arrayA, arrayB, &standardDeviationA, &standardDeviationB, meanA, meanB, n); startTime = omp_get_wtime(); // call to Pearson Correlation Coefficient with mean ,array and //standard Deviation calculated previously pearsonCoefficient(meanA, meanB, arrayA, arrayB, &pearsonCCoefficient, standardDeviationA, standardDeviationB, n); ; printf("Pearson Coefficient:%f\n", pearsonCCoefficient); endTime = omp_get_wtime(); printf("Total Execution Time : \n %f Sec \n %f ms", endTime - startTime, (endTime - startTime) * 1000); printf("\n"); return 0; }
int main() { int size, rank; MPI_Init(NULL, NULL); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); double startTime, endTime; startTime = MPI_Wtime(); double *arrayA = (double *) malloc(sizeof(double) * 1000000); double *arrayB = (double *) malloc(sizeof(double) * 1000000); double pearsonCCoefficient = 0.0; long n = 1000000; double standardDeviationA, standardDeviationB; double meanA, meanB; initializer(arrayA, arrayB, n, &meanA, &meanB); standardDeviation(arrayA, arrayB, &standardDeviationA, &standardDeviationB, meanA, meanB, n); pearsonCoefficient(meanA, meanB, arrayA, arrayB, &pearsonCCoefficient, standardDeviationA, standardDeviationB, n); printf("Pearson Coefficient:%f\n", pearsonCCoefficient); endTime = MPI_Wtime(); printf("Total Elapsed Time for Serial Version : %f \n", endTime - startTime); // system("pause"); }
/** * \brief Calculates the t value of a vector of numbers. * \param[in] values The vector of numbers. * \param[in] distributionMean The mean of the entire population. * \return The t value. */ double StatisticalTesting::tValue(const std::vector<double>& values, const double& distributionMean) { double t = 0.0; // TODO Calculate the t value. Estimate the standard deviation from the sample. double samplesigma =standardDeviation(values) ; double Mean = mean(values); t= (Mean - distributionMean)/(samplesigma /sqrt(values.size())); return t; }
std::vector<double> repeatFunction(F function) { std::vector<clock_t> numCalls(9); std::vector<double> info; std::generate(numCalls.begin(), numCalls.end(), [&](){ timer(function); }); info.push_back(std::mean(numCalls)); info.push_back(standardDeviation(numCalls)); return info; }
double pearsonCorrelationCoefficient(double *a, double *b) { double meanA = mean(a); double meanB = mean(b); double standardDeviationA = standardDeviation(a,&meanA); double standardDeviationB = standardDeviation(b,&meanB); // TOP of fraction double value = 0.0; for(size_t i =0; i < vec_size; i++) { value += ((a[i] - meanA) * (b[i] - meanB)); } value *= 1.0/vec_size; // BOTTOM of fraction value /= (standardDeviationA*standardDeviationB); return value; }
double estPi(double precision, int numTrials){ double numNeedles = NUM_NEEDLES; double sDev=precision; double result; while(sDev>=precision/2.0){ result = getEst(numNeedles, numTrials); sDev = standardDeviation(estimates, mean(estimates, numTrials), numTrials); numNeedles*=2; } return result; }
//频域 峰度 double kurt(double data[],int length){ if(data == NULL || length == 0) return 0.0; double meanD = mean(data,length); double dev = standardDeviation(data,length); double sum=0; int i; for(i=0;i<length;i++){ sum+=pow((data[i]-meanD)/dev,4)-3; } return sum/length; }
Real GeneralStatistics::skewness() const { Size N = samples(); QL_REQUIRE(N > 2, "sample number <=2, unsufficient"); Real x = expectationValue(compose(cube<Real>(), subtract<Real>(mean())), everywhere()).first; Real sigma = standardDeviation(); return (x/(sigma*sigma*sigma))*(N/(N-1.0))*(N/(N-2.0)); }
void colorization(float *LABs, float *LABt, float *LABd, int colst, int rowst, int colss, int rowss) { float meanss[3]; float deviationss[3]; float meanst[3]; float deviationst[3]; // Calcul des moyennes et écarts-types des images source et target mean(LABs, meanss, colss, rowss); mean(LABt, meanst, colst, rowst); standardDeviation(LABs, deviationss, colss, rowss); standardDeviation(LABt, deviationst, colst, rowst); // Luminance remapping de l'image source luminanceRemapping(LABs, LABt, colss, rowss, colst, rowst); int n = getJitteredSamplingN(colss, rowss); printf("%d\n", n); // Colorisation float tmp = 0.0; for (int i = 0; i < rowst; ++i) { for (int j = 0; j < colst; ++j) { for (int k = 0; k < 3; ++k) { LABs++; LABt++; LABd++; } } } LABs -= colss * rowss * 3; LABt -= colst * rowst * 3; LABd -= colst * rowst * 3; }
int main() { int N = _1000; char ** content = readFromFile(N); initHashTable(N); int i = 0; while (i < N) { insertElement(content[i]); i++; } computeDistributionsPerBucket(); printf("Standard deviation: %.3f\n", standardDeviation()); return 0; }
void luminanceRemapping(float *imgA, float *imgB, int colsA, int rowsA, int colsB, int rowsB) { float meansA[3]; float deviationsA[3]; float meansB[3]; float deviationsB[3]; mean(imgA, meansA, colsA, rowsA); mean(imgB, meansB, colsB, rowsB); standardDeviation(imgA, deviationsA, colsA, rowsA); standardDeviation(imgB, deviationsB, colsB, rowsB); for (int i = 0; i < rowsA; ++i) { for (int j = 0; j < colsA; ++j) { *imgA = (deviationsB[0]/deviationsA[0]) * (*imgA - meansA[0]) + meansB[0]; imgA += 3; } } imgA -= colsA * rowsA; }
Real IncrementalStatistics::skewness() const { QL_REQUIRE(sampleNumber_>2, "sample number <=2, unsufficient"); Real s = standardDeviation(); if (s==0.0) return 0.0; Real m = mean(); Real result = cubicSum_/sampleWeight_; result -= 3.0*m*(quadraticSum_/sampleWeight_); result += 2.0*m*m*m; result /= s*s*s; result *= sampleNumber_/(sampleNumber_-1.0); result *= sampleNumber_/(sampleNumber_-2.0); return result; }
/* Thresholding the Y channel of the image on the basis of the sigma obtained After this we are doing window based thresholding */ cv::Mat shadowDetection(cv::Mat &image){ int sigma = standardDeviation(image); // First threshold on the basis of sigma cv::Mat binary(image.rows,image.cols,CV_8UC1,cvScalarAll(0)); for (int i=0;i<image.rows;i++){ for (int j=0;j<image.cols;j++){ if (image.at<cv::Vec3b>(i,j)[0] > 1.5*sigma){ binary.at<uchar>(i,j) = 255; } else binary.at<uchar>(i,j) = 0; } } // Window based thresholding /*int mean = 0, count = 0; cv::Mat binary_final(image.rows,image.cols,CV_8UC1,cvScalarAll(0)); for (int i=1;i<image.rows-1;i++){ for (int j=1;j<image.cols-1;j++){ mean = sigma =0; if (binary.at<uchar>(i,j) == 255){ for (int k = i-1;k<=i+1;k++){ for (int l= j-1;l<=j+1;l++){ mean += image.at<cv::Vec3b>(k,l)[0]; } } mean /=9; for (int k = i-1;k<=i+1;k++){ for (int l= j-1;l<=j+1;l++){ sigma += (mean - image.at<cv::Vec3b>(k,l)[0])*(mean - image.at<cv::Vec3b>(k,l)[0]); } } sigma /= 9; sigma = sqrt((float)sigma); if (image.at<cv::Vec3b>(i,j)[0] > 1*sigma) binary_final.at<uchar>(i,j)=255; else binary_final.at<uchar>(i,j)=0; } else binary_final.at<uchar>(i,j) = 0; } }*/ return binary; }
void ViStatistician::process() { QObject::disconnect(mCurrentObject.data(), SIGNAL(decoded()), this, SLOT(process())); ViAudioReadData data(mCurrentObject->buffer(ViAudio::Target)); data.setSampleCount(mWindowSize); qreal value = 0; qint64 count = 0; qreal top = 0, bottom1 = 0, bottom2 = 0; qreal valuePos = 0, valueNeg = 0; int countPos = 0, countNeg = 0; while(data.hasData()) { data.read(); ViSampleChunk &samples1 = data.splitSamples(0); ViSampleChunk &samples2 = data.splitSamples(1); if(mMode == Mean) { value += mean(samples1); value += mean(samples2); count += 2; } else if(mMode == StandardDeviation) { value += standardDeviation(samples1); value +standardDeviation(samples2); count += 2; } else if(mMode == Pearson) { qreal theTopA = 0, theBottom1A = 0, theBottom2A = 0; qreal theTopB = 0, theBottom1B = 0, theBottom2B = 0; qreal value1 = pearson(samples1, theTopA, theBottom1A, theBottom2A); qreal value2 = pearson(samples2, theTopB, theBottom1B, theBottom2B); /*if(value1 != 0) { top += theTopA; bottom1 += theBottom1A; bottom2 += theBottom2A; } if(value2 != 0) { top += theTopB; bottom1 += theBottom1B; bottom2 += theBottom2B; }*/ if(value1 > 0) { valuePos += value1; ++countPos; } else if(value1 < 0) { valueNeg += value1; ++countNeg; } if(value2 > 0) { valuePos += value2; ++countPos; } else if(value2 < 0) { valueNeg += value2; ++countNeg; } } } if(mMode == Pearson) { /*value = top / (qSqrt(bottom1) * qSqrt(bottom2)); mValue += value; mCount += 1; printFileData(value); printTerminal(value);*/ mValuePos += valuePos; mCountPos += countPos; mValueNeg += valueNeg; mCountNeg += countNeg; valuePos /= countPos; valueNeg /= countNeg; printFileDataPearson(valuePos, valueNeg); printTerminalPearson(valuePos, valueNeg); } else { mValue += value; mCount += count; value /= count; printFileData(value); printTerminal(value); } nextFile(); }
//频域 标准备差 double fdev(double data[],int length){ return standardDeviation(data,length); }
int testStandardDeviation() { acc vals[] = { 3, 4, 7, 10, TERMINATION_VALUE }; printf("StdDev: %.3f", standardDeviation(vals, -1)); }
void printBenchmark(SortBenchmark b) { printf("%s sort: %.6lf s (± %.6lf)\n", b.algorithm, averageSortTime(b), standardDeviation(b)); }
int main(int argc, char **argv) { int size, rank; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD, &rank); long localArraySize = 1000000 / size; double *arrayA = (double *) malloc(sizeof(double) * localArraySize); double *arrayB = (double *) malloc(sizeof(double) * localArraySize); double *combinedA; double *combinedB; double pearsonCCoefficient = 0.0; double pearsonCC = 0.0; double sdA, sdB; double standardDeviationA, standardDeviationB; double localMeanA, localMeanB; double MeanA, MeanB; double localStart, localEnd, localElapsed, Elapsed; localStart = MPI_Wtime(); int test = 0; int status = -1; localMeanA = 0; localMeanB = 0; initializer(arrayA, arrayB, localArraySize, &localMeanA, &localMeanB, rank, size); // For initializing A values and Y values with random values and calculation mean if (rank == 0) { combinedA = malloc(localArraySize * size * (sizeof(double))); combinedB = malloc(localArraySize * size * (sizeof(double))); } //MPI_Barrier(MPI_COMM_WORLD); // Combining the distributed arrays to single array. // MPI GATHER statement MPI_Gather(arrayA, localArraySize, MPI_DOUBLE, combinedA, localArraySize, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Gather(arrayB, localArraySize, MPI_DOUBLE, combinedB, localArraySize, MPI_DOUBLE, 0, MPI_COMM_WORLD); // Calculation of overall mean MPI_Reduce(&localMeanA, &MeanA, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Reduce(&localMeanB, &MeanB, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); // Assigning global mean to process local mean for standard deviation MPI_Bcast(&MeanA, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Bcast(&MeanB, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); // Calculation of Standard deviation on every chunk standardDeviation(arrayA, arrayB, &sdA, &sdB, MeanA, MeanB, localArraySize, size); // Combining local standard deviation to overall standard deviation MPI_Reduce(&sdA, &standardDeviationA, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Reduce(&sdB, &standardDeviationB, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); if (rank == 0) { standardDeviationA = sqrt(standardDeviationA); standardDeviationB = sqrt(standardDeviationB); } // Assigning overall standard deviation to process local standard deviation MPI_Bcast(&standardDeviationA, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); MPI_Bcast(&standardDeviationB, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); // Calculation of Pearson Correlation Coefficient pearsonCoefficient(MeanA, MeanB, arrayA, arrayB, &pearsonCC, standardDeviationA, standardDeviationB, localArraySize, size); // Calculation of total Pearson Correlation Coefficient MPI_Reduce(&pearsonCC, &pearsonCCoefficient, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); localEnd = MPI_Wtime(); localElapsed = localEnd - localStart; printf("\n Elapsed time for process %d is %f", rank, localElapsed); MPI_Reduce(&localElapsed, &Elapsed, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); if (rank == 0) { int j = 0; printf("\n pearson coefficient total %f", pearsonCCoefficient); printf("\n Total Elapsed Time %f", Elapsed); printf("\n"); } MPI_Finalize(); return 0; }