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,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 =dnanvariancepn( N, 1, x1, 2 );
142
+
var v =dnanvariancepn( 5, 1, x1, 2 );
148
143
// returns 6.25
149
144
```
150
145
151
-
#### dnanvariancepn.ndarray( N, correction, x, stride, offset )
146
+
#### dnanvariancepn.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 two-pass algorithm and alternative indexing semantics.
154
149
@@ -163,18 +158,16 @@ var v = dnanvariancepn.ndarray( x.length, 1, x, 1, 0 );
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 dnanvariancepn =require( '@stdlib/stats/base/dnanvariancepn' );
207
200
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 );
201
+
functionrand() {
202
+
if ( bernoulli( 0.8 ) <1 ) {
203
+
returnNaN;
204
+
}
205
+
returnuniform( -50.0, 50.0 );
214
206
}
207
+
208
+
var x =filledarrayBy( 10, 'float64', rand );
215
209
console.log( x );
216
210
217
211
var v =dnanvariancepn( x.length, 1, x, 1 );
@@ -222,6 +216,125 @@ console.log( v );
222
216
223
217
<!-- /.examples -->
224
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/dnanvariancepn.h"
243
+
```
244
+
245
+
#### stdlib_strided_dnanvariancepn( N, correction, \*X, strideX )
246
+
247
+
Computes the [variance][variance] of a double-precision floating-point strided array ignoring `NaN` values and using a two-pass algorithm.
248
+
249
+
```c
250
+
constdouble x[] = { 1.0, -2.0, 0.0/0.0, 2.0 };
251
+
252
+
double v = stdlib_strided_dnanvariancepn( 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_dnanvariancepn_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 two-pass 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_dnanvariancepn_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