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
@@ -147,18 +146,16 @@ The function has the following parameters:
147
146
-**N**: number of indexed elements.
148
147
-**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).
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`,
151
+
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
175
171
176
-
varN=floor( x0.length/2 );
177
-
178
-
var v =dvariancetk( N, 1, x1, 2 );
172
+
var v =dvariancetk( 4, 1, x1, 2 );
179
173
// returns 6.25
180
174
```
181
175
182
-
#### dvariancetk.ndarray( N, correction, x, stride, offset )
176
+
#### dvariancetk.ndarray( N, correction, x, strideX, offsetX )
183
177
184
178
Computes the [variance][variance] of a double-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics.
var v =dvariancetk.ndarray( x.length, 1, x, 1, 0 );
193
186
// returns ~4.33333
194
187
```
195
188
196
189
The function has the following additional parameters:
197
190
198
-
-**offset**: starting index for `x`.
191
+
-**offsetX**: starting index for `x`.
199
192
200
-
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
193
+
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 the strided array starting from the second value
var discreteUniform =require( '@stdlib/random/array/discrete-uniform' );
239
228
var dvariancetk =require( '@stdlib/stats/base/dvariancetk' );
240
229
241
-
var x;
242
-
var i;
243
-
244
-
x =newFloat64Array( 10 );
245
-
for ( i =0; i <x.length; i++ ) {
246
-
x[ i ] =round( (randu()*100.0) -50.0 );
247
-
}
230
+
var x =discreteUniform( 10, -50, 50, {
231
+
'dtype':'float64'
232
+
});
248
233
console.log( x );
249
234
250
235
var v =dvariancetk( x.length, 1, x, 1 );
@@ -255,6 +240,125 @@ console.log( v );
255
240
256
241
<!-- /.examples -->
257
242
243
+
<!-- C interface documentation. -->
244
+
245
+
* * *
246
+
247
+
<sectionclass="c">
248
+
249
+
## C APIs
250
+
251
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
252
+
253
+
<sectionclass="intro">
254
+
255
+
</section>
256
+
257
+
<!-- /.intro -->
258
+
259
+
<!-- C usage documentation. -->
260
+
261
+
<sectionclass="usage">
262
+
263
+
### Usage
264
+
265
+
```c
266
+
#include"stdlib/stats/base/dvariancetk.h"
267
+
```
268
+
269
+
#### stdlib_strided_dvariancetk( N, correction, \*X, strideX )
270
+
271
+
Computes the [variance][variance] of a double-precision floating-point strided array using a one-pass textbook algorithm.
272
+
273
+
```c
274
+
constdouble x[] = { 1.0, -2.0, 2.0 };
275
+
276
+
double v = stdlib_strided_dvariancetk( 3, 1.0, x, 1 );
277
+
// returns ~4.3333
278
+
```
279
+
280
+
The function accepts the following arguments:
281
+
282
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
283
+
- **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. 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).
284
+
- **X**: `[in] double*` input array.
285
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
#### stdlib_strided_dvariancetk_ndarray( N, correction, \*X, strideX, offsetX )
292
+
293
+
Computes the [variance][variance] of a double-precision floating-point strided array using a one-pass textbook algorithm and alternative indexing semantics.
294
+
295
+
```c
296
+
constdouble x[] = { 1.0, -2.0, 2.0 };
297
+
298
+
double v = stdlib_strided_dvariancetk_ndarray( 3, 1.0, x, 1, 0 );
299
+
// returns ~4.3333
300
+
```
301
+
302
+
The function accepts the following arguments:
303
+
304
+
- **N**: `[in] CBLAS_INT` number of indexed elements.
305
+
- **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. 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).
306
+
- **X**: `[in] double*` input array.
307
+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
308
+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
0 commit comments