Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3437c9c
feat: add protocol support to stats/base/varianceyc
pulkitgupta2 Mar 8, 2025
eaf388a
fixup! feat: add protocol support to stats/base/varianceyc
pulkitgupta2 Mar 8, 2025
37729ad
fixup! fixup! feat: add protocol support to stats/base/varianceyc
pulkitgupta2 Mar 8, 2025
78f64b4
fixup! fixup! fixup! feat: add protocol support to stats/base/varianceyc
pulkitgupta2 Mar 8, 2025
0921de1
fixup! fixup! fixup! fixup! feat: add protocol support to stats/base/…
pulkitgupta2 Mar 8, 2025
2ed48eb
Update lib/node_modules/@stdlib/stats/base/varianceyc/README.md
pulkitgupta2 Mar 20, 2025
26bf6f1
Update lib/node_modules/@stdlib/stats/base/varianceyc/README.md
pulkitgupta2 Mar 20, 2025
833cd76
Update lib/node_modules/@stdlib/stats/base/varianceyc/docs/types/inde…
pulkitgupta2 Mar 20, 2025
f36aff0
Update lib/node_modules/@stdlib/stats/base/varianceyc/README.md
pulkitgupta2 Mar 20, 2025
8e04ff4
Update lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js
pulkitgupta2 Mar 20, 2025
37d4cbd
Update lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarr…
pulkitgupta2 Mar 20, 2025
91bfbdd
Update lib/node_modules/@stdlib/stats/base/varianceyc/test/test.ndarr…
pulkitgupta2 Mar 20, 2025
cf80425
fixup! refactor: updated docs
pulkitgupta2 Mar 23, 2025
d55df5e
fixup! refactor: updated accessor implemntation to avoid duplication
pulkitgupta2 Mar 23, 2025
0a9267d
Merge branch 'develop' into refactor-varianceyc
pulkitgupta2 Mar 31, 2025
81fc3ba
refac: formatting changes
pulkitgupta2 Mar 31, 2025
e61999a
refac: formatting changes
pulkitgupta2 Mar 31, 2025
6153de3
chore: clean-up
kgryte Apr 10, 2025
dac9595
chore: update copyright years
stdlib-bot Apr 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions lib/node_modules/@stdlib/stats/base/varianceyc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ The use of the term `n-1` is commonly referred to as Bessel's correction. Note,
var varianceyc = require( '@stdlib/stats/base/varianceyc' );
```

#### varianceyc( N, correction, x, stride )
#### varianceyc( N, correction, x, strideX )

Computes the [variance][variance] of a strided array `x` using a one-pass algorithm proposed by Youngs and Cramer.

Expand All @@ -114,17 +114,16 @@ 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. 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 strided 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 ];
var N = floor( x.length / 2 );

var v = varianceyc( N, 1, x, 2 );
var v = varianceyc( 4, 1, x, 2 );
// returns 6.25
```

Expand All @@ -139,13 +138,11 @@ 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 ] );
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var N = floor( x0.length / 2 );

var v = varianceyc( N, 1, x1, 2 );
var v = varianceyc( 4, 1, x1, 2 );
// returns 6.25
```

#### varianceyc.ndarray( N, correction, x, stride, offset )
#### varianceyc.ndarray( N, correction, x, strideX, offsetX )

Computes the [variance][variance] of a strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics.

Expand All @@ -158,17 +155,14 @@ var v = varianceyc.ndarray( x.length, 1, x, 1, 0 );

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 value in `x` starting from the second value

```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 = varianceyc.ndarray( N, 1, x, 2, 1 );
var v = varianceyc.ndarray( 4, 1, x, 2, 1 );
// returns 6.25
```

Expand All @@ -183,6 +177,7 @@ var v = varianceyc.ndarray( N, 1, x, 2, 1 );
- If `N <= 0`, both functions return `NaN`.
- If `N - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment), both functions return `NaN`.
- Depending on the environment, the typed versions ([`dvarianceyc`][@stdlib/stats/base/dvarianceyc], [`svarianceyc`][@stdlib/stats/base/svarianceyc], etc.) are likely to be significantly more performant.
- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).

</section>

Expand All @@ -195,18 +190,13 @@ var v = varianceyc.ndarray( N, 1, x, 2, 1 );
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var uniform = require( '@stdlib/random/array/uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var varianceyc = require( '@stdlib/stats/base/varianceyc' );

var x;
var i;

x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( (randu()*100.0) - 50.0 );
}
var x = uniform( 10, -50.0, 50.0, {
'dtype': 'float64'
});
console.log( x );

var v = varianceyc( x.length, 1, x, 1 );
Expand Down Expand Up @@ -256,6 +246,8 @@ console.log( v );

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor

[@stdlib/stats/base/svarianceyc]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/base/svarianceyc

