Skip to content

Commit 418d3ec

Browse files
committed
refactor: refactor the lib folder's files to align with existing style
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent da0f9d5 commit 418d3ec

File tree

6 files changed

+41
-74
lines changed

6 files changed

+41
-74
lines changed

lib/node_modules/@stdlib/stats/base/nanvariancech/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ var v = nanvariancech.ndarray( 5, 1, x, 2, 1 );
174174
- If `N <= 0`, both functions return `NaN`.
175175
- If `n - c` is less than or equal to `0` (where `c` corresponds to the provided degrees of freedom adjustment and `n` corresponds to the number of non-`NaN` indexed elements), both functions return `NaN`.
176176
- The underlying algorithm is a specialized case of Neely's two-pass algorithm. As the variance is invariant with respect to changes in the location parameter, the underlying algorithm uses the first non-`NaN` strided array element as a trial mean to shift subsequent data values and thus mitigate catastrophic cancellation. Accordingly, the algorithm's accuracy is best when data is **unordered** (i.e., the data is **not** sorted in either ascending or descending order such that the first value is an "extreme" value).
177-
- 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]).
178177
- Depending on the environment, the typed versions ([`dnanvariancech`][@stdlib/stats/strided/dnanvariancech], [`snanvariancech`][@stdlib/stats/base/snanvariancech], etc.) are likely to be significantly more performant.
179178

180179
</section>
@@ -274,8 +273,6 @@ console.log( v );
274273

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

277-
[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
278-
279276
<!-- </related-links> -->
280277

281278
</section>

lib/node_modules/@stdlib/stats/base/nanvariancech/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var filledarrayBy = require( '@stdlib/array/filled-by' );
2727
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2828
var pow = require( '@stdlib/math/base/special/pow' );
2929
var pkg = require( './../package.json' ).name;
30-
var nanvariancech = require( './../lib/nanvariancech.js' );
30+
var nanvariancech = require( './../lib/main.js' );
3131

3232

3333
// FUNCTIONS //

lib/node_modules/@stdlib/stats/base/nanvariancech/lib/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,28 @@
2828
*
2929
* var x = [ 1.0, -2.0, NaN, 2.0 ];
3030
*
31-
* var v = nanvariancech( x.length, 1, x, 1 );
31+
* var v = nanvariancech( 4, 1, x, 1 );
3232
* // returns ~4.3333
3333
*
3434
* @example
35-
* var floor = require( '@stdlib/math/base/special/floor' );
3635
* var nanvariancech = require( '@stdlib/stats/base/nanvariancech' );
3736
*
3837
* var x = [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0, NaN, NaN ];
39-
* var N = floor( x.length / 2 );
4038
*
41-
* var v = nanvariancech.ndarray( N, 1, x, 2, 1 );
39+
* var v = nanvariancech.ndarray( 5, 1, x, 2, 1 );
4240
* // returns 6.25
4341
*/
4442

4543
// MODULES //
4644

45+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
4746
var main = require( './main.js' );
47+
var ndarray = require( './ndarray.js' );
48+
49+
50+
// MAIN //
51+
52+
setReadOnly( main, 'ndarray', ndarray );
4853

4954

5055
// EXPORTS //

lib/node_modules/@stdlib/stats/base/nanvariancech/lib/main.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,41 @@
2020

2121
// MODULES //
2222

23-
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24-
var nanvariancech = require( './nanvariancech.js' );
23+
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
2524
var ndarray = require( './ndarray.js' );
2625

2726

2827
// MAIN //
2928

30-
setReadOnly( nanvariancech, 'ndarray', ndarray );
29+
/**
30+
* Computes the variance of a strided array ignoring `NaN` values and using a one-pass trial mean algorithm.
31+
*
32+
* ## Method
33+
*
34+
* - This implementation uses a one-pass trial mean approach, as suggested by Chan et al (1983).
35+
*
36+
* ## References
37+
*
38+
* - Neely, Peter M. 1966. "Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients." _Communications of the ACM_ 9 (7). Association for Computing Machinery: 496–99. doi:[10.1145/365719.365958](https://doi.org/10.1145/365719.365958).
39+
* - Ling, Robert F. 1974. "Comparison of Several Algorithms for Computing Sample Means and Variances." _Journal of the American Statistical Association_ 69 (348). American Statistical Association, Taylor & Francis, Ltd.: 859–66. doi:[10.2307/2286154](https://doi.org/10.2307/2286154).
40+
* - Chan, Tony F., Gene H. Golub, and Randall J. LeVeque. 1983. "Algorithms for Computing the Sample Variance: Analysis and Recommendations." _The American Statistician_ 37 (3). American Statistical Association, Taylor & Francis, Ltd.: 242–47. doi:[10.1080/00031305.1983.10483115](https://doi.org/10.1080/00031305.1983.10483115).
41+
* - Schubert, Erich, and Michael Gertz. 2018. "Numerically Stable Parallel Computation of (Co-)Variance." In _Proceedings of the 30th International Conference on Scientific and Statistical Database Management_. New York, NY, USA: Association for Computing Machinery. doi:[10.1145/3221269.3223036](https://doi.org/10.1145/3221269.3223036).
42+
*
43+
* @param {PositiveInteger} N - number of indexed elements
44+
* @param {number} correction - degrees of freedom adjustment
45+
* @param {NumericArray} x - input array
46+
* @param {integer} strideX - stride length
47+
* @returns {number} variance
48+
*
49+
* @example
50+
* var x = [ 1.0, -2.0, NaN, 2.0 ];
51+
*
52+
* var v = nanvariancech( 4, 1, x, 1 );
53+
* // returns ~4.3333
54+
*/
55+
function nanvariancech( N, correction, x, strideX ) {
56+
return ndarray( N, correction, x, strideX, stride2offset( N, strideX) );
57+
}
3158

3259

3360
// EXPORTS //

lib/node_modules/@stdlib/stats/base/nanvariancech/lib/nanvariancech.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

lib/node_modules/@stdlib/stats/base/nanvariancech/test/test.nanvariancech.js renamed to lib/node_modules/@stdlib/stats/base/nanvariancech/test/test.main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var Float64Array = require( '@stdlib/array/float64' );
2626
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
27-
var nanvariancech = require( './../lib/nanvariancech.js' );
27+
var nanvariancech = require( './../lib/main.js' );
2828

2929

3030
// TESTS //

0 commit comments

Comments
 (0)