@stdlib/stats-base-snanvariancepn 0.0.7 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CITATION.cff +30 -0
- package/NOTICE +1 -1
- package/README.md +26 -15
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +7 -0
- package/docs/types/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/package.json +17 -16
- package/docs/repl.txt +0 -121
- package/docs/types/test.ts +0 -187
package/CITATION.cff
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
title: stdlib
|
|
3
|
+
message: >-
|
|
4
|
+
If you use this software, please cite it using the
|
|
5
|
+
metadata from this file.
|
|
6
|
+
|
|
7
|
+
type: software
|
|
8
|
+
|
|
9
|
+
authors:
|
|
10
|
+
- name: The Stdlib Authors
|
|
11
|
+
url: https://github.com/stdlib-js/stdlib/graphs/contributors
|
|
12
|
+
|
|
13
|
+
repository-code: https://github.com/stdlib-js/stdlib
|
|
14
|
+
url: https://stdlib.io
|
|
15
|
+
|
|
16
|
+
abstract: |
|
|
17
|
+
Standard library for JavaScript and Node.js.
|
|
18
|
+
|
|
19
|
+
keywords:
|
|
20
|
+
- JavaScript
|
|
21
|
+
- Node.js
|
|
22
|
+
- TypeScript
|
|
23
|
+
- standard library
|
|
24
|
+
- scientific computing
|
|
25
|
+
- numerical computing
|
|
26
|
+
- statistical computing
|
|
27
|
+
|
|
28
|
+
license: Apache-2.0 AND BSL-1.0
|
|
29
|
+
|
|
30
|
+
date-released: 2016
|
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2023 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -18,6 +18,17 @@ limitations under the License.
|
|
|
18
18
|
|
|
19
19
|
-->
|
|
20
20
|
|
|
21
|
+
|
|
22
|
+
<details>
|
|
23
|
+
<summary>
|
|
24
|
+
About stdlib...
|
|
25
|
+
</summary>
|
|
26
|
+
<p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
|
|
27
|
+
<p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
|
|
28
|
+
<p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
|
|
29
|
+
<p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
|
|
30
|
+
</details>
|
|
31
|
+
|
|
21
32
|
# snanvariancepn
|
|
22
33
|
|
|
23
34
|
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
@@ -33,7 +44,7 @@ The population [variance][variance] of a finite size population of size `N` is g
|
|
|
33
44
|
<div class="equation" align="center" data-raw-text="\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2" data-equation="eq:population_variance">
|
|
34
45
|
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@d78f524f2ccddb696670f1a30bb4a39b5b6e8e19/lib/node_modules/@stdlib/stats/base/snanvariancepn/docs/img/equation_population_variance.svg" alt="Equation for the population variance.">
|
|
35
46
|
<br>
|
|
36
|
-
</div>
|
|
47
|
+
</div> -->
|
|
37
48
|
|
|
38
49
|
<!-- </equation> -->
|
|
39
50
|
|
|
@@ -41,10 +52,10 @@ where the population mean is given by
|
|
|
41
52
|
|
|
42
53
|
<!-- <equation class="equation" label="eq:population_mean" align="center" raw="\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i" alt="Equation for the population mean."> -->
|
|
43
54
|
|
|
44
|
-
<div class="equation" align="center" data-raw-text="\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i" data-equation="eq:population_mean">
|
|
55
|
+
<!-- <div class="equation" align="center" data-raw-text="\mu = \frac{1}{N} \sum_{i=0}^{N-1} x_i" data-equation="eq:population_mean">
|
|
45
56
|
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@d78f524f2ccddb696670f1a30bb4a39b5b6e8e19/lib/node_modules/@stdlib/stats/base/snanvariancepn/docs/img/equation_population_mean.svg" alt="Equation for the population mean.">
|
|
46
57
|
<br>
|
|
47
|
-
</div>
|
|
58
|
+
</div> -->
|
|
48
59
|
|
|
49
60
|
<!-- </equation> -->
|
|
50
61
|
|
|
@@ -52,10 +63,10 @@ Often in the analysis of data, the true population [variance][variance] is not k
|
|
|
52
63
|
|
|
53
64
|
<!-- <equation class="equation" label="eq:unbiased_sample_variance" align="center" raw="s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2" alt="Equation for computing an unbiased sample variance."> -->
|
|
54
65
|
|
|
55
|
-
<div class="equation" align="center" data-raw-text="s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2" data-equation="eq:unbiased_sample_variance">
|
|
66
|
+
<!-- <div class="equation" align="center" data-raw-text="s^2 = \frac{1}{n-1} \sum_{i=0}^{n-1} (x_i - \bar{x})^2" data-equation="eq:unbiased_sample_variance">
|
|
56
67
|
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@d78f524f2ccddb696670f1a30bb4a39b5b6e8e19/lib/node_modules/@stdlib/stats/base/snanvariancepn/docs/img/equation_unbiased_sample_variance.svg" alt="Equation for computing an unbiased sample variance.">
|
|
57
68
|
<br>
|
|
58
|
-
</div>
|
|
69
|
+
</div> -->
|
|
59
70
|
|
|
60
71
|
<!-- </equation> -->
|
|
61
72
|
|
|
@@ -63,7 +74,7 @@ where the sample mean is given by
|
|
|
63
74
|
|
|
64
75
|
<!-- <equation class="equation" label="eq:sample_mean" align="center" raw="\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i" alt="Equation for the sample mean."> -->
|
|
65
76
|
|
|
66
|
-
<div class="equation" align="center" data-raw-text="\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i" data-equation="eq:sample_mean">
|
|
77
|
+
<!-- <div class="equation" align="center" data-raw-text="\bar{x} = \frac{1}{n} \sum_{i=0}^{n-1} x_i" data-equation="eq:sample_mean">
|
|
67
78
|
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@d78f524f2ccddb696670f1a30bb4a39b5b6e8e19/lib/node_modules/@stdlib/stats/base/snanvariancepn/docs/img/equation_sample_mean.svg" alt="Equation for the sample mean.">
|
|
68
79
|
<br>
|
|
69
80
|
</div>
|
|
@@ -239,11 +250,11 @@ console.log( v );
|
|
|
239
250
|
|
|
240
251
|
## See Also
|
|
241
252
|
|
|
242
|
-
- <span class="package-name">[`@stdlib/stats
|
|
243
|
-
- <span class="package-name">[`@stdlib/stats
|
|
244
|
-
- <span class="package-name">[`@stdlib/stats
|
|
245
|
-
- <span class="package-name">[`@stdlib/stats
|
|
246
|
-
- <span class="package-name">[`@stdlib/stats
|
|
253
|
+
- <span class="package-name">[`@stdlib/stats-base/dnanvariancepn`][@stdlib/stats/base/dnanvariancepn]</span><span class="delimiter">: </span><span class="description">calculate the variance of a double-precision floating-point strided array ignoring NaN values and using a two-pass algorithm.</span>
|
|
254
|
+
- <span class="package-name">[`@stdlib/stats-base/nanvariancepn`][@stdlib/stats/base/nanvariancepn]</span><span class="delimiter">: </span><span class="description">calculate the variance of a strided array ignoring NaN values and using a two-pass algorithm.</span>
|
|
255
|
+
- <span class="package-name">[`@stdlib/stats-base/snanstdevpn`][@stdlib/stats/base/snanstdevpn]</span><span class="delimiter">: </span><span class="description">calculate the standard deviation of a single-precision floating-point strided array ignoring NaN values and using a two-pass algorithm.</span>
|
|
256
|
+
- <span class="package-name">[`@stdlib/stats-base/snanvariance`][@stdlib/stats/base/snanvariance]</span><span class="delimiter">: </span><span class="description">calculate the variance of a single-precision floating-point strided array ignoring NaN values.</span>
|
|
257
|
+
- <span class="package-name">[`@stdlib/stats-base/svariancepn`][@stdlib/stats/base/svariancepn]</span><span class="delimiter">: </span><span class="description">calculate the variance of a single-precision floating-point strided array using a two-pass algorithm.</span>
|
|
247
258
|
|
|
248
259
|
</section>
|
|
249
260
|
|
|
@@ -275,7 +286,7 @@ See [LICENSE][stdlib-license].
|
|
|
275
286
|
|
|
276
287
|
## Copyright
|
|
277
288
|
|
|
278
|
-
Copyright © 2016-
|
|
289
|
+
Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
|
|
279
290
|
|
|
280
291
|
</section>
|
|
281
292
|
|
|
@@ -288,8 +299,8 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
|
288
299
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-snanvariancepn.svg
|
|
289
300
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-snanvariancepn
|
|
290
301
|
|
|
291
|
-
[test-image]: https://github.com/stdlib-js/stats-base-snanvariancepn/actions/workflows/test.yml/badge.svg?branch=v0.0
|
|
292
|
-
[test-url]: https://github.com/stdlib-js/stats-base-snanvariancepn/actions/workflows/test.yml?query=branch:v0.0
|
|
302
|
+
[test-image]: https://github.com/stdlib-js/stats-base-snanvariancepn/actions/workflows/test.yml/badge.svg?branch=v0.1.0
|
|
303
|
+
[test-url]: https://github.com/stdlib-js/stats-base-snanvariancepn/actions/workflows/test.yml?query=branch:v0.1.0
|
|
293
304
|
|
|
294
305
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-snanvariancepn/main.svg
|
|
295
306
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-snanvariancepn?branch=main
|
|
@@ -302,7 +313,7 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors].
|
|
|
302
313
|
-->
|
|
303
314
|
|
|
304
315
|
[chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
|
|
305
|
-
[chat-url]: https://gitter.im
|
|
316
|
+
[chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
|
|
306
317
|
|
|
307
318
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
308
319
|
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";var C=function(v,e){return function(){return e||v((e={exports:{}}).exports,e),e.exports}};var K=C(function($,A){
|
|
2
|
+
var u=require('@stdlib/number-float64-base-to-float32/dist'),g=require('@stdlib/math-base-special-floor/dist'),h=128;function F(v,e,i,n,R){var a,t,c,o,p,q,s,l,E,T,O,f,r,y;if(a=R,v<8){for(O=0,f=0,y=0;y<v;y++)r=i[a],r===r&&(O=u(O+r),f+=1),a+=n;return e[0]=u(e[0]+O),e[1]+=f,e}if(v<=h){for(t=0,c=0,o=0,p=0,q=0,s=0,l=0,E=0,f=0,T=v%8,y=0;y<v-T;y+=8)r=i[a],r===r&&(t=u(t+r),f+=1),a+=n,r=i[a],r===r&&(c=u(c+r),f+=1),a+=n,r=i[a],r===r&&(o=u(o+r),f+=1),a+=n,r=i[a],r===r&&(p=u(p+r),f+=1),a+=n,r=i[a],r===r&&(q=u(q+r),f+=1),a+=n,r=i[a],r===r&&(s=u(s+r),f+=1),a+=n,r=i[a],r===r&&(l=u(l+r),f+=1),a+=n,r=i[a],r===r&&(E=u(E+r),f+=1),a+=n;for(O=u(u(u(t+c)+u(o+p))+u(u(q+s)+u(l+E))),y;y<v;y++)r=i[a],r===r&&(O=u(O+r),f+=1),a+=n;return e[0]=u(e[0]+O),e[1]+=f,e}return f=g(v/2),f-=f%8,u(F(f,e,i,n,a)+F(v-f,e,i,n,a+f*n))}A.exports=F
|
|
3
|
+
});var W=C(function(N,P){
|
|
4
|
+
var m=require('@stdlib/number-float64-base-to-float32/dist'),k=K(),j=[0,0];function z(v,e,i,n){var R,a,t,c,o,p,q,s,l;if(v<=0)return NaN;if(v===1||n===0)return q=i[0],q===q&&v-e>0?0:NaN;if(n<0?a=(1-v)*n:a=0,j[0]=0,j[1]=0,k(v,j,i,n,a),s=j[1],c=s-e,c<=0)return NaN;for(R=m(j[0]/s),t=0,o=0,l=0;l<v;l++)q=i[a],q===q&&(p=m(q-R),t=m(t+m(p*p)),o=m(o+p),s+=1),a+=n;return m(m(t/c)-m(m(o/s)*m(o/c)))}P.exports=z
|
|
5
|
+
});var B=C(function(x,_){
|
|
6
|
+
var M=require('@stdlib/number-float64-base-to-float32/dist'),D=K(),w=[0,0];function G(v,e,i,n,R){var a,t,c,o,p,q,s,l,E;if(v<=0)return NaN;if(v===1||n===0)return s=i[R],s===s&&v-e>0?0:NaN;if(t=R,w[0]=0,w[1]=0,D(v,w,i,n,t),l=w[1],o=l-e,o<=0)return NaN;for(a=M(w[0]/l),c=0,p=0,E=0;E<v;E++)s=i[t],s===s&&(q=M(s-a),c=M(c+M(q*q)),p=M(p+q),l+=1),t+=n;return M(M(c/o)-M(M(p/l)*M(p/o)))}_.exports=G
|
|
7
|
+
});var Z=C(function(d,L){
|
|
8
|
+
var H=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),I=W(),J=B();H(I,"ndarray",J);L.exports=I
|
|
9
|
+
});var Q=require("path").join,U=require('@stdlib/utils-try-require/dist'),V=require('@stdlib/assert-is-error/dist'),X=Z(),S,b=U(Q(__dirname,"./native.js"));V(b)?S=X:S=b;module.exports=S;
|
|
10
|
+
/** @license Apache-2.0 */
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../lib/snansumpw.js", "../lib/snanvariancepn.js", "../lib/ndarray.js", "../lib/main.js", "../lib/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );\nvar floor = require( '@stdlib/math-base-special-floor' );\n\n\n// VARIABLES //\n\n// Blocksize for pairwise summation (NOTE: decreasing the blocksize decreases rounding error as more pairs are summed, but also decreases performance. Because the inner loop is unrolled eight times, the blocksize is effectively `16`.):\nvar BLOCKSIZE = 128;\n\n\n// MAIN //\n\n/**\n* Computes the sum of a double-precision floating-point strided array elements, ignoring `NaN` values and using pairwise summation.\n*\n* ## Method\n*\n* - This implementation uses pairwise summation, which accrues rounding error `O(log2 N)` instead of `O(N)`. The recursion depth is also `O(log2 N)`.\n*\n* ## References\n*\n* - Higham, Nicholas J. 1993. \"The Accuracy of Floating Point Summation.\" _SIAM Journal on Scientific Computing_ 14 (4): 783\u201399. doi:[10.1137/0914050](https://doi.org/10.1137/0914050).\n*\n* @private\n* @param {PositiveInteger} N - number of indexed elements\n* @param {NumericArray} out - two-element output array whose first element is the accumulated sum and whose second element is the accumulated number of summed values\n* @param {Float32Array} x - input array\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @returns {NumericArray} output array\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var N = floor( x.length / 2 );\n*\n* var out = [ 0.0, 0 ];\n* var v = snansumpw( N, out, x, 2, 1 );\n* // returns [ 5.0, 4 ]\n*/\nfunction snansumpw( N, out, x, stride, offset ) {\n\tvar ix;\n\tvar s0;\n\tvar s1;\n\tvar s2;\n\tvar s3;\n\tvar s4;\n\tvar s5;\n\tvar s6;\n\tvar s7;\n\tvar M;\n\tvar s;\n\tvar n;\n\tvar v;\n\tvar i;\n\n\tix = offset;\n\tif ( N < 8 ) {\n\t\t// Use simple summation...\n\t\ts = 0.0;\n\t\tn = 0;\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts = float64ToFloat32( s + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t}\n\t\tout[ 0 ] = float64ToFloat32( out[ 0 ] + s );\n\t\tout[ 1 ] += n;\n\t\treturn out;\n\t}\n\tif ( N <= BLOCKSIZE ) {\n\t\t// Sum a block with 8 accumulators (by loop unrolling, we lower the effective blocksize to 16)...\n\t\ts0 = 0.0;\n\t\ts1 = 0.0;\n\t\ts2 = 0.0;\n\t\ts3 = 0.0;\n\t\ts4 = 0.0;\n\t\ts5 = 0.0;\n\t\ts6 = 0.0;\n\t\ts7 = 0.0;\n\t\tn = 0;\n\n\t\tM = N % 8;\n\t\tfor ( i = 0; i < N-M; i += 8 ) {\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts0 = float64ToFloat32( s0 + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts1 = float64ToFloat32( s1 + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts2 = float64ToFloat32( s2 + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts3 = float64ToFloat32( s3 + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts4 = float64ToFloat32( s4 + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts5 = float64ToFloat32( s5 + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts6 = float64ToFloat32( s6 + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts7 = float64ToFloat32( s7 + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t}\n\t\t// Pairwise sum the accumulators:\n\t\ts = float64ToFloat32( float64ToFloat32(float64ToFloat32(s0+s1) + float64ToFloat32(s2+s3)) + float64ToFloat32(float64ToFloat32(s4+s5) + float64ToFloat32(s6+s7)) ); // eslint-disable-line max-len\n\n\t\t// Clean-up loop...\n\t\tfor ( i; i < N; i++ ) {\n\t\t\tv = x[ ix ];\n\t\t\tif ( v === v ) {\n\t\t\t\ts = float64ToFloat32( s + v );\n\t\t\t\tn += 1;\n\t\t\t}\n\t\t\tix += stride;\n\t\t}\n\t\tout[ 0 ] = float64ToFloat32( out[ 0 ] + s );\n\t\tout[ 1 ] += n;\n\t\treturn out;\n\t}\n\t// Recurse by dividing by two, but avoiding non-multiples of unroll factor...\n\tn = floor( N/2 );\n\tn -= n % 8;\n\treturn float64ToFloat32( snansumpw( n, out, x, stride, ix ) + snansumpw( N-n, out, x, stride, ix+(n*stride) ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = snansumpw;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );\nvar snansumpw = require( './snansumpw.js' );\n\n\n// VARIABLES //\n\nvar WORKSPACE = [ 0.0, 0 ];\n\n\n// MAIN //\n\n/**\n* Computes the variance of a single-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm.\n*\n* ## Method\n*\n* - This implementation uses a two-pass approach, as suggested by Neely (1966).\n*\n* ## References\n*\n* - Neely, Peter M. 1966. \"Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients.\" _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496\u201399. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958).\n* - Schubert, Erich, and Michael Gertz. 2018. \"Numerically Stable Parallel Computation of (Co-)Variance.\" In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} correction - degrees of freedom adjustment\n* @param {Float32Array} x - input array\n* @param {integer} stride - stride length\n* @returns {number} variance\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n* var N = x.length;\n*\n* var v = snanvariancepn( N, 1, x, 1 );\n* // returns ~4.3333\n*/\nfunction snanvariancepn( N, correction, x, stride ) {\n\tvar mu;\n\tvar ix;\n\tvar M2;\n\tvar nc;\n\tvar M;\n\tvar d;\n\tvar v;\n\tvar n;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn NaN;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tv = x[ 0 ];\n\t\tif ( v === v && N-correction > 0.0 ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn NaN;\n\t}\n\tif ( stride < 0 ) {\n\t\tix = (1-N) * stride;\n\t} else {\n\t\tix = 0;\n\t}\n\t// Compute an estimate for the mean...\n\tWORKSPACE[ 0 ] = 0.0;\n\tWORKSPACE[ 1 ] = 0;\n\tsnansumpw( N, WORKSPACE, x, stride, ix );\n\tn = WORKSPACE[ 1 ];\n\tnc = n - correction;\n\tif ( nc <= 0.0 ) {\n\t\treturn NaN;\n\t}\n\tmu = float64ToFloat32( WORKSPACE[ 0 ] / n );\n\n\t// Compute the variance...\n\tM2 = 0.0;\n\tM = 0.0;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = x[ ix ];\n\t\tif ( v === v ) {\n\t\t\td = float64ToFloat32( v - mu );\n\t\t\tM2 = float64ToFloat32( M2 + float64ToFloat32( d*d ) );\n\t\t\tM = float64ToFloat32( M + d );\n\t\t\tn += 1;\n\t\t}\n\t\tix += stride;\n\t}\n\treturn float64ToFloat32( float64ToFloat32(M2/nc) - float64ToFloat32(float64ToFloat32(M/n)*float64ToFloat32(M/nc)) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = snanvariancepn;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar float64ToFloat32 = require( '@stdlib/number-float64-base-to-float32' );\nvar snansumpw = require( './snansumpw.js' );\n\n\n// VARIABLES //\n\nvar WORKSPACE = [ 0.0, 0 ];\n\n\n// MAIN //\n\n/**\n* Computes the variance of a single-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm.\n*\n* ## Method\n*\n* - This implementation uses a two-pass approach, as suggested by Neely (1966).\n*\n* ## References\n*\n* - Neely, Peter M. 1966. \"Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients.\" _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496\u201399. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958).\n* - Schubert, Erich, and Michael Gertz. 2018. \"Numerically Stable Parallel Computation of (Co-)Variance.\" In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036).\n*\n* @param {PositiveInteger} N - number of indexed elements\n* @param {number} correction - degrees of freedom adjustment\n* @param {Float32Array} x - input array\n* @param {integer} stride - stride length\n* @param {NonNegativeInteger} offset - starting index\n* @returns {number} variance\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var N = floor( x.length / 2 );\n*\n* var v = snanvariancepn( N, 1, x, 2, 1 );\n* // returns 6.25\n*/\nfunction snanvariancepn( N, correction, x, stride, offset ) {\n\tvar mu;\n\tvar ix;\n\tvar M2;\n\tvar nc;\n\tvar M;\n\tvar d;\n\tvar v;\n\tvar n;\n\tvar i;\n\n\tif ( N <= 0 ) {\n\t\treturn NaN;\n\t}\n\tif ( N === 1 || stride === 0 ) {\n\t\tv = x[ offset ];\n\t\tif ( v === v && N-correction > 0.0 ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\treturn NaN;\n\t}\n\tix = offset;\n\n\t// Compute an estimate for the mean...\n\tWORKSPACE[ 0 ] = 0.0;\n\tWORKSPACE[ 1 ] = 0;\n\tsnansumpw( N, WORKSPACE, x, stride, ix );\n\tn = WORKSPACE[ 1 ];\n\tnc = n - correction;\n\tif ( nc <= 0.0 ) {\n\t\treturn NaN;\n\t}\n\tmu = float64ToFloat32( WORKSPACE[ 0 ] / n );\n\n\t// Compute the variance...\n\tM2 = 0.0;\n\tM = 0.0;\n\tfor ( i = 0; i < N; i++ ) {\n\t\tv = x[ ix ];\n\t\tif ( v === v ) {\n\t\t\td = float64ToFloat32( v - mu );\n\t\t\tM2 = float64ToFloat32( M2 + float64ToFloat32( d*d ) );\n\t\t\tM = float64ToFloat32( M + d );\n\t\t\tn += 1;\n\t\t}\n\t\tix += stride;\n\t}\n\treturn float64ToFloat32( float64ToFloat32(M2/nc) - float64ToFloat32(float64ToFloat32(M/n)*float64ToFloat32(M/nc)) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = snanvariancepn;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar snanvariancepn = require( './snanvariancepn.js' );\nvar ndarray = require( './ndarray.js' );\n\n\n// MAIN //\n\nsetReadOnly( snanvariancepn, 'ndarray', ndarray );\n\n\n// EXPORTS //\n\nmodule.exports = snanvariancepn;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2020 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Compute the variance of a single-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm.\n*\n* @module @stdlib/stats-base-snanvariancepn\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var snanvariancepn = require( '@stdlib/stats-base-snanvariancepn' );\n*\n* var x = new Float32Array( [ 1.0, -2.0, NaN, 2.0 ] );\n*\n* var v = snanvariancepn( x.length, 1, x, 1 );\n* // returns ~4.3333\n*\n* @example\n* var Float32Array = require( '@stdlib/array-float32' );\n* var floor = require( '@stdlib/math-base-special-floor' );\n* var snanvariancepn = require( '@stdlib/stats-base-snanvariancepn' );\n*\n* var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );\n* var N = floor( x.length / 2 );\n*\n* var v = snanvariancepn.ndarray( N, 1, x, 2, 1 );\n* // returns 6.25\n*/\n\n// MODULES //\n\nvar join = require( 'path' ).join;\nvar tryRequire = require( '@stdlib/utils-try-require' );\nvar isError = require( '@stdlib/assert-is-error' );\nvar main = require( './main.js' );\n\n\n// MAIN //\n\nvar snanvariancepn;\nvar tmp = tryRequire( join( __dirname, './native.js' ) );\nif ( isError( tmp ) ) {\n\tsnanvariancepn = main;\n} else {\n\tsnanvariancepn = tmp;\n}\n\n\n// EXPORTS //\n\nmodule.exports = snanvariancepn;\n\n// exports: { \"ndarray\": \"snanvariancepn.ndarray\" }\n"],
|
|
5
|
+
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,wCAAyC,E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,EAAI,EACjBA,EAAW,CAAE,EAAI,EACjBD,EAAWG,EAAGF,EAAWI,EAAGC,EAAQG,CAAG,EACvCM,EAAId,EAAW,CAAE,EACjBU,EAAKI,EAAIX,EACJO,GAAM,EACV,MAAO,KAOR,IALAH,EAAKT,EAAkBE,EAAW,CAAE,EAAIc,CAAE,EAG1CL,EAAK,EACLE,EAAI,EACEI,EAAI,EAAGA,EAAIb,EAAGa,IACnBF,EAAIT,EAAGI,CAAG,EACLK,IAAMA,IACVD,EAAId,EAAkBe,EAAIN,CAAG,EAC7BE,EAAKX,EAAkBW,EAAKX,EAAkBc,EAAEA,CAAE,CAAE,EACpDD,EAAIb,EAAkBa,EAAIC,CAAE,EAC5BE,GAAK,GAENN,GAAMH,EAEP,OAAOP,EAAkBA,EAAiBW,EAAGC,CAAE,EAAIZ,EAAiBA,EAAiBa,EAAEG,CAAC,EAAEhB,EAAiBa,EAAED,CAAE,CAAC,CAAE,CACnH,CAKAb,EAAO,QAAUI,ICnHjB,IAAAe,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,uDAAwD,EAC/EC,EAAiB,IACjBC,EAAU,IAKdF,EAAaC,EAAgB,UAAWC,CAAQ,EAKhDH,EAAO,QAAUE,ICcjB,IAAIE,EAAO,QAAS,MAAO,EAAE,KACzBC,EAAa,QAAS,2BAA4B,EAClDC,EAAU,QAAS,yBAA0B,EAC7CC,EAAO,IAKPC,EACAC,EAAMJ,EAAYD,EAAM,UAAW,aAAc,CAAE,EAClDE,EAASG,CAAI,EACjBD,EAAiBD,EAEjBC,EAAiBC,EAMlB,OAAO,QAAUD",
|
|
6
|
+
"names": ["require_snansumpw", "__commonJSMin", "exports", "module", "float64ToFloat32", "floor", "BLOCKSIZE", "snansumpw", "N", "out", "x", "stride", "offset", "ix", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "M", "s", "n", "v", "i", "require_snanvariancepn", "__commonJSMin", "exports", "module", "float64ToFloat32", "snansumpw", "WORKSPACE", "snanvariancepn", "N", "correction", "x", "stride", "mu", "ix", "M2", "nc", "M", "d", "v", "n", "i", "require_ndarray", "__commonJSMin", "exports", "module", "float64ToFloat32", "snansumpw", "WORKSPACE", "snanvariancepn", "N", "correction", "x", "stride", "offset", "mu", "ix", "M2", "nc", "M", "d", "v", "n", "i", "require_main", "__commonJSMin", "exports", "module", "setReadOnly", "snanvariancepn", "ndarray", "join", "tryRequire", "isError", "main", "snanvariancepn", "tmp"]
|
|
7
|
+
}
|
package/docs/types/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
|
|
49
49
|
var join = require( 'path' ).join;
|
|
50
50
|
var tryRequire = require( '@stdlib/utils-try-require' );
|
|
51
|
+
var isError = require( '@stdlib/assert-is-error' );
|
|
51
52
|
var main = require( './main.js' );
|
|
52
53
|
|
|
53
54
|
|
|
@@ -55,7 +56,7 @@ var main = require( './main.js' );
|
|
|
55
56
|
|
|
56
57
|
var snanvariancepn;
|
|
57
58
|
var tmp = tryRequire( join( __dirname, './native.js' ) );
|
|
58
|
-
if ( tmp
|
|
59
|
+
if ( isError( tmp ) ) {
|
|
59
60
|
snanvariancepn = main;
|
|
60
61
|
} else {
|
|
61
62
|
snanvariancepn = tmp;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-snanvariancepn",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a two-pass algorithm.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -41,24 +41,25 @@
|
|
|
41
41
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@stdlib/
|
|
45
|
-
"@stdlib/
|
|
46
|
-
"@stdlib/
|
|
47
|
-
"@stdlib/utils-
|
|
48
|
-
"@stdlib/utils-
|
|
44
|
+
"@stdlib/assert-is-error": "^0.1.0",
|
|
45
|
+
"@stdlib/math-base-special-floor": "^0.1.0",
|
|
46
|
+
"@stdlib/number-float64-base-to-float32": "^0.1.0",
|
|
47
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.1.0",
|
|
48
|
+
"@stdlib/utils-library-manifest": "^0.1.0",
|
|
49
|
+
"@stdlib/utils-try-require": "^0.1.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@stdlib/array-float32": "^0.0
|
|
52
|
-
"@stdlib/assert-is-browser": "^0.0
|
|
53
|
-
"@stdlib/bench": "^0.0
|
|
54
|
-
"@stdlib/math-base-assert-is-nanf": "^0.0
|
|
55
|
-
"@stdlib/math-base-special-pow": "^0.0.
|
|
56
|
-
"@stdlib/math-base-special-round": "^0.0
|
|
57
|
-
"@stdlib/random-base-randu": "^0.0.
|
|
52
|
+
"@stdlib/array-float32": "^0.1.0",
|
|
53
|
+
"@stdlib/assert-is-browser": "^0.1.0",
|
|
54
|
+
"@stdlib/bench": "^0.1.0",
|
|
55
|
+
"@stdlib/math-base-assert-is-nanf": "^0.1.0",
|
|
56
|
+
"@stdlib/math-base-special-pow": "^0.0.7",
|
|
57
|
+
"@stdlib/math-base-special-round": "^0.1.0",
|
|
58
|
+
"@stdlib/random-base-randu": "^0.0.8",
|
|
58
59
|
"proxyquire": "^2.0.0",
|
|
59
60
|
"tape": "git+https://github.com/kgryte/tape.git#fix/globby",
|
|
60
61
|
"istanbul": "^0.4.1",
|
|
61
|
-
"tap-
|
|
62
|
+
"tap-min": "git+https://github.com/Planeshifter/tap-min.git"
|
|
62
63
|
},
|
|
63
64
|
"engines": {
|
|
64
65
|
"node": ">=0.10.0",
|
|
@@ -102,7 +103,7 @@
|
|
|
102
103
|
],
|
|
103
104
|
"__stdlib__": {},
|
|
104
105
|
"funding": {
|
|
105
|
-
"type": "
|
|
106
|
-
"url": "https://
|
|
106
|
+
"type": "opencollective",
|
|
107
|
+
"url": "https://opencollective.com/stdlib"
|
|
107
108
|
}
|
|
108
109
|
}
|
package/docs/repl.txt
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
{{alias}}( N, correction, x, stride )
|
|
3
|
-
Computes the variance of a single-precision floating-point strided array
|
|
4
|
-
ignoring `NaN` values and using a two-pass algorithm.
|
|
5
|
-
|
|
6
|
-
The `N` and `stride` parameters determine which elements in `x` are accessed
|
|
7
|
-
at runtime.
|
|
8
|
-
|
|
9
|
-
Indexing is relative to the first index. To introduce an offset, use a typed
|
|
10
|
-
array view.
|
|
11
|
-
|
|
12
|
-
If `N <= 0`, the function returns `NaN`.
|
|
13
|
-
|
|
14
|
-
If every indexed element is `NaN`, the function returns `NaN`.
|
|
15
|
-
|
|
16
|
-
Parameters
|
|
17
|
-
----------
|
|
18
|
-
N: integer
|
|
19
|
-
Number of indexed elements.
|
|
20
|
-
|
|
21
|
-
correction: number
|
|
22
|
-
Degrees of freedom adjustment. Setting this parameter to a value other
|
|
23
|
-
than `0` has the effect of adjusting the divisor during the calculation
|
|
24
|
-
of the variance according to `n - c` where `c` corresponds to the
|
|
25
|
-
provided degrees of freedom adjustment and `n` corresponds to the number
|
|
26
|
-
of non-`NaN` indexed elements. When computing the variance of a
|
|
27
|
-
population, setting this parameter to `0` is the standard choice (i.e.,
|
|
28
|
-
the provided array contains data constituting an entire population).
|
|
29
|
-
When computing the unbiased sample variance, setting this parameter to
|
|
30
|
-
`1` is the standard choice (i.e., the provided array contains data
|
|
31
|
-
sampled from a larger population; this is commonly referred to as
|
|
32
|
-
Bessel's correction).
|
|
33
|
-
|
|
34
|
-
x: Float32Array
|
|
35
|
-
Input array.
|
|
36
|
-
|
|
37
|
-
stride: integer
|
|
38
|
-
Index increment.
|
|
39
|
-
|
|
40
|
-
Returns
|
|
41
|
-
-------
|
|
42
|
-
out: number
|
|
43
|
-
The variance.
|
|
44
|
-
|
|
45
|
-
Examples
|
|
46
|
-
--------
|
|
47
|
-
// Standard Usage:
|
|
48
|
-
> var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, NaN, 2.0 ] );
|
|
49
|
-
> {{alias}}( x.length, 1, x, 1 )
|
|
50
|
-
~4.3333
|
|
51
|
-
|
|
52
|
-
// Using `N` and `stride` parameters:
|
|
53
|
-
> x = new {{alias:@stdlib/array/float32}}( [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ] );
|
|
54
|
-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
|
|
55
|
-
> {{alias}}( N, 1, x, 2 )
|
|
56
|
-
~4.3333
|
|
57
|
-
|
|
58
|
-
// Using view offsets:
|
|
59
|
-
> var x0 = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
|
|
60
|
-
> var x1 = new {{alias:@stdlib/array/float32}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
|
|
61
|
-
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
|
|
62
|
-
> {{alias}}( N, 1, x1, 2 )
|
|
63
|
-
~4.3333
|
|
64
|
-
|
|
65
|
-
{{alias}}.ndarray( N, correction, x, stride, offset )
|
|
66
|
-
Computes the variance of a single-precision floating-point strided array
|
|
67
|
-
ignoring `NaN` values and using a two-pass algorithm and alternative
|
|
68
|
-
indexing semantics.
|
|
69
|
-
|
|
70
|
-
While typed array views mandate a view offset based on the underlying
|
|
71
|
-
buffer, the `offset` parameter supports indexing semantics based on a
|
|
72
|
-
starting index.
|
|
73
|
-
|
|
74
|
-
Parameters
|
|
75
|
-
----------
|
|
76
|
-
N: integer
|
|
77
|
-
Number of indexed elements.
|
|
78
|
-
|
|
79
|
-
correction: number
|
|
80
|
-
Degrees of freedom adjustment. Setting this parameter to a value other
|
|
81
|
-
than `0` has the effect of adjusting the divisor during the calculation
|
|
82
|
-
of the variance according to `n - c` where `c` corresponds to the
|
|
83
|
-
provided degrees of freedom adjustment and `n` corresponds to the number
|
|
84
|
-
of non-`NaN` indexed elements. When computing the variance of a
|
|
85
|
-
population, setting this parameter to `0` is the standard choice (i.e.,
|
|
86
|
-
the provided array contains data constituting an entire population).
|
|
87
|
-
When computing the unbiased sample variance, setting this parameter to
|
|
88
|
-
`1` is the standard choice (i.e., the provided array contains data
|
|
89
|
-
sampled from a larger population; this is commonly referred to as
|
|
90
|
-
Bessel's correction).
|
|
91
|
-
|
|
92
|
-
x: Float32Array
|
|
93
|
-
Input array.
|
|
94
|
-
|
|
95
|
-
stride: integer
|
|
96
|
-
Index increment.
|
|
97
|
-
|
|
98
|
-
offset: integer
|
|
99
|
-
Starting index.
|
|
100
|
-
|
|
101
|
-
Returns
|
|
102
|
-
-------
|
|
103
|
-
out: number
|
|
104
|
-
The variance.
|
|
105
|
-
|
|
106
|
-
Examples
|
|
107
|
-
--------
|
|
108
|
-
// Standard Usage:
|
|
109
|
-
> var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, NaN, 2.0 ] );
|
|
110
|
-
> {{alias}}.ndarray( x.length, 1, x, 1, 0 )
|
|
111
|
-
~4.3333
|
|
112
|
-
|
|
113
|
-
// Using offset parameter:
|
|
114
|
-
> var x = new {{alias:@stdlib/array/float32}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
|
|
115
|
-
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
|
|
116
|
-
> {{alias}}.ndarray( N, 1, x, 2, 1 )
|
|
117
|
-
~4.3333
|
|
118
|
-
|
|
119
|
-
See Also
|
|
120
|
-
--------
|
|
121
|
-
|
package/docs/types/test.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @license Apache-2.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020 The Stdlib Authors.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import snanvariancepn = require( './index' );
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// TESTS //
|
|
23
|
-
|
|
24
|
-
// The function returns a number...
|
|
25
|
-
{
|
|
26
|
-
const x = new Float32Array( 10 );
|
|
27
|
-
|
|
28
|
-
snanvariancepn( x.length, 1, x, 1 ); // $ExpectType number
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// The compiler throws an error if the function is provided a first argument which is not a number...
|
|
32
|
-
{
|
|
33
|
-
const x = new Float32Array( 10 );
|
|
34
|
-
|
|
35
|
-
snanvariancepn( '10', 1, x, 1 ); // $ExpectError
|
|
36
|
-
snanvariancepn( true, 1, x, 1 ); // $ExpectError
|
|
37
|
-
snanvariancepn( false, 1, x, 1 ); // $ExpectError
|
|
38
|
-
snanvariancepn( null, 1, x, 1 ); // $ExpectError
|
|
39
|
-
snanvariancepn( undefined, 1, x, 1 ); // $ExpectError
|
|
40
|
-
snanvariancepn( [], 1, x, 1 ); // $ExpectError
|
|
41
|
-
snanvariancepn( {}, 1, x, 1 ); // $ExpectError
|
|
42
|
-
snanvariancepn( ( x: number ): number => x, 1, x, 1 ); // $ExpectError
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// The compiler throws an error if the function is provided a second argument which is not a number...
|
|
46
|
-
{
|
|
47
|
-
const x = new Float32Array( 10 );
|
|
48
|
-
|
|
49
|
-
snanvariancepn( x.length, '10', x, 1 ); // $ExpectError
|
|
50
|
-
snanvariancepn( x.length, true, x, 1 ); // $ExpectError
|
|
51
|
-
snanvariancepn( x.length, false, x, 1 ); // $ExpectError
|
|
52
|
-
snanvariancepn( x.length, null, x, 1 ); // $ExpectError
|
|
53
|
-
snanvariancepn( x.length, undefined, x, 1 ); // $ExpectError
|
|
54
|
-
snanvariancepn( x.length, [], x, 1 ); // $ExpectError
|
|
55
|
-
snanvariancepn( x.length, {}, x, 1 ); // $ExpectError
|
|
56
|
-
snanvariancepn( x.length, ( x: number ): number => x, x, 1 ); // $ExpectError
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// The compiler throws an error if the function is provided a third argument which is not a Float32Array...
|
|
60
|
-
{
|
|
61
|
-
const x = new Float32Array( 10 );
|
|
62
|
-
|
|
63
|
-
snanvariancepn( x.length, 1, 10, 1 ); // $ExpectError
|
|
64
|
-
snanvariancepn( x.length, 1, '10', 1 ); // $ExpectError
|
|
65
|
-
snanvariancepn( x.length, 1, true, 1 ); // $ExpectError
|
|
66
|
-
snanvariancepn( x.length, 1, false, 1 ); // $ExpectError
|
|
67
|
-
snanvariancepn( x.length, 1, null, 1 ); // $ExpectError
|
|
68
|
-
snanvariancepn( x.length, 1, undefined, 1 ); // $ExpectError
|
|
69
|
-
snanvariancepn( x.length, 1, [], 1 ); // $ExpectError
|
|
70
|
-
snanvariancepn( x.length, 1, {}, 1 ); // $ExpectError
|
|
71
|
-
snanvariancepn( x.length, 1, ( x: number ): number => x, 1 ); // $ExpectError
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// The compiler throws an error if the function is provided a fourth argument which is not a number...
|
|
75
|
-
{
|
|
76
|
-
const x = new Float32Array( 10 );
|
|
77
|
-
|
|
78
|
-
snanvariancepn( x.length, 1, x, '10' ); // $ExpectError
|
|
79
|
-
snanvariancepn( x.length, 1, x, true ); // $ExpectError
|
|
80
|
-
snanvariancepn( x.length, 1, x, false ); // $ExpectError
|
|
81
|
-
snanvariancepn( x.length, 1, x, null ); // $ExpectError
|
|
82
|
-
snanvariancepn( x.length, 1, x, undefined ); // $ExpectError
|
|
83
|
-
snanvariancepn( x.length, 1, x, [] ); // $ExpectError
|
|
84
|
-
snanvariancepn( x.length, 1, x, {} ); // $ExpectError
|
|
85
|
-
snanvariancepn( x.length, 1, x, ( x: number ): number => x ); // $ExpectError
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// The compiler throws an error if the function is provided an unsupported number of arguments...
|
|
89
|
-
{
|
|
90
|
-
const x = new Float32Array( 10 );
|
|
91
|
-
|
|
92
|
-
snanvariancepn(); // $ExpectError
|
|
93
|
-
snanvariancepn( x.length ); // $ExpectError
|
|
94
|
-
snanvariancepn( x.length, 1 ); // $ExpectError
|
|
95
|
-
snanvariancepn( x.length, 1, x ); // $ExpectError
|
|
96
|
-
snanvariancepn( x.length, 1, x, 1, 10 ); // $ExpectError
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Attached to main export is an `ndarray` method which returns a number...
|
|
100
|
-
{
|
|
101
|
-
const x = new Float32Array( 10 );
|
|
102
|
-
|
|
103
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...
|
|
107
|
-
{
|
|
108
|
-
const x = new Float32Array( 10 );
|
|
109
|
-
|
|
110
|
-
snanvariancepn.ndarray( '10', 1, x, 1, 0 ); // $ExpectError
|
|
111
|
-
snanvariancepn.ndarray( true, 1, x, 1, 0 ); // $ExpectError
|
|
112
|
-
snanvariancepn.ndarray( false, 1, x, 1, 0 ); // $ExpectError
|
|
113
|
-
snanvariancepn.ndarray( null, 1, x, 1, 0 ); // $ExpectError
|
|
114
|
-
snanvariancepn.ndarray( undefined, 1, x, 1, 0 ); // $ExpectError
|
|
115
|
-
snanvariancepn.ndarray( [], 1, x, 1, 0 ); // $ExpectError
|
|
116
|
-
snanvariancepn.ndarray( {}, 1, x, 1, 0 ); // $ExpectError
|
|
117
|
-
snanvariancepn.ndarray( ( x: number ): number => x, 1, x, 1, 0 ); // $ExpectError
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// The compiler throws an error if the `ndarray` method is provided a second argument which is not a number...
|
|
121
|
-
{
|
|
122
|
-
const x = new Float32Array( 10 );
|
|
123
|
-
|
|
124
|
-
snanvariancepn.ndarray( x.length, '10', x, 1, 0 ); // $ExpectError
|
|
125
|
-
snanvariancepn.ndarray( x.length, true, x, 1, 0 ); // $ExpectError
|
|
126
|
-
snanvariancepn.ndarray( x.length, false, x, 1, 0 ); // $ExpectError
|
|
127
|
-
snanvariancepn.ndarray( x.length, null, x, 1, 0 ); // $ExpectError
|
|
128
|
-
snanvariancepn.ndarray( x.length, undefined, x, 1, 0 ); // $ExpectError
|
|
129
|
-
snanvariancepn.ndarray( x.length, [], x, 1, 0 ); // $ExpectError
|
|
130
|
-
snanvariancepn.ndarray( x.length, {}, x, 1, 0 ); // $ExpectError
|
|
131
|
-
snanvariancepn.ndarray( x.length, ( x: number ): number => x, x, 1, 0 ); // $ExpectError
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// The compiler throws an error if the `ndarray` method is provided a third argument which is not a Float32Array...
|
|
135
|
-
{
|
|
136
|
-
const x = new Float32Array( 10 );
|
|
137
|
-
|
|
138
|
-
snanvariancepn.ndarray( x.length, 1, 10, 1, 0 ); // $ExpectError
|
|
139
|
-
snanvariancepn.ndarray( x.length, 1, '10', 1, 0 ); // $ExpectError
|
|
140
|
-
snanvariancepn.ndarray( x.length, 1, true, 1, 0 ); // $ExpectError
|
|
141
|
-
snanvariancepn.ndarray( x.length, 1, false, 1, 0 ); // $ExpectError
|
|
142
|
-
snanvariancepn.ndarray( x.length, 1, null, 1, 0 ); // $ExpectError
|
|
143
|
-
snanvariancepn.ndarray( x.length, 1, undefined, 1, 0 ); // $ExpectError
|
|
144
|
-
snanvariancepn.ndarray( x.length, 1, [], 1, 0 ); // $ExpectError
|
|
145
|
-
snanvariancepn.ndarray( x.length, 1, {}, 1, 0 ); // $ExpectError
|
|
146
|
-
snanvariancepn.ndarray( x.length, 1, ( x: number ): number => x, 1, 0 ); // $ExpectError
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a number...
|
|
150
|
-
{
|
|
151
|
-
const x = new Float32Array( 10 );
|
|
152
|
-
|
|
153
|
-
snanvariancepn.ndarray( x.length, 1, x, '10', 0 ); // $ExpectError
|
|
154
|
-
snanvariancepn.ndarray( x.length, 1, x, true, 0 ); // $ExpectError
|
|
155
|
-
snanvariancepn.ndarray( x.length, 1, x, false, 0 ); // $ExpectError
|
|
156
|
-
snanvariancepn.ndarray( x.length, 1, x, null, 0 ); // $ExpectError
|
|
157
|
-
snanvariancepn.ndarray( x.length, 1, x, undefined, 0 ); // $ExpectError
|
|
158
|
-
snanvariancepn.ndarray( x.length, 1, x, [], 0 ); // $ExpectError
|
|
159
|
-
snanvariancepn.ndarray( x.length, 1, x, {}, 0 ); // $ExpectError
|
|
160
|
-
snanvariancepn.ndarray( x.length, 1, x, ( x: number ): number => x, 0 ); // $ExpectError
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a number...
|
|
164
|
-
{
|
|
165
|
-
const x = new Float32Array( 10 );
|
|
166
|
-
|
|
167
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, '10' ); // $ExpectError
|
|
168
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, true ); // $ExpectError
|
|
169
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, false ); // $ExpectError
|
|
170
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, null ); // $ExpectError
|
|
171
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, undefined ); // $ExpectError
|
|
172
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, [] ); // $ExpectError
|
|
173
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, {} ); // $ExpectError
|
|
174
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, ( x: number ): number => x ); // $ExpectError
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// The compiler throws an error if the `ndarray` method is provided an unsupported number of arguments...
|
|
178
|
-
{
|
|
179
|
-
const x = new Float32Array( 10 );
|
|
180
|
-
|
|
181
|
-
snanvariancepn.ndarray(); // $ExpectError
|
|
182
|
-
snanvariancepn.ndarray( x.length ); // $ExpectError
|
|
183
|
-
snanvariancepn.ndarray( x.length, 1 ); // $ExpectError
|
|
184
|
-
snanvariancepn.ndarray( x.length, 1, x ); // $ExpectError
|
|
185
|
-
snanvariancepn.ndarray( x.length, 1, x, 1 ); // $ExpectError
|
|
186
|
-
snanvariancepn.ndarray( x.length, 1, x, 1, 0, 10 ); // $ExpectError
|
|
187
|
-
}
|