diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/index.js new file mode 100644 index 000000000000..9d378cc16bf6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/index.js @@ -0,0 +1,25 @@ +'use strict'; + +/** +* Half-normal distribution expected value. +* +* @module @stdlib/stats/base/dists/halfnormal/mean +* +* @example +* var mean = require( '@stdlib/stats/base/dists/halfnormal/mean' ); +* +* var v = mean( 1.0 ); +* // returns ~0.798 +* +* var v = mean( 2.0 ); +* // returns ~1.596 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/main.js new file mode 100644 index 000000000000..688f7b074ede --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/lib/main.js @@ -0,0 +1,45 @@ +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var PI = require( '@stdlib/constants/float64/pi' ); + + +// VARIABLES // + +var SQRT_TWO_OVER_PI = sqrt( 2.0 / PI ); + + +// MAIN // + +/** +* Returns the expected value of a half-normal distribution. +* +* @param {number} sigma - scale parameter +* @returns {number} expected value +* +* @example +* var v = mean( 1.0 ); +* // returns ~0.798 +* +* @example +* var v = mean( 2.0 ); +* // returns ~1.596 +* +* @example +* var v = mean( -1.0 ); +* // returns NaN +*/ +function mean( sigma ) { + if ( isnan( sigma ) || sigma <= 0.0 ) { + return NaN; + } + return sigma * SQRT_TWO_OVER_PI; +} + + +// EXPORTS // + +module.exports = mean; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/package.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/package.json new file mode 100644 index 000000000000..c88122ce8d48 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/package.json @@ -0,0 +1,76 @@ +{ + "name": "@stdlib/stats-base-dists-halfnormal-mean", + "version": "0.0.0", + "description": "Half-normal distribution expected value.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "lib": "./lib", + "doc": "./docs", + "test": "./test", + "benchmark": "./benchmark" + }, + "types": "./docs/types", + "scripts": { + "test": "make test", + "test-cov": "make test-cov", + "test-browsers": "make test-browsers" + }, + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": { + "@stdlib/constants/float64/pi": "^0.2.2", + "@stdlib/math/base/assert/is-nan": "^0.2.2", + "@stdlib/math/base/special/sqrt": "^0.2.2" + }, + "devDependencies": { + "@stdlib/math/base/special/abs": "^0.2.2", + "tape": "git+https://github.com/kgryte/tape.git#fix/globby", + "istanbul": "^0.4.1", + "tap-min": "git+https://github.com/Planeshifter/tap-min.git", + "@stdlib/bench/harness": "^0.2.2" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "half-normal", + "halfnormal", + "mean", + "expected value", + "expectation" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/test/test.js new file mode 100644 index 000000000000..f680dc43fb26 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/mean/test/test.js @@ -0,0 +1,67 @@ +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var mean = require( './../lib' ); + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.equal( typeof mean, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for `sigma`, the function returns `NaN`', function test( t ) { + var v = mean( NaN ); + t.equal( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'if provided a value less than or equal to 0 for `sigma`, the function returns `NaN`', function test( t ) { + var v; + + v = mean( 0.0 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = mean( -1.0 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = mean( NINF ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns the expected value', function test( t ) { + var expected; + var sigma; + var v; + var i; + + // Test cases (sigma, expected) + // Mean = sigma * sqrt(2/pi) -> sigma * ~0.79788456 + sigma = [ 1.0, 2.0, 5.0, 0.5 ]; + expected = [ + 0.79788456, + 1.59576912, + 3.98942280, + 0.39894228 + ]; + + for ( i = 0; i < sigma.length; i++ ) { + v = mean( sigma[ i ] ); + // We check if the difference is very small (epsilon) + if ( abs( v - expected[ i ] ) > 1e-7 ) { + t.fail( 'returns ' + v + ' when expected ' + expected[ i ] ); + } else { + t.pass( 'returns ' + v + ' when expected ' + expected[ i ] ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/index.js new file mode 100644 index 000000000000..dfde7b732a25 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/index.js @@ -0,0 +1,25 @@ +'use strict'; + +/** +* Half-normal distribution variance. +* +* @module @stdlib/stats/base/dists/halfnormal/variance +* +* @example +* var variance = require( '@stdlib/stats/base/dists/halfnormal/variance' ); +* +* var v = variance( 1.0 ); +* // returns ~0.363 +* +* var v = variance( 2.0 ); +* // returns ~1.454 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/main.js new file mode 100644 index 000000000000..f10a39c7ed54 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/lib/main.js @@ -0,0 +1,46 @@ +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var PI = require( '@stdlib/constants/float64/pi' ); + + +// VARIABLES // + +// 1 - 2/pi +var FACTOR = 1.0 - ( 2.0 / PI ); + + +// MAIN // + +/** +* Returns the variance of a half-normal distribution. +* +* @param {number} sigma - scale parameter +* @returns {number} variance +* +* @example +* var v = variance( 1.0 ); +* // returns ~0.363 +* +* @example +* var v = variance( 2.0 ); +* // returns ~1.454 +* +* @example +* var v = variance( -1.0 ); +* // returns NaN +*/ +function variance( sigma ) { + if ( isnan( sigma ) || sigma <= 0.0 ) { + return NaN; + } + return pow( sigma, 2.0 ) * FACTOR; +} + + +// EXPORTS // + +module.exports = variance; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/package.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/package.json new file mode 100644 index 000000000000..80c483f2f7b3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/stats-base-dists-halfnormal-variance", + "version": "0.0.0", + "description": "Half-normal distribution variance.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "doc": "./docs", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": { + "test": "make test", + "test-cov": "make test-cov", + "test-browsers": "make test-browsers" + }, + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": { + "@stdlib/constants/float64/pi": "^0.2.2", + "@stdlib/math/base/assert/is-nan": "^0.2.2", + "@stdlib/math/base/special/pow": "^0.2.2" + }, + "devDependencies": { + "@stdlib/math/base/special/abs": "^0.2.2", + "tape": "git+https://github.com/kgryte/tape.git#fix/globby", + "istanbul": "^0.4.1", + "tap-min": "git+https://github.com/Planeshifter/tap-min.git" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "half-normal", + "halfnormal", + "variance", + "var", + "dispersion" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/test/test.js new file mode 100644 index 000000000000..d645f2be295a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/variance/test/test.js @@ -0,0 +1,67 @@ +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var variance = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.equal( typeof variance, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for `sigma`, the function returns `NaN`', function test( t ) { + var v = variance( NaN ); + t.equal( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'if provided a value less than or equal to 0 for `sigma`, the function returns `NaN`', function test( t ) { + var v; + + v = variance( 0.0 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( -1.0 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = variance( NINF ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'the function returns the variance', function test( t ) { + var expected; + var sigma; + var v; + var i; + + // Test cases (sigma, expected) + // Variance = sigma^2 * (1 - 2/pi) + // 1 - 2/pi ≈ 0.3633802276 + sigma = [ 1.0, 2.0, 5.0 ]; + expected = [ + 0.36338023, + 1.45352091, + 9.08450569 + ]; + + for ( i = 0; i < sigma.length; i++ ) { + v = variance( sigma[ i ] ); + if ( abs( v - expected[ i ] ) > 1e-7 ) { + t.fail( 'returns ' + v + ' when expected ' + expected[ i ] ); + } else { + t.pass( 'returns ' + v + ' when expected ' + expected[ i ] ); + } + } + t.end(); +});