-
-
Notifications
You must be signed in to change notification settings - Fork 906
feat: add accessor protocol support and refactor stats/base/nanvariancech
#6048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note, | |||||
var nanvariancech = require( '@stdlib/stats/base/nanvariancech' ); | ||||||
``` | ||||||
|
||||||
#### nanvariancech( N, correction, x, stride ) | ||||||
#### nanvariancech( N, correction, x, strideX ) | ||||||
|
||||||
Computes the [variance][variance] of a strided array `x` ignoring `NaN` values and using a one-pass trial mean algorithm. | ||||||
|
||||||
|
@@ -114,17 +114,14 @@ The function has the following parameters: | |||||
- **N**: number of indexed elements. | ||||||
- **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). | ||||||
- **x**: input [`Array`][mdn-array] or [`typed array`][mdn-typed-array]. | ||||||
- **stride**: index increment for `x`. | ||||||
- **strideX**: stride length for `x`. | ||||||
|
||||||
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`, | ||||||
The `N` and stride parameters determine which elements in the stided array are accessed at runtime. For example, to compute the [variance][variance] of every other element in `x`, | ||||||
|
||||||
```javascript | ||||||
var floor = require( '@stdlib/math/base/special/floor' ); | ||||||
|
||||||
var x = [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0, NaN ]; | ||||||
var N = floor( x.length / 2 ); | ||||||
|
||||||
var v = nanvariancech( N, 1, x, 2 ); | ||||||
var v = nanvariancech( 4, 1, x, 2 ); | ||||||
// returns 6.25 | ||||||
``` | ||||||
|
||||||
|
@@ -134,41 +131,35 @@ Note that indexing is relative to the first index. To introduce an offset, use [ | |||||
|
||||||
```javascript | ||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||
var floor = require( '@stdlib/math/base/special/floor' ); | ||||||
|
||||||
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN ] ); | ||||||
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||||||
|
||||||
var N = floor( x0.length / 2 ); | ||||||
|
||||||
var v = nanvariancech( N, 1, x1, 2 ); | ||||||
var v = nanvariancech( 4, 1, x1, 2 ); | ||||||
// returns 6.25 | ||||||
``` | ||||||
|
||||||
#### nanvariancech.ndarray( N, correction, x, stride, offset ) | ||||||
#### nanvariancech.ndarray( N, correction, x, strideX, offsetX ) | ||||||
|
||||||
Computes the [variance][variance] of a strided array ignoring `NaN` values and using a one-pass trial mean algorithm and alternative indexing semantics. | ||||||
|
||||||
```javascript | ||||||
var x = [ 1.0, -2.0, NaN, 2.0 ]; | ||||||
|
||||||
var v = nanvariancech.ndarray( x.length, 1, x, 1, 0 ); | ||||||
var v = nanvariancech.ndarray( 4, 1, x, 1, 0 ); | ||||||
// returns ~4.33333 | ||||||
``` | ||||||
|
||||||
The function has the following additional parameters: | ||||||
|
||||||
- **offset**: starting index for `x`. | ||||||
- **offsetX**: starting index for `x`. | ||||||
|
||||||
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 | ||||||
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 the strided array starting from the second element | ||||||
|
||||||
```javascript | ||||||
var floor = require( '@stdlib/math/base/special/floor' ); | ||||||
|
||||||
var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ]; | ||||||
var N = floor( x.length / 2 ); | ||||||
|
||||||
var v = nanvariancech.ndarray( N, 1, x, 2, 1 ); | ||||||
var v = nanvariancech.ndarray( 4, 1, x, 2, 1 ); | ||||||
|
var v = nanvariancech.ndarray( 4, 1, x, 2, 1 ); | |
var v = nanvariancech.ndarray( 5, 1, x, 2, 1 ); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments as examples/index.js
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kindly use this as a reference There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments for your other benchmark file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should explicitly show how we're handling the
NaN
element