You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note,
98
98
var dnanvariancewd =require( '@stdlib/stats/base/dnanvariancewd' );
99
99
```
100
100
101
-
#### dnanvariancewd( N, correction, x, stride )
101
+
#### dnanvariancewd( N, correction, x, strideX )
102
102
103
103
Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values and using Welford's algorithm.
104
104
@@ -116,39 +116,38 @@ The function has the following parameters:
116
116
-**N**: number of indexed elements.
117
117
-**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 and `n` corresponds to the number of non-`NaN` indexed elements. 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).
The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`,
121
+
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`,
var floor =require( '@stdlib/math/base/special/floor' );
141
142
142
-
var x0 =newFloat64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] );
143
+
var x0 =newFloat64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ] );
143
144
var x1 =newFloat64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
144
145
145
-
varN=floor( x0.length/2 );
146
-
147
-
var v =dnanvariancewd( N, 1, x1, 2 );
146
+
var v =dnanvariancewd( 5, 1, x1, 2 );
148
147
// returns 6.25
149
148
```
150
149
151
-
#### dnanvariancewd.ndarray( N, correction, x, stride, offset )
150
+
#### dnanvariancewd.ndarray( N, correction, x, strideX, offsetX )
152
151
153
152
Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics.
154
153
@@ -163,18 +162,19 @@ var v = dnanvariancewd.ndarray( x.length, 1, x, 1, 0 );
163
162
164
163
The function has the following additional parameters:
165
164
166
-
-**offset**: starting index for `x`.
165
+
-**offset**: starting index for `X`.
166
+
167
+
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
167
168
168
-
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 value in `x` starting from the second value
var dnanvariancewd =require( '@stdlib/stats/base/dnanvariancewd' );
207
207
208
-
var x;
209
-
var i;
210
-
211
-
x =newFloat64Array( 10 );
212
-
for ( i =0; i <x.length; i++ ) {
213
-
x[ i ] =round( (randu()*100.0) -50.0 );
208
+
functionrand() {
209
+
if ( bernoulli( 0.8 ) <1 ) {
210
+
returnNaN;
211
+
}
212
+
returnuniform( -50.0, 50.0 );
214
213
}
214
+
215
+
var x =filledarrayBy( 10, 'float64', rand );
215
216
console.log( x );
216
217
217
218
var v =dnanvariancewd( x.length, 1, x, 1 );
@@ -222,6 +223,125 @@ console.log( v );
222
223
223
224
<!-- /.examples -->
224
225
226
+
<!-- C interface documentation. -->
227
+
228
+
* * *
229
+
230
+
<sectionclass="c">
231
+
232
+
## C APIs
233
+
234
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
235
+
236
+
<sectionclass="intro">
237
+
238
+
</section>
239
+
240
+
<!-- /.intro -->
241
+
242
+
<!-- C usage documentation. -->
243
+
244
+
<sectionclass="usage">
245
+
246
+
### Usage
247
+
248
+
```c
249
+
#include"stdlib/stats/base/dnanvariancewd.h"
250
+
```
251
+
252
+
#### stdlib_strided_dnanvariancewd( N, correction, \*X, strideX )
253
+
254
+
Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm.
255
+
256
+
```c
257
+
constdouble x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };
258
+
259
+
double v = stdlib_strided_dnanvariancewd( 4, 1.0, x, 1 );
260
+
// returns ~4.3333
261
+
```
262
+
263
+
The function accepts the following arguments:
264
+
265
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
266
+
- **correction**: `[in] double` 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 and `n` corresponds to the number of non-`NaN` indexed elements. 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).
267
+
- **X**: `[in] double*` input array.
268
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
#### stdlib_strided_dnanvariancewd_ndarray( N, correction, \*X, strideX, offsetX )
275
+
276
+
Computes the variance of a double-precision floating-point strided array ignoring `NaN` values and using Welford's algorithm and alternative indexing semantics.
277
+
278
+
```c
279
+
constdouble x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };
280
+
281
+
double v = stdlib_strided_dnanvariancewd_ndarray( 4, 1.0, x, 1, 0 );
282
+
// returns ~4.3333
283
+
```
284
+
285
+
The function accepts the following arguments:
286
+
287
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
288
+
- **correction**: `[in] double` 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 and `n` corresponds to the number of non-`NaN` indexed elements. 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).
289
+
- **X**: `[in] double*` input array.
290
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
291
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
0 commit comments