diff --git a/stats/base/dists/bernoulli/cdf/coverage.ndjson b/stats/base/dists/bernoulli/cdf/coverage.ndjson new file mode 100644 index 000000000..b9805028a --- /dev/null +++ b/stats/base/dists/bernoulli/cdf/coverage.ndjson @@ -0,0 +1 @@ +[282,282,100,27,27,100,4,4,100,282,282,100,"ba78aa0847bc80f0dee0a27252c5618ed272bc1d","2024-12-16 23:03:01 +0530"] diff --git a/stats/base/dists/bernoulli/cdf/factory.js.html b/stats/base/dists/bernoulli/cdf/factory.js.html new file mode 100644 index 000000000..863e13db7 --- /dev/null +++ b/stats/base/dists/bernoulli/cdf/factory.js.html @@ -0,0 +1,316 @@ + + + + +
++ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 | 3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +2008x +2008x +4x +4x +2004x +2004x +2004x +2004x +2004x +2004x +2004x +2004x +2004x +2004x +2004x +2004x +2004x +2004x +2006x +1x +1x +2006x +4x +4x +2006x +1581x +1581x +420x +2006x +2008x +3x +3x +3x +3x +3x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var constantFunction = require( '@stdlib/utils/constant-function' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Returns a function for evaluating the cumulative distribution function (CDF) for a Bernoulli distribution with success probability `p`. +* +* @param {Probability} p - success probability +* @returns {Function} CDF +* +* @example +* var cdf = factory( 0.5 ); +* var y = cdf( 3.0 ); +* // returns 1.0 +* +* y = cdf( 0.7 ); +* // returns 0.5 +*/ +function factory( p ) { + if ( isnan( p ) || p < 0.0 || p > 1.0 ) { + return constantFunction( NaN ); + } + return cdf; + + /** + * Evaluates the cumulative distribution function (CDF) for a Bernoulli distribution. + * + * @private + * @param {number} x - input value + * @returns {Probability} evaluated CDF + * + * @example + * var y = cdf( 2.0 ); + * // returns <number> + */ + function cdf( x ) { + if ( isnan( x ) ) { + return NaN; + } + if ( x < 0.0 ) { + return 0.0; + } + if ( x >= 1.0 ) { + return 1.0; + } + return 1.0 - p; + } +} + + +// EXPORTS // + +module.exports = factory; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
---|---|---|---|---|---|---|---|---|---|
factory.js | +
+
+ |
+ 100% | +77/77 | +100% | +13/13 | +100% | +2/2 | +100% | +77/77 | +
index.js | +
+
+ |
+ 100% | +57/57 | +100% | +1/1 | +100% | +0/0 | +100% | +57/57 | +
main.js | +
+
+ |
+ 100% | +81/81 | +100% | +11/11 | +100% | +1/1 | +100% | +81/81 | +
native.js | +
+
+ |
+ 100% | +67/67 | +100% | +2/2 | +100% | +1/1 | +100% | +67/67 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 | 2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Bernoulli distribution cumulative distribution function (CDF). +* +* @module @stdlib/stats/base/dists/bernoulli/cdf +* +* @example +* var cdf = require( '@stdlib/stats/base/dists/bernoulli/cdf' ); +* +* var y = cdf( 1.0, 0.5 ); +* // returns 1.0 +* +* y = cdf( 0.5, 0.1 ); +* // returns 0.9 +* +* var mycdf = cdf.factory( 0.5 ); +* y = mycdf( 3.0 ); +* // returns 1.0 +* +* y = mycdf( -1.0 ); +* // returns 0.0 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var factory = require( './factory.js' ); + + +// MAIN // + +setReadOnly( main, 'factory', factory ); + + +// EXPORTS // + +module.exports = main; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 | 2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2010x +2010x +2010x +2010x +2010x +2006x +2010x +6x +6x +2010x +3x +3x +2010x +1581x +1581x +420x +2010x +2x +2x +2x +2x +2x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Evaluates the cumulative distribution function (CDF) for a Bernoulli distribution with success probability `p` at a value `x`. +* +* @param {number} x - input value +* @param {Probability} p - success probability +* @returns {Probability} evaluated CDF +* +* @example +* var y = cdf( 0.5, 0.5 ); +* // returns 0.5 +* +* @example +* var y = cdf( 2.0, 0.1 ); +* // returns 1.0 +* +* @example +* var y = cdf( -1.0, 0.3 ); +* // returns 0.0 +* +* @example +* var y = cdf( NaN, 0.5 ); +* // returns NaN +* +* @example +* var y = cdf( 0.0, NaN ); +* // returns NaN +* +* @example +* // Invalid probability +* var y = cdf( 0.5, 1.4 ); +* // returns NaN +*/ +function cdf( x, p ) { + if ( + isnan( x ) || + isnan( p ) || + p < 0.0 || + p > 1.0 + ) { + return NaN; + } + if ( x < 0.0 ) { + return 0.0; + } + if ( x >= 1.0 ) { + return 1.0; + } + return 1.0 - p; +} + + +// EXPORTS // + +module.exports = cdf; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 | 1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +2010x +2010x +2010x +1x +1x +1x +1x +1x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Evaluates the cumulative distribution function (CDF) for a Bernoulli distribution with success probability `p` at a value `x`. +* +* @param {number} x - input value +* @param {Probability} p - success probability +* @returns {Probability} evaluated CDF +* +* @example +* var y = cdf( 0.5, 0.5 ); +* // returns 1.0 +* +* @example +* var y = cdf( 2.0, 0.1 ); +* // returns 1.0 +* +* @example +* var y = cdf( -1.0, 0.3 ); +* // returns 0.0 +* +* @example +* var y = cdf( NaN, 0.5 ); +* // returns NaN +* +* @example +* var y = cdf( 0.0, NaN ); +* // returns NaN +* +* @example +* // Invalid probability +* var y = cdf( 0.5, 1.4 ); +* // returns NaN +*/ +function cdf( x, p ) { + return addon( x, p ); +} + + +// EXPORTS // + +module.exports = cdf; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 | 3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +2006x +2006x +3x +3x +2003x +2003x +2003x +2003x +2003x +2003x +2003x +2003x +2003x +2003x +2003x +2003x +2003x +2003x +2003x +3x +3x +2003x +990x +990x +1010x +2003x +2006x +3x +3x +3x +3x +3x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var constantFunction = require( '@stdlib/utils/constant-function' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Returns a function for evaluating the quantile function for a Bernoulli distribution with success probability `p`. +* +* @param {Probability} p - success probability +* @returns {Function} quantile function +* +* @example +* var quantile = factory( 0.4 ); +* var y = quantile( 0.4 ); +* // returns 0 +* +* y = quantile( 0.8 ); +* // returns 1 +* +* y = quantile( 1.0 ); +* // returns 1 +*/ +function factory( p ) { + if ( isnan( p ) || p < 0.0 || p > 1.0 ) { + return constantFunction( NaN ); + } + return quantile; + + /** + * Evaluates the quantile function for a Bernoulli distribution. + * + * @private + * @param {Probability} r - input value + * @returns {NonNegativeInteger} evaluated quantile function + * + * @example + * var y = quantile( 0.3 ); + * // returns <number> + */ + function quantile( r ) { + if ( isnan( r ) || r < 0.0 || r > 1.0 ) { + return NaN; + } + if ( r <= 1.0 - p ) { + return 0; + } + return 1; + } +} + + +// EXPORTS // + +module.exports = factory; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +File | ++ | Statements | ++ | Branches | ++ | Functions | ++ | Lines | ++ |
---|---|---|---|---|---|---|---|---|---|
factory.js | +
+
+ |
+ 100% | +77/77 | +100% | +13/13 | +100% | +2/2 | +100% | +77/77 | +
index.js | +
+
+ |
+ 100% | +60/60 | +100% | +1/1 | +100% | +0/0 | +100% | +60/60 | +
main.js | +
+
+ |
+ 100% | +87/87 | +100% | +11/11 | +100% | +1/1 | +100% | +87/87 | +
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 | 2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Bernoulli distribution quantile function. +* +* @module @stdlib/stats/base/dists/bernoulli/quantile +* +* @example +* var quantile = require( '@stdlib/stats/base/dists/bernoulli/quantile' ); +* +* var y = quantile( 0.8, 0.4 ); +* // returns 1 +* +* y = quantile( 0.5, 0.4 ); +* // returns 0 +* +* var myquantile = quantile.factory( 0.4 ); +* y = myquantile( 0.4 ); +* // returns 0 +* +* y = myquantile( 0.8 ); +* // returns 1 +* +* y = myquantile( 1.0 ); +* // returns 1 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var factory = require( './factory.js' ); + + +// MAIN // + +setReadOnly( main, 'factory', factory ); + + +// EXPORTS // + +module.exports = main; + |
+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +
+ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 | 2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2x +2007x +2007x +2007x +2007x +2007x +2007x +2007x +2001x +2007x +7x +7x +2007x +990x +990x +1010x +2007x +2x +2x +2x +2x +2x + | /** +* @license Apache-2.0 +* +* Copyright (c) 2018 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); + + +// MAIN // + +/** +* Evaluates the quantile function for a Bernoulli distribution with success probability `p` at a probability `r`. +* +* @param {Probability} r - input value +* @param {Probability} p - success probability +* @returns {NonNegativeInteger} evaluated quantile function +* +* @example +* var y = quantile( 0.8, 0.4 ); +* // returns 1 +* +* @example +* var y = quantile( 0.5, 0.4 ); +* // returns 0 +* +* @example +* var y = quantile( 0.8, 0.1 ); +* // returns 0 +* +* @example +* var y = quantile( -0.2, 0.1 ); +* // returns NaN +* +* @example +* var y = quantile( NaN, 0.8 ); +* // returns NaN +* +* @example +* var y = quantile( 0.4, NaN ); +* // returns NaN +* +* @example +* var y = quantile( 0.5, -1.0 ); +* // returns NaN +* +* @example +* var y = quantile( 0.5, 1.5 ); +* // returns NaN +*/ +function quantile( r, p ) { + if ( + isnan( p ) || + isnan( r ) || + p < 0.0 || + p > 1.0 || + r < 0.0 || + r > 1.0 + ) { + return NaN; + } + if ( r <= 1.0 - p ) { + return 0; + } + return 1; +} + + +// EXPORTS // + +module.exports = quantile; + |