21#if defined(linux) || (defined(_WIN32) && !defined(_MINGW))
24void omp_set_num_threads(
int a) {}
53 double sum = 0, sumSqr = 0, value, mean;
56 omp_set_num_threads(numThreads);
57#pragma omp parallel shared(sum)
59 double partial_sum = 0;
61 for (i = 0; i < n; i++) {
74#pragma omp parallel private(value) shared(sumSqr)
76 double partial_sumSqr = 0;
78 for (i = 0; i < n; i++) {
80 partial_sumSqr += value * value;
86 sumSqr += partial_sumSqr;
88 sumSqr = partial_sumSqr;
91 return sqrt(sumSqr / (n - 1));
109 double *meanAbsoluteDev,
double *x,
long n) {
128 double *meanAbsoluteDev,
double *x,
long n,
long numThreads) {
130 double sum = 0, sumSqr = 0, value, sum2 = 0;
131 double lMean, lRms, lStDev, lMAD;
139 if (!meanAbsoluteDev)
140 meanAbsoluteDev = &lMAD;
142 *mean = *standDev = *meanAbsoluteDev = DBL_MAX;
147 omp_set_num_threads(numThreads);
149#pragma omp parallel private(value) shared(sumSqr, sum)
151 double partial_sumSqr = 0;
152 double partial_sum = 0;
154 for (i = 0; i < n; i++) {
155 partial_sum += (value = x[i]);
156 partial_sumSqr += sqr(value);
161 if (numThreads > 1) {
163 sumSqr += partial_sumSqr;
166 sumSqr = partial_sumSqr;
171 *rms = sqrt(sumSqr / n);
174#pragma omp parallel private(value) shared(sum, sum2)
176 double partial_sum = 0;
177 double partial_sum2 = 0;
179 for (i = 0; i < n; i++) {
180 value = x[i] - *mean;
181 partial_sum2 += value * value;
182 partial_sum += fabs(value);
187 if (numThreads > 1) {
188 sum2 += partial_sum2;
197 *standDev = sqrt(sum2 / (n - 1));
198 *meanAbsoluteDev = sum / n;
219 double *meanAbsoluteDev,
double *x,
double *w,
long n) {
240 double *meanAbsoluteDev,
double *x,
double *w,
long n,
long numThreads) {
242 double sumW = 0, sum = 0, sumWx = 0, sumSqrWx = 0, sum2 = 0, value;
244 double lMean, lRms, lStDev, lMAD;
252 if (!meanAbsoluteDev)
253 meanAbsoluteDev = &lMAD;
255 *mean = *standDev = *meanAbsoluteDev = DBL_MAX;
260 omp_set_num_threads(numThreads);
262#pragma omp parallel private(value) shared(sumW, sumWx, sumSqrWx)
264 double partial_sumW = 0;
265 double partial_sumWx = 0;
266 double partial_sumSqrWx = 0;
268 for (i = 0; i < n; i++) {
269 partial_sumW += w[i];
270 partial_sumWx += (value = x[i]) * w[i];
271 partial_sumSqrWx += value * value * w[i];
276 if (numThreads > 1) {
277 sumW += partial_sumW;
278 sumWx += partial_sumWx;
279 sumSqrWx += partial_sumSqrWx;
282 sumWx = partial_sumWx;
283 sumSqrWx = partial_sumSqrWx;
289 *mean = sumWx / sumW;
290 *rms = sqrt(sumSqrWx / sumW);
291#pragma omp parallel private(value) shared(sum, sum2)
293 double partial_sum = 0;
294 double partial_sum2 = 0;
296 for (i = 0; i < n; i++) {
297 value = x[i] - *mean;
298 partial_sum += value * w[i];
299 partial_sum2 += value * value * w[i];
304 if (numThreads > 1) {
306 sum2 += partial_sum2;
315 *standDev = sqrt((sum2 * n) / (sumW * (n - 1.0)));
316 *meanAbsoluteDev = sum / sumW;
322long accumulateMoments(
double *mean,
double *rms,
double *standDev,
323 double *x,
long n,
long reset) {
324 return accumulateMomentsThreaded(mean, rms, standDev, x, n, reset, 1);
327long accumulateMomentsThreaded(
double *mean,
double *rms,
double *standDev,
328 double *x,
long n,
long reset,
long numThreads) {
330 static double sum = 0, sumSqr = 0, value;
334 nTotal = sum = sumSqr = 0;
340 omp_set_num_threads(numThreads);
341#pragma omp parallel private(value) shared(sum, sumSqr)
343 double partial_sum = 0;
344 double partial_sumSqr = 0;
346 for (i = 0; i < n; i++) {
347 partial_sum += (value = x[i]);
348 partial_sumSqr += sqr(value);
353 if (numThreads > 1) {
355 sumSqr += partial_sumSqr;
358 sumSqr = partial_sumSqr;
363 *mean = sum / nTotal;
364 *rms = sqrt(sumSqr / nTotal);
365 *standDev = sqrt((sumSqr / nTotal - sqr(*mean)) * nTotal / (nTotal - 1.0));
370long accumulateWeightedMoments(
double *mean,
double *rms,
double *standDev,
371 double *x,
double *w,
long n,
long reset) {
372 return accumulateWeightedMomentsThreaded(mean, rms, standDev, x, w, n, reset, 1);
375long accumulateWeightedMomentsThreaded(
double *mean,
double *rms,
double *standDev,
376 double *x,
double *w,
long n,
long reset,
long numThreads) {
378 static double sumW = 0, sumWx = 0, sumSqrWx = 0;
386 sumW = sumWx = sumSqrWx = nTotal = 0;
388 omp_set_num_threads(numThreads);
389#pragma omp parallel shared(sumW, sumWx, sumSqrWx)
391 double partial_sumW = 0;
392 double partial_sumWx = 0;
393 double partial_sumSqrWx = 0;
395 for (i = 0; i < n; i++) {
396 partial_sumW += w[i];
397 partial_sumWx += w[i] * x[i];
398 partial_sumSqrWx += x[i] * x[i] * w[i];
403 if (numThreads > 1) {
404 sumW += partial_sumW;
405 sumWx += partial_sumWx;
406 sumSqrWx += partial_sumSqrWx;
409 sumWx = partial_sumWx;
410 sumSqrWx = partial_sumSqrWx;
415 *mean = sumWx / sumW;
416 *rms = sqrt(sumSqrWx / sumW);
417 *standDev = sqrt((sumSqrWx / sumW - sqr(*mean)) * (nTotal / (nTotal - 1.0)));
458 double xAve = 0, yAve = 0, dx, dy;
460 *C11 = *C12 = *C22 = 0;
464 omp_set_num_threads(numThreads);
465#pragma omp parallel shared(xAve, yAve)
467 double partial_xAve = 0;
468 double partial_yAve = 0;
470 for (i = 0; i < n; i++) {
471 partial_xAve += x[i];
472 partial_yAve += y[i];
477 if (numThreads > 1) {
478 xAve += partial_xAve;
479 yAve += partial_yAve;
489#pragma omp parallel private(dx, dy) shared(C11, C12, C22)
491 double partial_C11 = 0;
492 double partial_C12 = 0;
493 double partial_C22 = 0;
495 for (i = 0; i < n; i++) {
498 partial_C11 += dx * dx;
499 partial_C12 += dx * dy;
500 partial_C22 += dy * dy;
505 if (numThreads > 1) {
553 omp_set_num_threads(numThreads);
554#pragma omp parallel shared(sum)
556 double partial_sum = 0;
558 for (i = 0; i < n; i++) {
603 omp_set_num_threads(numThreads);
604#pragma omp parallel shared(sum)
606 double partial_sum = 0;
608 for (i = 0; i < n; i++) {
609 partial_sum += y[i] * y[i];
620 return (sqrt(sum / n));
649 double ave = 0, sum = 0;
653 omp_set_num_threads(numThreads);
654#pragma omp parallel shared(ave)
656 double partial_ave = 0;
658 for (i = 0; i < n; i++) {
671#pragma omp parallel shared(sum)
673 double partial_sum = 0;
675 for (i = 0; i < n; i++) {
676 partial_sum += fabs(y[i] - ave);
717 double ySum = 0, wSum = 0;
721 omp_set_num_threads(numThreads);
722#pragma omp parallel shared(wSum, ySum)
724 double partial_wSum = 0;
725 double partial_ySum = 0;
727 for (i = 0; i < n; i++) {
728 partial_wSum += w[i];
729 partial_ySum += y[i] * w[i];
734 if (numThreads > 1) {
735 wSum += partial_wSum;
736 ySum += partial_ySum;
776 double sum = 0, wSum = 0;
780 omp_set_num_threads(numThreads);
781#pragma omp parallel shared(sum, wSum)
783 double partial_sum = 0;
784 double partial_wSum = 0;
786 for (i = 0; i < n; i++) {
787 partial_sum += y[i] * y[i] * w[i];
788 partial_wSum += w[i];
793 if (numThreads > 1) {
795 wSum += partial_wSum;
803 return sqrt(sum / wSum);
835 double mean, sum = 0, wSum = 0;
839 omp_set_num_threads(numThreads);
840#pragma omp parallel shared(sum, wSum)
842 double partial_sum = 0;
843 double partial_wSum = 0;
845 for (i = 0; i < n; i++) {
846 partial_sum += y[i] * w[i];
847 partial_wSum += w[i];
852 if (numThreads > 1) {
854 wSum += partial_wSum;
865#pragma omp parallel shared(sum)
867 double partial_sum = 0;
869 for (i = 0; i < n; i++) {
870 partial_sum += fabs(y[i] - mean) * w[i];
912 double mean, sum = 0, wSum = 0, value;
916 omp_set_num_threads(numThreads);
917#pragma omp parallel shared(sum, wSum)
919 double partial_sum = 0;
920 double partial_wSum = 0;
922 for (i = 0; i < n; i++) {
923 partial_sum += y[i] * w[i];
924 partial_wSum += w[i];
929 if (numThreads > 1) {
931 wSum += partial_wSum;
942#pragma omp parallel private(value) shared(sum)
944 double partial_sum = 0;
946 for (i = 0; i < n; i++) {
948 partial_sum += value * value * w[i];
959 return sqrt((sum * n) / (wSum * (n - 1.0)));
double arithmeticAverage(double *y, long n)
Calculates the arithmetic average of an array of doubles.
double weightedStDevThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted standard deviation of an array of doubles using multiple threads.
double standardDeviationThreaded(double *x, long n, long numThreads)
Calculates the standard deviation of an array of doubles using multiple threads.
long computeWeightedMoments(double *mean, double *rms, double *standDev, double *meanAbsoluteDev, double *x, double *w, long n)
Computes weighted statistical moments of an array.
long computeWeightedMomentsThreaded(double *mean, double *rms, double *standDev, double *meanAbsoluteDev, double *x, double *w, long n, long numThreads)
Computes weighted statistical moments of an array using multiple threads.
double weightedStDev(double *y, double *w, long n)
Calculates the weighted standard deviation of an array of doubles.
double rmsValueThreaded(double *y, long n, long numThreads)
Calculates the RMS (Root Mean Square) value of an array of doubles using multiple threads.
long computeMoments(double *mean, double *rms, double *standDev, double *meanAbsoluteDev, double *x, long n)
Computes the mean, RMS, standard deviation, and mean absolute deviation of an array.
double arithmeticAverageThreaded(double *y, long n, long numThreads)
Calculates the arithmetic average of an array of doubles using multiple threads.
double weightedRMSThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted RMS (Root Mean Square) value of an array of doubles using multiple threads.
long computeCorrelationsThreaded(double *C11, double *C12, double *C22, double *x, double *y, long n, long numThreads)
Computes the correlations between two datasets using multiple threads.
double meanAbsoluteDeviationThreaded(double *y, long n, long numThreads)
Calculates the mean absolute deviation of an array of doubles using multiple threads.
long computeCorrelations(double *C11, double *C12, double *C22, double *x, double *y, long n)
Computes the correlations between two datasets.
long computeMomentsThreaded(double *mean, double *rms, double *standDev, double *meanAbsoluteDev, double *x, long n, long numThreads)
Computes the mean, RMS, standard deviation, and mean absolute deviation of an array using multiple th...
double weightedMADThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted mean absolute deviation of an array of doubles using multiple threads.
double meanAbsoluteDeviation(double *y, long n)
Calculates the mean absolute deviation of an array of doubles.
double weightedMAD(double *y, double *w, long n)
Calculates the weighted mean absolute deviation of an array of doubles.
double weightedRMS(double *y, double *w, long n)
Calculates the weighted RMS (Root Mean Square) value of an array of doubles.
double rmsValue(double *y, long n)
Calculates the RMS (Root Mean Square) value of an array of doubles.
double weightedAverageThreaded(double *y, double *w, long n, long numThreads)
Calculates the weighted average of an array of doubles using multiple threads.
double weightedAverage(double *y, double *w, long n)
Calculates the weighted average of an array of doubles.
double standardDeviation(double *x, long n)
Calculates the standard deviation of an array of doubles.