[@youngs:1971a]: https://doi.org/10.1080/00401706.1971.10488826
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var uniform = require( '@stdlib/random/array/uniform' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var varianceyc = require( './../lib/varianceyc.js' );


// VARIABLES //

var options = {
'dtype': 'generic'
};


// FUNCTIONS //

/**
Expand All @@ -38,13 +45,7 @@ var varianceyc = require( './../lib/varianceyc.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = [];
for ( i = 0; i < len; i++ ) {
x.push( ( randu()*20.0 ) - 10.0 );
}
var x = uniform( len, -10.0, 10.0, options );
return benchmark;

function benchmark( b ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
var varianceyc = require( './../lib/ndarray.js' );


// VARIABLES //

var options = {
'dtype': 'generic'
};


// FUNCTIONS //

/**
Expand All @@ -38,13 +45,7 @@ var varianceyc = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var i;

x = [];
for ( i = 0; i < len; i++ ) {
x.push( ( randu()*20.0 ) - 10.0 );
}
var x = uniform( len, -10.0, 10.0, options );
return benchmark;

function benchmark( b ) {
Expand Down
34 changes: 15 additions & 19 deletions lib/node_modules/@stdlib/stats/base/varianceyc/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

{{alias}}( N, correction, x, stride )
{{alias}}( N, correction, x, strideX )
Computes the variance of a strided array using a one-pass algorithm proposed
by Youngs and Cramer.

The `N` and `stride` parameters determine which elements in `x` are accessed
at runtime.
The `N` and stride parameters determine which elements in the strided array
are accessed at runtime.

Indexing is relative to the first index. To introduce an offset, use a typed
array view.
Expand All @@ -31,8 +31,8 @@
x: Array<number>|TypedArray
Input array.

stride: integer
Index increment.
strideX: integer
Stride length.

Returns
-------
Expand All @@ -46,27 +46,24 @@
> {{alias}}( x.length, 1, x, 1 )
~4.3333

// Using `N` and `stride` parameters:
// Using `N` and stride parameters:
> x = [ -2.0, 1.0, 1.0, -5.0, 2.0, -1.0 ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> var stride = 2;
> {{alias}}( N, 1, x, stride )
> {{alias}}( 3, 1, x, 2 )
~4.3333

// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ] );
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
> N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
> stride = 2;
> {{alias}}( N, 1, x1, stride )
> {{alias}}( 3, 1, x1, 2 )
~4.3333

{{alias}}.ndarray( N, correction, x, stride, offset )

{{alias}}.ndarray( N, correction, x, strideX, offsetX )
Computes the variance of a strided array using a one-pass algorithm proposed
by Youngs and Cramer and alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
buffer, the `offset` parameter supports indexing semantics based on a
buffer, the offset parameter supports indexing semantics based on a
starting index.

Parameters
Expand All @@ -89,10 +86,10 @@
x: Array<number>|TypedArray
Input array.

stride: integer
Index increment.
strideX: integer
Stride length.

offset: integer
offsetX: integer
Starting index.

Returns
Expand All @@ -109,8 +106,7 @@

// Using offset parameter:
> var x = [ 1.0, -2.0, 3.0, 2.0, 5.0, -1.0 ];
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> {{alias}}.ndarray( N, 1, x, 2, 1 )
> {{alias}}.ndarray( 3, 1, x, 2, 1 )
~4.3333

See Also
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@

/// <reference types="@stdlib/types"/>

import { NumericArray } from '@stdlib/types/array';
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';


/**
* Input array.
*/
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;


/**
* Interface describing `varianceyc`.
Expand All @@ -32,7 +39,7 @@ interface Routine {
* @param N - number of indexed elements
* @param correction - degrees of freedom adjustment
* @param x - input array
* @param stride - stride length
* @param strideX - stride length for `x`
* @returns variance
*
* @example
Expand All @@ -41,16 +48,16 @@ interface Routine {
* var v = varianceyc( x.length, 1, x, 1 );
* // returns ~4.3333
*/
( N: number, correction: number, x: NumericArray, stride: number ): number;
( N: number, correction: number, x: InputArray, stride: number ): number;

/**
* Computes the variance of a strided array using a one-pass algorithm proposed by Youngs and Cramer and alternative indexing semantics.
*
* @param N - number of indexed elements
* @param correction - degrees of freedom adjustment
* @param x - input array
* @param stride - stride length
* @param offset - starting index
* @param strideX - stride length for `x`
* @param offsetX - starting index
* @returns variance
*
* @example
Expand All @@ -59,7 +66,7 @@ interface Routine {
* var v = varianceyc.ndarray( x.length, 1, x, 1, 0 );
* // returns ~4.3333
*/
ndarray( N: number, correction: number, x: NumericArray, stride: number, offset: number ): number;
ndarray( N: number, correction: number, x: InputArray, stride: number, offset: number ): number;
}

/**
Expand All @@ -68,7 +75,7 @@ interface Routine {
* @param N - number of indexed elements
* @param correction - degrees of freedom adjustment
* @param x - input array
* @param stride - stride length
* @param strideX - stride length
* @returns variance
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

import AccessorArray = require( '@stdlib/array/base/accessor' );
import varianceyc = require( './index' );


Expand All @@ -26,6 +27,7 @@ import varianceyc = require( './index' );
const x = new Float64Array( 10 );

varianceyc( x.length, 1, x, 1 ); // $ExpectType number
varianceyc( x.length, 1, new AccessorArray( x ), 1 ); // $ExpectType number
}

// The compiler throws an error if the function is provided a first argument which is not a number...
Expand Down Expand Up @@ -101,6 +103,7 @@ import varianceyc = require( './index' );
const x = new Float64Array( 10 );

varianceyc.ndarray( x.length, 1, x, 1, 0 ); // $ExpectType number
varianceyc.ndarray( x.length, 1, new AccessorArray( x ), 1, 0 ); // $ExpectType number
}

// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...
Expand Down
14 changes: 4 additions & 10 deletions lib/node_modules/@stdlib/stats/base/varianceyc/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@

'use strict';

var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/array/uniform' );
var varianceyc = require( './../lib' );

var x;
var i;

x = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( (randu()*100.0) - 50.0 );
}
var x = uniform( 10, -50.0, 50.0, {
'dtype': 'float64'
});
console.log( x );

var v = varianceyc( x.length, 1, x, 1 );
Expand Down
Loading