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
@@ -116,41 +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`,
@@ -163,18 +160,18 @@ var v = dnanvariance.ndarray( x.length, 1, x, 1, 0 );
163
160
164
161
The function has the following additional parameters:
165
162
166
-
-**offset**: starting index for `x`.
163
+
-**offsetX**: starting index for `x`.
167
164
168
165
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 dnanvariance =require( '@stdlib/stats/base/dnanvariance' );
207
204
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 );
205
+
functionrand() {
206
+
if ( bernoulli( 0.8 ) <1 ) {
207
+
returnNaN;
208
+
}
209
+
returnuniform( -50.0, 50.0 );
214
210
}
211
+
212
+
var x =filledarrayBy( 10, 'float64', rand );
215
213
console.log( x );
216
214
217
215
var v =dnanvariance( x.length, 1, x, 1 );
@@ -222,6 +220,125 @@ console.log( v );
222
220
223
221
<!-- /.examples -->
224
222
223
+
<!-- C interface documentation. -->
224
+
225
+
* * *
226
+
227
+
<sectionclass="c">
228
+
229
+
## C APIs
230
+
231
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
232
+
233
+
<sectionclass="intro">
234
+
235
+
</section>
236
+
237
+
<!-- /.intro -->
238
+
239
+
<!-- C usage documentation. -->
240
+
241
+
<sectionclass="usage">
242
+
243
+
### Usage
244
+
245
+
```c
246
+
#include"stdlib/stats/base/dnanvariance.h"
247
+
```
248
+
249
+
#### stdlib_strided_dnanvariance( N, correction, \*X, strideX )
250
+
251
+
Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values.
252
+
253
+
```c
254
+
constdouble x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };
255
+
256
+
double v = stdlib_strided_dnanvariance( 4, 1.0, x, 1 );
257
+
// returns ~4.3333
258
+
```
259
+
260
+
The function accepts the following arguments:
261
+
262
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
263
+
- **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).
264
+
- **X**: `[in] double*` input array.
265
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
#### stdlib_strided_dnanvariance_ndarray( N, correction, \*X, strideX, offsetX )
272
+
273
+
Computes the [variance][variance] of a double-precision floating-point strided array, ignoring `NaN` values and alternative indexing semantics.
274
+
275
+
```c
276
+
constdouble x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };
277
+
278
+
double v = stdlib_strided_dnanvariance_ndarray( 4, 1.0, x, 1, 0 );
279
+
// returns ~4.3333
280
+
```
281
+
282
+
The function accepts the following arguments:
283
+
284
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
285
+
- **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).
286
+
- **X**: `[in] double*` input array.
287
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
288
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
0 commit comments