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 dnanvariancech =require( '@stdlib/stats/base/dnanvariancech' );
99
99
```
100
100
101
-
#### dnanvariancech( N, correction, x, stride )
101
+
#### dnanvariancech( 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 a one-pass trial mean algorithm.
104
104
@@ -116,18 +116,16 @@ 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 x1 =newFloat64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
144
141
145
-
varN=floor( x0.length/2 );
146
-
147
-
var v =dnanvariancech( N, 1, x1, 2 );
142
+
var v =dnanvariancech( 5, 1, x1, 2 );
148
143
// returns 6.25
149
144
```
150
145
151
-
#### dnanvariancech.ndarray( N, correction, x, stride, offset )
146
+
#### dnanvariancech.ndarray( N, correction, x, strideX, offsetX )
152
147
153
148
Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using a one-pass trial mean algorithm and alternative indexing semantics.
var x =newFloat64Array( [ 1.0, -2.0, NaN, 2.0 ] );
153
+
var x =newFloat64Array( [ 1.0, -2.0, 2.0 ] );
159
154
160
155
var v =dnanvariancech.ndarray( x.length, 1, x, 1, 0 );
161
156
// returns ~4.33333
162
157
```
163
158
164
159
The function has the following additional parameters:
165
160
166
-
-**offset**: starting index for `x`.
161
+
-**offsetX**: starting index for `x`.
167
162
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
163
+
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
var dnanvariancech =require( '@stdlib/stats/base/dnanvariancech' );
208
201
209
-
var x;
210
-
var i;
211
-
212
-
x =newFloat64Array( 10 );
213
-
for ( i =0; i <x.length; i++ ) {
214
-
x[ i ] =round( (randu()*100.0) -50.0 );
202
+
functionrand() {
203
+
if ( bernoulli( 0.8 ) <1 ) {
204
+
returnNaN;
205
+
}
206
+
returnuniform( -50.0, 50.0 );
215
207
}
216
-
console.log( x );
208
+
209
+
var x =filledarrayBy( 10, 'float64', rand );
217
210
218
211
var v =dnanvariancech( x.length, 1, x, 1 );
219
212
console.log( v );
@@ -223,6 +216,125 @@ console.log( v );
223
216
224
217
<!-- /.examples -->
225
218
219
+
<!-- C interface documentation. -->
220
+
221
+
* * *
222
+
223
+
<sectionclass="c">
224
+
225
+
## C APIs
226
+
227
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
228
+
229
+
<sectionclass="intro">
230
+
231
+
</section>
232
+
233
+
<!-- /.intro -->
234
+
235
+
<!-- C usage documentation. -->
236
+
237
+
<sectionclass="usage">
238
+
239
+
### Usage
240
+
241
+
```c
242
+
#include"stdlib/stats/base/dnanvariancech.h"
243
+
```
244
+
245
+
#### stdlib_strided_dnanvariancech( N, correction, \*X, strideX )
246
+
247
+
Computes the [variance][variance] of a double-precision floating-point strided array `x` ignoring `NaN` values and using a one-pass trial mean algorithm.
248
+
249
+
```c
250
+
constdouble x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };
251
+
252
+
double v = stdlib_strided_dnanvariancech( 4, 1.0, x, 1 );
253
+
// returns ~4.3333
254
+
```
255
+
256
+
The function accepts the following arguments:
257
+
258
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
259
+
- **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).
260
+
- **X**: `[in] double*` input array.
261
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
#### stdlib_strided_dnanvariancech_ndarray( N, correction, \*X, strideX, offsetX )
268
+
269
+
Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using a one-pass trial mean algorithm and alternative indexing semantics.
270
+
271
+
```c
272
+
constdouble x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };
273
+
274
+
double v = stdlib_strided_dnanvariancech_ndarray( 4, 1.0, x, 1, 0 );
275
+
// returns ~4.3333
276
+
```
277
+
278
+
The function accepts the following arguments:
279
+
280
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
281
+
- **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).
282
+
- **X**: `[in] double*` input array.
283
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
284
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
0 commit comments