From 27869567eacde084422cc5010df3465a30c42600 Mon Sep 17 00:00:00 2001 From: Ruthwik Chikoti Date: Mon, 15 Jul 2024 18:29:31 +0530 Subject: [PATCH 1/2] issue#1632 resolved --- .../stats/base/dists/kumaraswamy/README.md | 70 +++++++++++++++++++ .../base/dists/kumaraswamy/examples/index.js | 69 ++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/README.md b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/README.md index bd18036609bb..06a50c7b6b01 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/README.md @@ -111,6 +111,76 @@ var objectKeys = require( '@stdlib/utils/keys' ); var kumaraswamy = require( '@stdlib/stats/base/dists/kumaraswamy' ); console.log( objectKeys( kumaraswamy ) ); +// Create a Kumaraswamy distribution object +var a = 2.0; +var b = 5.0; +var dist = new kumaraswamy.Kumaraswamy( a, b ); + +// Calculate basic distribution properties +console.log( 'Mean: %d', dist.mean ); +console.log( 'Median: %d', dist.median ); +console.log( 'Mode: %d', dist.mode ); +console.log( 'Variance: %d', dist.variance ); + +// Evaluate the probability density function (PDF) +var x = 0.5; +var y = dist.pdf( x ); +console.log( 'PDF at x = %d: %d', x, y ); + +// Evaluate the cumulative distribution function (CDF) +y = dist.cdf( x ); +console.log( 'CDF at x = %d: %d', x, y ); + +// Evaluate the natural logarithm of PDF and CDF +console.log( 'Log PDF at x = %d: %d', x, dist.logpdf( x ) ); +console.log( 'Log CDF at x = %d: %d', x, dist.logcdf( x ) ); + +// Calculate the quantile for a given probability +var p = 0.75; +x = dist.quantile( p ); +console.log( 'Quantile at p = %d: %d', p, x ); + +// Generate random numbers +var r = new Array( 5 ); +for ( var i = 0; i < 5; i++ ) { + r[ i ] = kumaraswamy.random( a, b ); +} +console.log( 'Random samples: %s', r.join( ', ' ) ); + +// Use standalone functions +x = 0.3; +y = kumaraswamy.pdf( x, a, b ); +console.log( 'Standalone PDF at x = %d: %d', x, y ); + +y = kumaraswamy.cdf( x, a, b ); +console.log( 'Standalone CDF at x = %d: %d', x, y ); + +y = kumaraswamy.quantile( 0.9, a, b ); +console.log( 'Standalone Quantile at p = 0.9: %d', y ); + +// Calculate additional distribution properties +console.log( 'Kurtosis: %d', kumaraswamy.kurtosis( a, b ) ); +console.log( 'Skewness: %d', kumaraswamy.skewness( a, b ) ); +console.log( 'Standard Deviation: %d', kumaraswamy.stdev( a, b ) ); + +// Demonstrate the effect of different shape parameters +console.log( '\nEffect of shape parameters:' ); +var shapes = [ + [0.5, 0.5], + [5.0, 1.0], + [1.0, 5.0], + [2.0, 2.0], + [10.0, 10.0] +]; + +for ( var i = 0; i < shapes.length; i++ ) { + var params = shapes[i]; + console.log( '\na = %d, b = %d', params[0], params[1] ); + console.log( 'Mean: %d', kumaraswamy.mean( params[0], params[1] ) ); + console.log( 'Median: %d', kumaraswamy.median( params[0], params[1] ) ); + console.log( 'Mode: %d', kumaraswamy.mode( params[0], params[1] ) ); + console.log( 'Skewness: %d', kumaraswamy.skewness( params[0], params[1] ) ); +} ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/examples/index.js index 668493a128a3..31e3df9d3040 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/examples/index.js @@ -22,3 +22,72 @@ var objectKeys = require( '@stdlib/utils/keys' ); var kumaraswamy = require( './../lib' ); console.log( objectKeys( kumaraswamy ) ); +// Create a Kumaraswamy distribution object +var a = 2.0; +var b = 5.0; +var dist = new kumaraswamy.Kumaraswamy( a, b ); + +// Calculate basic distribution properties +console.log( 'Mean: %d', dist.mean ); +console.log( 'Median: %d', dist.median ); +console.log( 'Mode: %d', dist.mode ); +console.log( 'Variance: %d', dist.variance ); + +// Evaluate the probability density function (PDF) +var x = 0.5; +var y = dist.pdf( x ); +console.log( 'PDF at x = %d: %d', x, y ); + +// Evaluate the cumulative distribution function (CDF) +y = dist.cdf( x ); +console.log( 'CDF at x = %d: %d', x, y ); + +// Evaluate the natural logarithm of PDF and CDF +console.log( 'Log PDF at x = %d: %d', x, dist.logpdf( x ) ); +console.log( 'Log CDF at x = %d: %d', x, dist.logcdf( x ) ); + +// Calculate the quantile for a given probability +var p = 0.75; +x = dist.quantile( p ); +console.log( 'Quantile at p = %d: %d', p, x ); + +// Generate random numbers +var r = new Array( 5 ); +for ( var i = 0; i < 5; i++ ) { + r[ i ] = kumaraswamy.random( a, b ); +} +console.log( 'Random samples: %s', r.join( ', ' ) ); + +// Use standalone functions +x = 0.3; +y = kumaraswamy.pdf( x, a, b ); +console.log( 'Standalone PDF at x = %d: %d', x, y ); + +y = kumaraswamy.cdf( x, a, b ); +console.log( 'Standalone CDF at x = %d: %d', x, y ); + +y = kumaraswamy.quantile( 0.9, a, b ); +console.log( 'Standalone Quantile at p = 0.9: %d', y ); + +// Calculate additional distribution properties +console.log( 'Kurtosis: %d', kumaraswamy.kurtosis( a, b ) ); +console.log( 'Skewness: %d', kumaraswamy.skewness( a, b ) ); +console.log( 'Standard Deviation: %d', kumaraswamy.stdev( a, b ) ); + +// Demonstrate the effect of different shape parameters +console.log( '\nEffect of shape parameters:' ); +var shapes = [ + [0.5, 0.5], + [5.0, 1.0], + [1.0, 5.0], + [2.0, 2.0], + [10.0, 10.0] +]; +for ( var i = 0; i < shapes.length; i++ ) { + var params = shapes[i]; + console.log( '\na = %d, b = %d', params[0], params[1] ); + console.log( 'Mean: %d', kumaraswamy.mean( params[0], params[1] ) ); + console.log( 'Median: %d', kumaraswamy.median( params[0], params[1] ) ); + console.log( 'Mode: %d', kumaraswamy.mode( params[0], params[1] ) ); + console.log( 'Skewness: %d', kumaraswamy.skewness( params[0], params[1] ) ); +} From 488fd160e42cf53d399c07e274aa05d9dca00408 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Mon, 11 Nov 2024 17:58:21 -0500 Subject: [PATCH 2/2] chore: clean-up new examples --- .../stats/base/dists/kumaraswamy/README.md | 46 +++++++--------- .../base/dists/kumaraswamy/examples/index.js | 53 ++++++++----------- 2 files changed, 41 insertions(+), 58 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/README.md b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/README.md index 06a50c7b6b01..aaa18533aeac 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/README.md @@ -102,52 +102,41 @@ var y = dist.logpdf( 0.8 ); ## Examples - - ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); var kumaraswamy = require( '@stdlib/stats/base/dists/kumaraswamy' ); -console.log( objectKeys( kumaraswamy ) ); -// Create a Kumaraswamy distribution object +// Create a Kumaraswamy distribution object: var a = 2.0; var b = 5.0; var dist = new kumaraswamy.Kumaraswamy( a, b ); -// Calculate basic distribution properties +// Calculate basic distribution properties: console.log( 'Mean: %d', dist.mean ); console.log( 'Median: %d', dist.median ); console.log( 'Mode: %d', dist.mode ); console.log( 'Variance: %d', dist.variance ); -// Evaluate the probability density function (PDF) +// Evaluate the probability density function (PDF): var x = 0.5; var y = dist.pdf( x ); console.log( 'PDF at x = %d: %d', x, y ); -// Evaluate the cumulative distribution function (CDF) +// Evaluate the cumulative distribution function (CDF): y = dist.cdf( x ); console.log( 'CDF at x = %d: %d', x, y ); -// Evaluate the natural logarithm of PDF and CDF +// Evaluate the natural logarithm of PDF and CDF: console.log( 'Log PDF at x = %d: %d', x, dist.logpdf( x ) ); console.log( 'Log CDF at x = %d: %d', x, dist.logcdf( x ) ); -// Calculate the quantile for a given probability +// Calculate the quantile for a given probability: var p = 0.75; x = dist.quantile( p ); console.log( 'Quantile at p = %d: %d', p, x ); -// Generate random numbers -var r = new Array( 5 ); -for ( var i = 0; i < 5; i++ ) { - r[ i ] = kumaraswamy.random( a, b ); -} -console.log( 'Random samples: %s', r.join( ', ' ) ); - -// Use standalone functions +// Use standalone distribution functions: x = 0.3; y = kumaraswamy.pdf( x, a, b ); console.log( 'Standalone PDF at x = %d: %d', x, y ); @@ -158,23 +147,24 @@ console.log( 'Standalone CDF at x = %d: %d', x, y ); y = kumaraswamy.quantile( 0.9, a, b ); console.log( 'Standalone Quantile at p = 0.9: %d', y ); -// Calculate additional distribution properties +// Calculate additional distribution properties: console.log( 'Kurtosis: %d', kumaraswamy.kurtosis( a, b ) ); console.log( 'Skewness: %d', kumaraswamy.skewness( a, b ) ); console.log( 'Standard Deviation: %d', kumaraswamy.stdev( a, b ) ); -// Demonstrate the effect of different shape parameters +// Demonstrate the effect of different shape parameters: console.log( '\nEffect of shape parameters:' ); var shapes = [ - [0.5, 0.5], - [5.0, 1.0], - [1.0, 5.0], - [2.0, 2.0], - [10.0, 10.0] + [ 0.5, 0.5 ], + [ 5.0, 1.0 ], + [ 1.0, 5.0 ], + [ 2.0, 2.0 ], + [ 10.0, 10.0 ] ]; - -for ( var i = 0; i < shapes.length; i++ ) { - var params = shapes[i]; +var params; +var i; +for ( i = 0; i < shapes.length; i++ ) { + params = shapes[i]; console.log( '\na = %d, b = %d', params[0], params[1] ); console.log( 'Mean: %d', kumaraswamy.mean( params[0], params[1] ) ); console.log( 'Median: %d', kumaraswamy.median( params[0], params[1] ) ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/examples/index.js index 31e3df9d3040..1f0b34c120c5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/kumaraswamy/examples/index.js @@ -18,47 +18,38 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); var kumaraswamy = require( './../lib' ); -console.log( objectKeys( kumaraswamy ) ); -// Create a Kumaraswamy distribution object +// Create a Kumaraswamy distribution object: var a = 2.0; var b = 5.0; var dist = new kumaraswamy.Kumaraswamy( a, b ); -// Calculate basic distribution properties +// Calculate basic distribution properties: console.log( 'Mean: %d', dist.mean ); console.log( 'Median: %d', dist.median ); console.log( 'Mode: %d', dist.mode ); console.log( 'Variance: %d', dist.variance ); -// Evaluate the probability density function (PDF) +// Evaluate the probability density function (PDF): var x = 0.5; var y = dist.pdf( x ); console.log( 'PDF at x = %d: %d', x, y ); -// Evaluate the cumulative distribution function (CDF) +// Evaluate the cumulative distribution function (CDF): y = dist.cdf( x ); console.log( 'CDF at x = %d: %d', x, y ); -// Evaluate the natural logarithm of PDF and CDF +// Evaluate the natural logarithm of PDF and CDF: console.log( 'Log PDF at x = %d: %d', x, dist.logpdf( x ) ); console.log( 'Log CDF at x = %d: %d', x, dist.logcdf( x ) ); -// Calculate the quantile for a given probability +// Calculate the quantile for a given probability: var p = 0.75; x = dist.quantile( p ); console.log( 'Quantile at p = %d: %d', p, x ); -// Generate random numbers -var r = new Array( 5 ); -for ( var i = 0; i < 5; i++ ) { - r[ i ] = kumaraswamy.random( a, b ); -} -console.log( 'Random samples: %s', r.join( ', ' ) ); - -// Use standalone functions +// Use standalone distribution functions: x = 0.3; y = kumaraswamy.pdf( x, a, b ); console.log( 'Standalone PDF at x = %d: %d', x, y ); @@ -69,25 +60,27 @@ console.log( 'Standalone CDF at x = %d: %d', x, y ); y = kumaraswamy.quantile( 0.9, a, b ); console.log( 'Standalone Quantile at p = 0.9: %d', y ); -// Calculate additional distribution properties +// Calculate additional distribution properties: console.log( 'Kurtosis: %d', kumaraswamy.kurtosis( a, b ) ); console.log( 'Skewness: %d', kumaraswamy.skewness( a, b ) ); console.log( 'Standard Deviation: %d', kumaraswamy.stdev( a, b ) ); -// Demonstrate the effect of different shape parameters +// Demonstrate the effect of different shape parameters: console.log( '\nEffect of shape parameters:' ); var shapes = [ - [0.5, 0.5], - [5.0, 1.0], - [1.0, 5.0], - [2.0, 2.0], - [10.0, 10.0] + [ 0.5, 0.5 ], + [ 5.0, 1.0 ], + [ 1.0, 5.0 ], + [ 2.0, 2.0 ], + [ 10.0, 10.0 ] ]; -for ( var i = 0; i < shapes.length; i++ ) { - var params = shapes[i]; - console.log( '\na = %d, b = %d', params[0], params[1] ); - console.log( 'Mean: %d', kumaraswamy.mean( params[0], params[1] ) ); - console.log( 'Median: %d', kumaraswamy.median( params[0], params[1] ) ); - console.log( 'Mode: %d', kumaraswamy.mode( params[0], params[1] ) ); - console.log( 'Skewness: %d', kumaraswamy.skewness( params[0], params[1] ) ); +var params; +var i; +for ( i = 0; i < shapes.length; i++ ) { + params = shapes[ i ]; + console.log( '\na = %d, b = %d', params[0], params[1] ); + console.log( 'Mean: %d', kumaraswamy.mean( params[0], params[1] ) ); + console.log( 'Median: %d', kumaraswamy.median( params[0], params[1] ) ); + console.log( 'Mode: %d', kumaraswamy.mode( params[0], params[1] ) ); + console.log( 'Skewness: %d', kumaraswamy.skewness( params[0], params[1] ) ); }