@stdlib/stats-strided-svariancetk 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/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,487 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2020 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
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
+
32
+ # svariancetk
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > Calculate the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm.
37
+
38
+ <section class="intro">
39
+
40
+ The population [variance][variance] of a finite size population of size `N` is given by
41
+
42
+ <!-- <equation class="equation" label="eq:population_variance" align="center" raw="\sigma^2 = \frac{1}{N} \sum_{i=0}^{N-1} (x_i - \mu)^2" alt="Equation for the population variance."> -->
43
+
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">
45
+ <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@6da3e7388e483798f23a9ce30fcb35f454e7e3b4/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance.svg" alt="Equation for the population variance.">
46
+ <br>
47
+ </div> -->
48
+
49
+ <!-- </equation> -->
50
+
51
+ where the population mean is given by
52
+
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."> -->
54
+
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">
56
+ <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@6da3e7388e483798f23a9ce30fcb35f454e7e3b4/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_mean.svg" alt="Equation for the population mean.">
57
+ <br>
58
+ </div> -->
59
+
60
+ <!-- </equation> -->
61
+
62
+ After rearranging terms, the population [variance][variance] can be equivalently expressed as
63
+
64
+ <!-- <equation class="equation" label="eq:population_variance_textbook" align="center" raw="\sigma^2 = \frac{1}{N}\biggl(\ \sum_{i=0}^{N-1} x_i^2 - \frac{1}{N}\biggl(\ \sum_{i=0}^{N-1} x_i \ \biggr)^2\ \biggr)" alt="Equation for the population variance (one-pass textbook formula)."> -->
65
+
66
+ <!-- <div class="equation" align="center" data-raw-text="\sigma^2 = \frac{1}{N}\biggl(\ \sum_{i=0}^{N-1} x_i^2 - \frac{1}{N}\biggl(\ \sum_{i=0}^{N-1} x_i \ \biggr)^2\ \biggr)" data-equation="eq:population_variance_textbook">
67
+ <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@6da3e7388e483798f23a9ce30fcb35f454e7e3b4/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_population_variance_textbook.svg" alt="Equation for the population variance (one-pass textbook formula).">
68
+ <br>
69
+ </div> -->
70
+
71
+ <!-- </equation> -->
72
+
73
+ Often in the analysis of data, the true population [variance][variance] is not known _a priori_ and must be estimated from a sample drawn from the population distribution. If one attempts to use the formula for the population [variance][variance], the result is biased and yields a **biased sample variance**. To compute an **unbiased sample variance** for a sample of size `n`,
74
+
75
+ <!-- <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."> -->
76
+
77
+ <!-- <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">
78
+ <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@6da3e7388e483798f23a9ce30fcb35f454e7e3b4/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance.svg" alt="Equation for computing an unbiased sample variance.">
79
+ <br>
80
+ </div> -->
81
+
82
+ <!-- </equation> -->
83
+
84
+ where the sample mean is given by
85
+
86
+ <!-- <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."> -->
87
+
88
+ <!-- <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">
89
+ <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@6da3e7388e483798f23a9ce30fcb35f454e7e3b4/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_sample_mean.svg" alt="Equation for the sample mean.">
90
+ <br>
91
+ </div> -->
92
+
93
+ <!-- </equation> -->
94
+
95
+ Similar to the population [variance][variance], after rearranging terms, the **unbiased sample variance** can be equivalently expressed as
96
+
97
+ <!-- <equation class="equation" label="eq:unbiased_sample_variance_textbook" align="center" raw="s^2 = \frac{1}{n-1}\biggl(\ \sum_{i=0}^{n-1} x_i^2 - \frac{1}{n}\biggl(\ \sum_{i=0}^{n-1} x_i \ \biggr)^2\ \biggr)" alt="Equation for the unbiased sample variance (one-pass textbook formula)."> -->
98
+
99
+ <!-- <div class="equation" align="center" data-raw-text="s^2 = \frac{1}{n-1}\biggl(\ \sum_{i=0}^{n-1} x_i^2 - \frac{1}{n}\biggl(\ \sum_{i=0}^{n-1} x_i \ \biggr)^2\ \biggr)" data-equation="eq:unbiased_sample_variance_textbook">
100
+ <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@6da3e7388e483798f23a9ce30fcb35f454e7e3b4/lib/node_modules/@stdlib/stats/strided/svariancetk/docs/img/equation_unbiased_sample_variance_textbook.svg" alt="Equation for the unbiased sample variance (one-pass textbook formula).">
101
+ <br>
102
+ </div>
103
+
104
+ <!-- </equation> -->
105
+
106
+ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, however, that applying Bessel's correction can increase the mean squared error between the sample variance and population variance. Depending on the characteristics of the population distribution, other correction factors (e.g., `n-1.5`, `n+1`, etc) can yield better estimators.
107
+
108
+ </section>
109
+
110
+ <!-- /.intro -->
111
+
112
+ <section class="installation">
113
+
114
+ ## Installation
115
+
116
+ ```bash
117
+ npm install @stdlib/stats-strided-svariancetk
118
+ ```
119
+
120
+ </section>
121
+
122
+ <section class="usage">
123
+
124
+ ## Usage
125
+
126
+ ```javascript
127
+ var svariancetk = require( '@stdlib/stats-strided-svariancetk' );
128
+ ```
129
+
130
+ #### svariancetk( N, correction, x, strideX )
131
+
132
+ Computes the [variance][variance] of a single-precision floating-point strided array `x` using a one-pass textbook algorithm.
133
+
134
+ ```javascript
135
+ var Float32Array = require( '@stdlib/array-float32' );
136
+
137
+ var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
138
+
139
+ var v = svariancetk( x.length, 1, x, 1 );
140
+ // returns ~4.3333
141
+ ```
142
+
143
+ The function has the following parameters:
144
+
145
+ - **N**: number of indexed elements.
146
+ - **correction**: 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 [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction).
147
+ - **x**: input [`Float32Array`][@stdlib/array/float32].
148
+ - **strideX**: stride length for `x`.
149
+
150
+ The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`,
151
+
152
+ ```javascript
153
+ var Float32Array = require( '@stdlib/array-float32' );
154
+
155
+ var x = new Float32Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
156
+
157
+ var v = svariancetk( 4, 1, x, 2 );
158
+ // returns 6.25
159
+ ```
160
+
161
+ Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
162
+
163
+ <!-- eslint-disable stdlib/capitalized-comments -->
164
+
165
+ ```javascript
166
+ var Float32Array = require( '@stdlib/array-float32' );
167
+
168
+ var x0 = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
169
+ var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
170
+
171
+ var v = svariancetk( 4, 1, x1, 2 );
172
+ // returns 6.25
173
+ ```
174
+
175
+ #### svariancetk.ndarray( N, correction, x, strideX, offsetX )
176
+
177
+ Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics.
178
+
179
+ ```javascript
180
+ var Float32Array = require( '@stdlib/array-float32' );
181
+
182
+ var x = new Float32Array( [ 1.0, -2.0, 2.0 ] );
183
+
184
+ var v = svariancetk.ndarray( x.length, 1, x, 1, 0 );
185
+ // returns ~4.33333
186
+ ```
187
+
188
+ The function has the following additional parameters:
189
+
190
+ - **offsetX**: starting index for `x`.
191
+
192
+ While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to calculate the [variance][variance] for every other element in `x` starting from the second element
193
+
194
+ ```javascript
195
+ var Float32Array = require( '@stdlib/array-float32' );
196
+
197
+ var x = new Float32Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
198
+
199
+ var v = svariancetk.ndarray( 4, 1, x, 2, 1 );
200
+ // returns 6.25
201
+ ```
202
+
203
+ </section>
204
+
205
+ <!-- /.usage -->
206
+
207
+ <section class="notes">
208
+
209
+ ## Notes
210
+
211
+ - If `N <= 0`, both functions return `NaN`.
212
+ - If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`.
213
+ - Some caution should be exercised when using the one-pass textbook algorithm. Literature overwhelmingly discourages the algorithm's use for two reasons: 1) the lack of safeguards against underflow and overflow and 2) the risk of catastrophic cancellation when subtracting the two sums if the sums are large and the variance small. These concerns have merit; however, the one-pass textbook algorithm should not be dismissed outright. For data distributions with a moderately large standard deviation to mean ratio (i.e., **coefficient of variation**), the one-pass textbook algorithm may be acceptable, especially when performance is paramount and some precision loss is acceptable (including a risk of returning a negative variance due to floating-point rounding errors!). In short, no single "best" algorithm for computing the variance exists. The "best" algorithm depends on the underlying data distribution, your performance requirements, and your minimum precision requirements. When evaluating which algorithm to use, consider the relative pros and cons, and choose the algorithm which best serves your needs.
214
+
215
+ </section>
216
+
217
+ <!-- /.notes -->
218
+
219
+ <section class="examples">
220
+
221
+ ## Examples
222
+
223
+ <!-- eslint no-undef: "error" -->
224
+
225
+ ```javascript
226
+ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
227
+ var svariancetk = require( '@stdlib/stats-strided-svariancetk' );
228
+
229
+ var x = discreteUniform( 10, -50, 50, {
230
+ 'dtype': 'float32'
231
+ });
232
+ console.log( x );
233
+
234
+ var v = svariancetk( x.length, 1, x, 1 );
235
+ console.log( v );
236
+ ```
237
+
238
+ </section>
239
+
240
+ <!-- /.examples -->
241
+
242
+ <!-- C interface documentation. -->
243
+
244
+ * * *
245
+
246
+ <section class="c">
247
+
248
+ ## C APIs
249
+
250
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
251
+
252
+ <section class="intro">
253
+
254
+ </section>
255
+
256
+ <!-- /.intro -->
257
+
258
+ <!-- C usage documentation. -->
259
+
260
+ <section class="usage">
261
+
262
+ ### Usage
263
+
264
+ ```c
265
+ #include "stdlib/stats/strided/svariancetk.h"
266
+ ```
267
+
268
+ #### stdlib_strided_svariancetk( N, correction, \*X, strideX )
269
+
270
+ Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm.
271
+
272
+ ```c
273
+ const float x[] = { 1.0f, -2.0f, 2.0f };
274
+
275
+ float v = stdlib_strided_svariancetk( 3, 1.0f, x, 1 );
276
+ // returns ~4.3333f
277
+ ```
278
+
279
+ The function accepts the following arguments:
280
+
281
+ - **N**: `[in] CBLAS_INT` number of indexed elements.
282
+ - **correction**: `[in] float` 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 [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction).
283
+ - **X**: `[in] float*` input array.
284
+ - **strideX**: `[in] CBLAS_INT` stride length for `X`.
285
+
286
+ ```c
287
+ float stdlib_strided_svariancetk( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX );
288
+ ```
289
+
290
+ #### stdlib_strided_svariancetk_ndarray( N, correction, \*X, strideX, offsetX )
291
+
292
+ Computes the [variance][variance] of a single-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics.
293
+
294
+ ```c
295
+ const float x[] = { 1.0f, -2.0f, 2.0f };
296
+
297
+ float v = stdlib_strided_svariancetk_ndarray( 3, 1.0f, x, 1, 0 );
298
+ // returns ~4.3333f
299
+ ```
300
+
301
+ The function accepts the following arguments:
302
+
303
+ - **N**: `[in] CBLAS_INT` number of indexed elements.
304
+ - **correction**: `[in] float` 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 [variance][variance] according to `N-c` where `c` corresponds to the provided degrees of freedom adjustment. When computing the [variance][variance] of a population, setting this parameter to `0` is the standard choice (i.e., the provided array contains data constituting an entire population). When computing the unbiased sample [variance][variance], setting this parameter to `1` is the standard choice (i.e., the provided array contains data sampled from a larger population; this is commonly referred to as Bessel's correction).
305
+ - **X**: `[in] float*` input array.
306
+ - **strideX**: `[in] CBLAS_INT` stride length for `X`.
307
+ - **offsetX**: `[in] CBLAS_INT` starting index for `X`.
308
+
309
+ ```c
310
+ float stdlib_strided_svariancetk_ndarray( const CBLAS_INT N, const float correction, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX );
311
+ ```
312
+
313
+ </section>
314
+
315
+ <!-- /.usage -->
316
+
317
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
318
+
319
+ <section class="notes">
320
+
321
+ </section>
322
+
323
+ <!-- /.notes -->
324
+
325
+ <!-- C API usage examples. -->
326
+
327
+ <section class="examples">
328
+
329
+ ### Examples
330
+
331
+ ```c
332
+ #include "stdlib/stats/strided/svariancetk.h"
333
+ #include <stdio.h>
334
+
335
+ int main( void ) {
336
+ // Create a strided array:
337
+ const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
338
+
339
+ // Specify the number of elements:
340
+ const int N = 4;
341
+
342
+ // Specify the stride length:
343
+ const int strideX = 2;
344
+
345
+ // Compute the variance:
346
+ float v = stdlib_strided_svariancetk( N, 1.0f, x, strideX );
347
+
348
+ // Print the result:
349
+ printf( "sample variance: %f\n", v );
350
+ }
351
+ ```
352
+
353
+ </section>
354
+
355
+ <!-- /.examples -->
356
+
357
+ </section>
358
+
359
+ <!-- /.c -->
360
+
361
+ * * *
362
+
363
+ <section class="references">
364
+
365
+ ## References
366
+
367
+ - Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154][@ling:1974a].
368
+
369
+ </section>
370
+
371
+ <!-- /.references -->
372
+
373
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
374
+
375
+ <section class="related">
376
+
377
+ * * *
378
+
379
+ ## See Also
380
+
381
+ - <span class="package-name">[`@stdlib/stats-strided/dvariancetk`][@stdlib/stats/strided/dvariancetk]</span><span class="delimiter">: </span><span class="description">calculate the variance of a double-precision floating-point strided array using a one-pass textbook algorithm.</span>
382
+ - <span class="package-name">[`@stdlib/stats-base/snanvariancetk`][@stdlib/stats/base/snanvariancetk]</span><span class="delimiter">: </span><span class="description">calculate the variance of a single-precision floating-point strided array ignoring NaN values and using a one-pass textbook algorithm.</span>
383
+ - <span class="package-name">[`@stdlib/stats-strided/sstdevtk`][@stdlib/stats/strided/sstdevtk]</span><span class="delimiter">: </span><span class="description">calculate the standard deviation of a single-precision floating-point strided array using a one-pass textbook algorithm.</span>
384
+ - <span class="package-name">[`@stdlib/stats-strided/svariance`][@stdlib/stats/strided/svariance]</span><span class="delimiter">: </span><span class="description">calculate the variance of a single-precision floating-point strided array.</span>
385
+ - <span class="package-name">[`@stdlib/stats-strided/variancetk`][@stdlib/stats/strided/variancetk]</span><span class="delimiter">: </span><span class="description">calculate the variance of a strided array using a one-pass textbook algorithm.</span>
386
+
387
+ </section>
388
+
389
+ <!-- /.related -->
390
+
391
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
392
+
393
+
394
+ <section class="main-repo" >
395
+
396
+ * * *
397
+
398
+ ## Notice
399
+
400
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
401
+
402
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
403
+
404
+ #### Community
405
+
406
+ [![Chat][chat-image]][chat-url]
407
+
408
+ ---
409
+
410
+ ## License
411
+
412
+ See [LICENSE][stdlib-license].
413
+
414
+
415
+ ## Copyright
416
+
417
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
418
+
419
+ </section>
420
+
421
+ <!-- /.stdlib -->
422
+
423
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
424
+
425
+ <section class="links">
426
+
427
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-strided-svariancetk.svg
428
+ [npm-url]: https://npmjs.org/package/@stdlib/stats-strided-svariancetk
429
+
430
+ [test-image]: https://github.com/stdlib-js/stats-strided-svariancetk/actions/workflows/test.yml/badge.svg?branch=v0.1.0
431
+ [test-url]: https://github.com/stdlib-js/stats-strided-svariancetk/actions/workflows/test.yml?query=branch:v0.1.0
432
+
433
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-strided-svariancetk/main.svg
434
+ [coverage-url]: https://codecov.io/github/stdlib-js/stats-strided-svariancetk?branch=main
435
+
436
+ <!--
437
+
438
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/stats-strided-svariancetk.svg
439
+ [dependencies-url]: https://david-dm.org/stdlib-js/stats-strided-svariancetk/main
440
+
441
+ -->
442
+
443
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
444
+ [chat-url]: https://stdlib.zulipchat.com
445
+
446
+ [stdlib]: https://github.com/stdlib-js/stdlib
447
+
448
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
449
+
450
+ [umd]: https://github.com/umdjs/umd
451
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
452
+
453
+ [deno-url]: https://github.com/stdlib-js/stats-strided-svariancetk/tree/deno
454
+ [deno-readme]: https://github.com/stdlib-js/stats-strided-svariancetk/blob/deno/README.md
455
+ [umd-url]: https://github.com/stdlib-js/stats-strided-svariancetk/tree/umd
456
+ [umd-readme]: https://github.com/stdlib-js/stats-strided-svariancetk/blob/umd/README.md
457
+ [esm-url]: https://github.com/stdlib-js/stats-strided-svariancetk/tree/esm
458
+ [esm-readme]: https://github.com/stdlib-js/stats-strided-svariancetk/blob/esm/README.md
459
+ [branches-url]: https://github.com/stdlib-js/stats-strided-svariancetk/blob/main/branches.md
460
+
461
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/stats-strided-svariancetk/main/LICENSE
462
+
463
+ [variance]: https://en.wikipedia.org/wiki/Variance
464
+
465
+ [@stdlib/array/float32]: https://www.npmjs.com/package/@stdlib/array-float32
466
+
467
+ [mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
468
+
469
+ [@ling:1974a]: https://doi.org/10.2307/2286154
470
+
471
+ <!-- <related-links> -->
472
+
473
+ [@stdlib/stats/strided/dvariancetk]: https://www.npmjs.com/package/@stdlib/stats-strided-dvariancetk
474
+
475
+ [@stdlib/stats/base/snanvariancetk]: https://www.npmjs.com/package/@stdlib/stats-base-snanvariancetk
476
+
477
+ [@stdlib/stats/strided/sstdevtk]: https://www.npmjs.com/package/@stdlib/stats-strided-sstdevtk
478
+
479
+ [@stdlib/stats/strided/svariance]: https://www.npmjs.com/package/@stdlib/stats-strided-svariance
480
+
481
+ [@stdlib/stats/strided/variancetk]: https://www.npmjs.com/package/@stdlib/stats-strided-variancetk
482
+
483
+ <!-- </related-links> -->
484
+
485
+ </section>
486
+
487
+ <!-- /.links -->
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).