forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.txt
More file actions
64 lines (53 loc) · 2.45 KB
/
Copy pathrepl.txt
File metadata and controls
64 lines (53 loc) · 2.45 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
{{alias}}( arrays )
Computes the covariance of two one-dimensional single-precision
floating-point ndarrays provided known means and using a one-pass textbook
algorithm.
If provided an empty ndarray, the function returns `NaN`.
Parameters
----------
arrays: ArrayLikeObject<ndarray>
The function expects the following ndarrays in order:
- first one-dimensional input ndarray.
- second one-dimensional input ndarray.
- a zero-dimensional ndarray specifying mean of the first
one-dimensional ndarray.
- a zero-dimensional ndarray specifying mean of the second
one-dimensional ndarray.
- a zero-dimensional ndarray specifying degrees of freedom
adjustment. Setting this parameter to a value other than `0` has the
effect of adjusting the divisor during the calculation of the
covariance according to `N-c` where `c` corresponds to the provided
degrees of freedom adjustment. When computing the population
covariance, setting this parameter to `0` is the standard choice (i.e.,
the provided arrays contain data constituting entire populations). When
computing the unbiased sample covariance, setting this parameter to `1`
is the standard choice (i.e., the provided arrays contain data sampled
from larger populations; this is commonly referred to as Bessel's
correction).
Returns
-------
out: number
The covariance.
Examples
--------
// Create the input ndarrays:
> var xbuf = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 2.0 ] );
> var ybuf = new {{alias:@stdlib/array/float32}}( [ 2.0, -2.0, 1.0 ] );
> var dt = 'float32';
> var sh = [ xbuf.length ];
> var st = [ 1 ];
> var oo = 0;
> var ord = 'row-major';
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord );
> var y = new {{alias:@stdlib/ndarray/ctor}}( dt, ybuf, sh, st, oo, ord );
// Specify the known means:
> var opts = { 'dtype': dt };
> var meanx = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0/3.0, opts );
> var meany = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0/3.0, opts );
// Specify the degrees of freedom adjustment:
> var correction = new {{alias:@stdlib/ndarray/from-scalar}}( 1.0, opts );
// Calculate the sample covariance:
> {{alias}}( [ x, y, meanx, meany, correction ] )
~3.8333
See Also
--------