forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.h
More file actions
685 lines (533 loc) · 23.5 KB
/
Copy pathstatistics.h
File metadata and controls
685 lines (533 loc) · 23.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#pragma once
#include <af/defines.h>
#ifdef __cplusplus
namespace af
{
class array;
/**
C++ Interface for mean
\param[in] in is the input array
\param[in] dim the dimension along which the mean is extracted
\return the mean of the input array along dimension \p dim
\ingroup stat_func_mean
\note \p dim is -1 by default. -1 denotes the first non-singleton dimension.
*/
AFAPI array mean(const array& in, const dim_t dim=-1);
/**
C++ Interface for mean of weighted inputs
\param[in] in is the input array
\param[in] weights is used to scale input \p in before getting mean
\param[in] dim the dimension along which the mean is extracted
\return the mean of the weighted input array along dimension \p dim
\ingroup stat_func_mean
\note \p dim is -1 by default. -1 denotes the first non-singleton dimension.
*/
AFAPI array mean(const array& in, const array& weights, const dim_t dim=-1);
/**
C++ Interface for variance
\param[in] in is the input array
\param[in] isbiased is boolean denoting Population variance (false) or Sample
Variance (true)
\param[in] dim the dimension along which the variance is extracted
\return the variance of the input array along dimension \p dim
\ingroup stat_func_var
\note \p dim is -1 by default. -1 denotes the first non-singleton dimension.
\deprecated Use \ref af::var that takes \ref af_var_bias instead
*/
AF_DEPRECATED("Use \ref af::var(const array&, const af_var_bias, const dim_t)")
AFAPI array var(const array& in, const bool isbiased=false, const dim_t dim=-1);
#if AF_API_VERSION >= 38
/**
C++ Interface for variance
\param[in] in is the input array
\param[in] bias The type of bias used for variance calculation. Takes o
value of type \ref af_var_bias.
\param[in] dim the dimension along which the variance is extracted
\return the variance of the input array along dimension \p dim
\ingroup stat_func_var
\note \p dim is -1 by default. -1 denotes the first non-singleton dimension.
*/
AFAPI array var(const array &in, const af_var_bias bias, const dim_t dim = -1);
#endif
/**
C++ Interface for variance of weighted inputs
\param[in] in is the input array
\param[in] weights is used to scale input \p in before getting variance
\param[in] dim the dimension along which the variance is extracted
\return the variance of the weighted input array along dimension \p dim
\ingroup stat_func_var
\note \p dim is -1 by default. -1 denotes the first non-singleton dimension.
*/
AFAPI array var(const array& in, const array &weights, const dim_t dim=-1);
#if AF_API_VERSION >= 37
/**
C++ Interface for mean and variance
\param[out] mean The mean of the input array along \p dim dimension
\param[out] var The variance of the input array along the \p dim dimension
\param[in] in The input array
\param[in] weights The weights to scale the input array before calculating
the mean and varience. If empty, the input is not scaled
\param[in] bias The type of bias used for variance calculation
\param[in] dim The dimension along which the variance and mean are
calculated. Default is -1 meaning the first non-zero dim
*/
AFAPI void meanvar(array& mean, array& var, const array& in, const array& weights,
const af_var_bias bias = AF_VARIANCE_POPULATION, const dim_t dim=-1);
#endif
/**
C++ Interface for standard deviation
\param[in] in is the input array
\param[in] dim the dimension along which the standard deviation is extracted
\return the standard deviation of the input array along dimension \p dim
\ingroup stat_func_stdev
\note \p dim is -1 by default. -1 denotes the first non-singleton dimension.
\deprecated Use \ref af::stdev that takes \ref af_var_bias instead
*/
AF_DEPRECATED("Use af::stdev(const array&, const af_var_bias, const dim_t)")
AFAPI array stdev(const array& in, const dim_t dim=-1);
#if AF_API_VERSION >= 38
/**
C++ Interface for standard deviation
\param[in] in is the input array
\param[in] bias The type of bias used for variance calculation. Takes of
value of type \ref af_var_bias.
\param[in] dim the dimension along which the standard deviation is extracted
\return the standard deviation of the input array along dimension \p dim
\ingroup stat_func_stdev
\note \p dim is -1 by default. -1 denotes the first non-singleton dimension.
*/
AFAPI array stdev(const array &in, const af_var_bias bias,
const dim_t dim = -1);
#endif
/**
C++ Interface for covariance
\param[in] X is the first input array
\param[in] Y is the second input array
\param[in] isbiased is boolean specifying if biased estimate should be
taken (default: false)
\return the covariance of the input arrays
\ingroup stat_func_cov
\deprecated Use af::cov(const array&, const array& const af_var_bias)
*/
AF_DEPRECATED("Use af::cov(const af::array&, const array&, conv af_var_bias)")
AFAPI array cov(const array& X, const array& Y, const bool isbiased=false);
#if AF_API_VERSION >= 38
/**
C++ Interface for covariance
\param[in] X is the first input array
\param[in] Y is the second input array
\param[in] bias The type of bias used for variance calculation. Takes of
value of type \ref af_var_bias.
\return the covariance of the input arrays
\ingroup stat_func_cov
*/
AFAPI array cov(const array &X, const array &Y, const af_var_bias bias);
#endif
/**
C++ Interface for median
\param[in] in is the input array
\param[in] dim the dimension along which the median is extracted
\return the median of the input array along dimension \p dim
\ingroup stat_func_median
\note \p dim is -1 by default. -1 denotes the first non-singleton dimension.
*/
AFAPI array median(const array& in, const dim_t dim=-1);
/**
C++ Interface for mean of all elements
\param[in] in is the input array
\return mean of the entire input array
\ingroup stat_func_mean
*/
template<typename T>
AFAPI T mean(const array& in);
/**
C++ Interface for mean of all elements in weighted input
\param[in] in is the input array
\param[in] weights is used to scale input \p in before getting mean
\return mean of the entire weighted input array
\ingroup stat_func_mean
*/
template<typename T>
AFAPI T mean(const array& in, const array& weights);
/**
C++ Interface for variance of all elements
\param[in] in is the input array
\param[in] isbiased is boolean denoting Population variance (false) or Sample
Variance (true)
\return variance of the entire input array
\ingroup stat_func_var
\deprecated Use \ref af::var that takes \ref af_var_bias instead
*/
template <typename T>
AF_DEPRECATED("Use af::var(const af::array&, const af_var_bias)")
AFAPI T var(const array &in, const bool isbiased = false);
#if AF_API_VERSION >= 38
/**
C++ Interface for variance of all elements
\param[in] in is the input array
\param[in] bias The type of bias used for variance calculation. Takes of
value of type \ref af_var_bias.
\return variance of the \p in array
\ingroup stat_func_var
*/
template <typename T> AFAPI T var(const array &in, const af_var_bias bias);
#endif
/**
C++ Interface for variance of all elements in weighted input
\param[in] in is the input array
\param[in] weights is used to scale input \p in before getting variance
\return variance of the entire input array
\ingroup stat_func_var
*/
template<typename T>
AFAPI T var(const array& in, const array& weights);
/**
C++ Interface for standard deviation of all elements
\param[in] in is the input array
\return standard deviation of the entire input array
\ingroup stat_func_stdev
\deprecated Use \ref af::stdev that takes \ref af_var_bias instead
*/
template <typename T>
AF_DEPRECATED("Use af::stdev(const array&, const af_var_bias)")
AFAPI T stdev(const array &in);
#if AF_API_VERSION >= 38
/**
C++ Interface for standard deviation of all elements
\param[in] in is the input array
\param[in] bias The type of bias used for variance calculation. Takes of
value of type \ref af_var_bias.
\return standard deviation of the entire input array
\ingroup stat_func_stdev
*/
template <typename T> AFAPI T stdev(const array &in, const af_var_bias bias);
#endif
/**
C++ Interface for median of all elements
\param[in] in is the input array
\return median of the entire input array
\ingroup stat_func_median
*/
template<typename T>
AFAPI T median(const array& in);
/**
C++ Interface for correlation coefficient
\param[in] X is the first input array
\param[in] Y is the second input array
\return correlation coefficient of the input arrays
\note There are many ways correlation coefficient is calculated. This algorithm returns Pearson product-moment correlation coefficient.
\ingroup stat_func_corrcoef
*/
template<typename T>
AFAPI T corrcoef(const array& X, const array& Y);
#if AF_API_VERSION >= 36
/**
C++ Interface for finding top k elements along a given dimension
\param[out] values The values of the top k elements along the \p dim dimension
\param[out] indices The indices of the top k elements along the \p dim dimension
\param[in] in Input \ref af::array with at least \p k elements along
\p dim
\param[in] k The number of elements to be retriefed along the \p dim dimension
\param[in] dim The dimension along which top k elements are extracted.
(Must be 0)
\param[in] order If Descending the highest values are returned. Otherwise
the lowest values are returned
\note{This function is optimized for small values of k.}
\note{The order of the returned keys may not be in the same order as the
appear in the input array}
\ingroup stat_func_topk
*/
AFAPI void topk(array &values, array &indices, const array& in, const int k,
const int dim = -1, const topkFunction order = AF_TOPK_MAX);
#endif
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
C Interface for mean
\param[out] out will contain the mean of the input array along dimension \p dim
\param[in] in is the input array
\param[in] dim the dimension along which the mean is extracted
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_mean
*/
AFAPI af_err af_mean(af_array *out, const af_array in, const dim_t dim);
/**
C Interface for mean of weighted input array
\param[out] out will contain the mean of the input array along dimension \p dim
\param[in] in is the input array
\param[in] weights is used to scale input \p in before getting mean
\param[in] dim the dimension along which the mean is extracted
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_mean
*/
AFAPI af_err af_mean_weighted(af_array *out, const af_array in, const af_array weights, const dim_t dim);
/**
C Interface for variance
\param[out] out will contain the variance of the input array along dimension \p dim
\param[in] in is the input array
\param[in] isbiased is boolean denoting Population variance (false) or Sample Variance (true)
\param[in] dim the dimension along which the variance is extracted
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_var
\deprecated Use \ref af_var_v2 instead
*/
AF_DEPRECATED("Use af_var_v2")
AFAPI af_err af_var(af_array *out, const af_array in, const bool isbiased, const dim_t dim);
#if AF_API_VERSION >= 38
/**
C Interface for variance
\param[out] out will contain the variance of the input array along dimension
\p dim
\param[in] in is the input array
\param[in] bias The type of bias used for variance calculation. Takes of
value of type \ref af_var_bias
\param[in] dim the dimension along which the variance is extracted
\return \ref AF_SUCCESS if the operation is successful, otherwise an
appropriate error code is returned.
\ingroup stat_func_var
*/
AFAPI af_err af_var_v2(af_array *out, const af_array in, const af_var_bias bias,
const dim_t dim);
#endif
/**
C Interface for variance of weighted input array
\param[out] out will contain the variance of the input array along dimension \p dim
\param[in] in is the input array
\param[in] weights is used to scale input \p in before getting variance
\param[in] dim the dimension along which the variance is extracted
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_var
*/
AFAPI af_err af_var_weighted(af_array *out, const af_array in, const af_array weights, const dim_t dim);
#if AF_API_VERSION >= 37
/**
C Interface for mean and variance
\param[out] mean The mean of the input array along \p dim dimension
\param[out] var The variance of the input array along the \p dim dimension
\param[in] in The input array
\param[in] weights The weights to scale the input array before calculating
the mean and varience. If empty, the input is not scaled
\param[in] bias The type of bias used for variance calculation
\param[in] dim The dimension along which the variance and mean are
calculated. Default is -1 meaning the first non-zero dim
*/
AFAPI af_err af_meanvar(af_array *mean, af_array *var, const af_array in,
const af_array weights, const af_var_bias bias, const dim_t dim);
#endif
/**
C Interface for standard deviation
\param[out] out will contain the standard deviation of the input array along dimension \p dim
\param[in] in is the input array
\param[in] dim the dimension along which the standard deviation is extracted
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_stdev
\deprecated Use \ref af_stdev_v2 instead
*/
AF_DEPRECATED("Use af_stdev_v2")
AFAPI af_err af_stdev(af_array *out, const af_array in, const dim_t dim);
#if AF_API_VERSION >= 38
/**
C Interface for standard deviation
\param[out] out will contain the standard deviation of the input array along
dimension \p dim
\param[in] in is the input array
\param[in] bias The type of bias used for variance calculation. Takes of
value of type \ref af_var_bias
\param[in] dim the dimension along which the standard deviation is extracted
\return \ref AF_SUCCESS if the operation is successful, otherwise an
appropriate error code is returned.
\ingroup stat_func_stdev
*/
AFAPI af_err af_stdev_v2(af_array *out, const af_array in,
const af_var_bias bias, const dim_t dim);
#endif
/**
C Interface for covariance
\param[out] out will the covariance of the input arrays
\param[in] X is the first input array
\param[in] Y is the second input array
\param[in] isbiased is boolean specifying if biased estimate should be taken (default: false)
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_cov
\deprecated Use \ref af_cov_v2 instead
*/
AF_DEPRECATED("Use af_cov_v2")
AFAPI af_err af_cov(af_array* out, const af_array X, const af_array Y, const bool isbiased);
#if AF_API_VERSION >= 38
/**
C Interface for covariance
\param[out] out will the covariance of the input arrays
\param[in] X is the first input array
\param[in] Y is the second input array
\param[in] bias The type of bias used for variance calculation. Takes of
value of type \ref af_var_bias
\return \ref AF_SUCCESS if the operation is successful, otherwise an
appropriate error code is returned.
\ingroup stat_func_cov
*/
AFAPI af_err af_cov_v2(af_array *out, const af_array X, const af_array Y,
const af_var_bias bias);
#endif
/**
C Interface for median
\param[out] out will contain the median of the input array along dimension \p dim
\param[in] in is the input array
\param[in] dim the dimension along which the median is extracted
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_median
*/
AFAPI af_err af_median(af_array* out, const af_array in, const dim_t dim);
/**
C Interface for mean of all elements
\param[out] real will contain the real part of mean of the entire input array
\param[out] imag will contain the imaginary part of mean of the entire input array
\param[in] in is the input array
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_mean
*/
AFAPI af_err af_mean_all(double *real, double *imag, const af_array in);
/**
C Interface for mean of all elements in weighted input
\param[out] real will contain the real part of mean of the entire weighted input array
\param[out] imag will contain the imaginary part of mean of the entire weighted input array
\param[in] in is the input array
\param[in] weights is used to scale input \p in before getting mean
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_mean
*/
AFAPI af_err af_mean_all_weighted(double *real, double *imag, const af_array in, const af_array weights);
/**
C Interface for variance of all elements
\param[out] realVal will contain the real part of variance of the entire input array
\param[out] imagVal will contain the imaginary part of variance of the entire input array
\param[in] in is the input array
\param[in] isbiased is boolean denoting Population variance (false) or Sample Variance (true)
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_var
\deprecated Use \ref af_var_all_v2 instead
*/
AF_DEPRECATED("Use af_var_all_v2")
AFAPI af_err af_var_all(double *realVal, double *imagVal, const af_array in, const bool isbiased);
#if AF_API_VERSION >= 38
/**
C Interface for variance of all elements
\param[out] realVal will contain the real part of variance of the entire
input array
\param[out] imagVal will contain the imaginary part of variance
of the entire input array
\param[in] in is the input array
\param[in] bias The type of bias used for variance calculation. Takes of
value of type \ref af_var_bias
\return \ref AF_SUCCESS if the operation is successful, otherwise an
appropriate error code is returned.
\ingroup stat_func_var
*/
AFAPI af_err af_var_all_v2(double *realVal, double *imagVal, const af_array in,
const af_var_bias bias);
#endif
/**
C Interface for variance of all elements in weighted input
\param[out] realVal will contain the real part of variance of the entire weighted input array
\param[out] imagVal will contain the imaginary part of variance of the entire weighted input array
\param[in] in is the input array
\param[in] weights is used to scale input \p in before getting variance
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_var
*/
AFAPI af_err af_var_all_weighted(double *realVal, double *imagVal, const af_array in, const af_array weights);
/**
C Interface for standard deviation of all elements
\param[out] real will contain the real part of standard deviation of the entire input array
\param[out] imag will contain the imaginary part of standard deviation of the entire input array
\param[in] in is the input array
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_stdev
\deprecated Use \ref af_stdev_all_v2 instead
*/
AF_DEPRECATED("Use af_stdev_all_v2")
AFAPI af_err af_stdev_all(double *real, double *imag, const af_array in);
#if AF_API_VERSION >= 38
/**
C Interface for standard deviation of all elements
\param[out] real will contain the real part of standard deviation of the
entire input array
\param[out] imag will contain the imaginary part of standard deviation
of the entire input array
\param[in] in is the input array
\param[in] bias The type of bias used for variance calculation. Takes of
value of type \ref af_var_bias
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_stdev
*/
AFAPI af_err af_stdev_all_v2(double *real, double *imag, const af_array in,
const af_var_bias bias);
#endif
/**
C Interface for median
\param[out] realVal will contain the real part of median of the entire input array
\param[out] imagVal will contain the imaginary part of median of the entire input array
\param[in] in is the input array
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\ingroup stat_func_median
*/
AFAPI af_err af_median_all(double *realVal, double *imagVal, const af_array in);
/**
C Interface for correlation coefficient
\param[out] realVal will contain the real part of correlation coefficient of the inputs
\param[out] imagVal will contain the imaginary part of correlation coefficient of the inputs
\param[in] X is the first input array
\param[in] Y is the second input array
\return \ref AF_SUCCESS if the operation is successful,
otherwise an appropriate error code is returned.
\note There are many ways correlation coefficient is calculated. This algorithm returns Pearson product-moment correlation coefficient.
\ingroup stat_func_corrcoef
*/
AFAPI af_err af_corrcoef(double *realVal, double *imagVal, const af_array X, const af_array Y);
#if AF_API_VERSION >= 36
/**
C Interface for finding top k elements along a given dimension
\param[out] values The values of the top k elements along the \p dim dimension
\param[out] indices The indices of the top k elements along the \p dim dimension
\param[in] in Input \ref af::array with at least \p k elements along
\p dim
\param[in] k The number of elements to be retriefed along the \p dim dimension
\param[in] dim The dimension along which top k elements are extracted.
(Must be 0)
\param[in] order If Descending the highest values are returned. Otherwise
the lowest values are returned
\note{This function is optimized for small values of k.}
\note{The order of the returned keys may not be in the same order as the
appear in the input array}
\ingroup stat_func_topk
*/
AFAPI af_err af_topk(af_array *values, af_array *indices, const af_array in,
const int k, const int dim, const af_topk_function order);
#endif
#ifdef __cplusplus
}
#endif