From 69899f78044205849258c3c8bdf3dad4f3d0f211 Mon Sep 17 00:00:00 2001 From: Kohantika Nath Date: Fri, 26 Jul 2024 22:55:11 +0530 Subject: [PATCH 1/4] Docs: improve README examples of stats/base/dists/cosine namespace --- .../@stdlib/stats/base/dists/cosine/README.md | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md b/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md index 0c3bbd1c508..cfe202f12f7 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md @@ -108,10 +108,54 @@ var y = dist.cdf( 0.5 ); ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); var cosine = require( '@stdlib/stats/base/dists/cosine' ); -console.log( objectKeys( cosine ) ); + +// Create a raised cosine distribution +var mu = 2.0; +var s = 1.5; +var dist = new cosine.Cosine( mu, s ); + +// Calculate various distribution properties +console.log( 'Mean: %d', dist.mean ); +// => Mean: 2 + +console.log( 'Median: %d', dist.median ); +// => Median: 2 + +console.log( 'Mode: %d', dist.mode ); +// => Mode: 2 + +console.log( 'Standard Deviation: %d', dist.stdev ); +// => Standard Deviation: 0.6123724356957945 + +console.log( 'Variance: %d', dist.variance ); +// => Variance: 0.375 + +// Evaluate the probability density function (PDF) +var x = 1.5; +console.log( 'PDF( %d ): %d', x, dist.pdf( x ) ); +// => PDF( 1.5 ): 0.2886751345948129 + +// Evaluate the cumulative distribution function (CDF) +console.log( 'CDF( %d ): %d', x, dist.cdf( x ) ); +// => CDF( 1.5 ): 0.21132486540518708 + +// Generate random samples +var samples = new Array( 5 ); +for ( var i = 0; i < 5; i++ ) { + samples[ i ] = dist.quantile( Math.random() ); +} +console.log( 'Samples: %s', samples.join( ', ' ) ); +// => Samples: 2.2642152512549444, 2.7489308009950834, 1.6391832278662363, 1.3555922486975812, 2.4894454832467757 + +// Calculate distribution moments +console.log( 'Skewness: %d', cosine.skewness( mu, s ) ); +// => Skewness: 0 + +console.log( 'Excess Kurtosis: %d', cosine.kurtosis( mu, s ) ); +// => Excess Kurtosis: -0.5933333333333333 + ``` From bd64130b32a4321805d934409a1cc3ff4bd0f2ce Mon Sep 17 00:00:00 2001 From: Kohantika Nath Date: Sat, 27 Jul 2024 22:30:37 +0530 Subject: [PATCH 2/4] Docs:improve README examples of stats/base/dists/chisquare namespace --- .../stats/base/dists/chisquare/README.md | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md b/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md index f4c6a0505a4..6975ccf61fd 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md @@ -108,10 +108,54 @@ var mu = dist.mean; ```javascript -var objectKeys = require( '@stdlib/utils/keys' ); var chisquare = require( '@stdlib/stats/base/dists/chisquare' ); - -console.log( objectKeys( chisquare ) ); +var round = require( '@stdlib/math/base/special/round' ); + +// Define degrees of freedom +var k = 5.0; + +// Create a chi-square distribution object +var dist = new chisquare.ChiSquare( k ); + +console.log( 'Chi-square distribution with %d degrees of freedom:', k ); + +// Calculate basic properties +console.log( 'Mean: %d', chisquare.mean( k ) ); +console.log( 'Median: %d', round( chisquare.median( k ), 4 ) ); +console.log( 'Mode: %d', chisquare.mode( k ) ); +console.log( 'Variance: %d', chisquare.variance( k ) ); +console.log( 'Standard Deviation: %d', round( chisquare.stdev( k ), 4 ) ); + +// Calculate distribution shape properties +console.log( 'Skewness: %d', round( chisquare.skewness( k ), 4 ) ); +console.log( 'Excess Kurtosis: %d', round( chisquare.kurtosis( k ), 4 ) ); +console.log( 'Entropy: %d', round( chisquare.entropy( k ), 4 ) ); + +// Evaluate probability functions +var x = 3.0; +console.log( '\nEvaluating at x = %d', x ); +console.log( 'PDF: %d', round( chisquare.pdf( x, k ), 4 ) ); +console.log( 'logPDF: %d', round( chisquare.logpdf( x, k ), 4 ) ); +console.log( 'CDF: %d', round( chisquare.cdf( x, k ), 4 ) ); + +// Calculate quantiles +var p = 0.7; +console.log( '\nQuantile at p = %d: %d', p, round( chisquare.quantile( p, k ), 4 ) ); + +// Evaluate moment-generating function +var t = 0.1; +console.log( 'MGF at t = %d: %d', t, round( chisquare.mgf( t, k ), 4 ) ); + +// Generate random variates +var seed = 1234; +var rand = chisquare.factory( k, { + 'seed': seed +}); +var samples = new Array( 5 ); +for ( var i = 0; i < 5; i++ ) { + samples[ i ] = round( rand(), 2 ); +} +console.log( '\nRandom samples: %s', samples.join( ', ' ) ); ``` From 1c62799486d56d1effb17138d816d4deb761fada Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 17 Nov 2024 15:37:02 -0500 Subject: [PATCH 3/4] chore: revert changes in cosine namespace --- .../@stdlib/stats/base/dists/cosine/README.md | 48 +------------------ 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md b/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md index cfe202f12f7..0c3bbd1c508 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/cosine/README.md @@ -108,54 +108,10 @@ var y = dist.cdf( 0.5 ); ```javascript +var objectKeys = require( '@stdlib/utils/keys' ); var cosine = require( '@stdlib/stats/base/dists/cosine' ); - -// Create a raised cosine distribution -var mu = 2.0; -var s = 1.5; -var dist = new cosine.Cosine( mu, s ); - -// Calculate various distribution properties -console.log( 'Mean: %d', dist.mean ); -// => Mean: 2 - -console.log( 'Median: %d', dist.median ); -// => Median: 2 - -console.log( 'Mode: %d', dist.mode ); -// => Mode: 2 - -console.log( 'Standard Deviation: %d', dist.stdev ); -// => Standard Deviation: 0.6123724356957945 - -console.log( 'Variance: %d', dist.variance ); -// => Variance: 0.375 - -// Evaluate the probability density function (PDF) -var x = 1.5; -console.log( 'PDF( %d ): %d', x, dist.pdf( x ) ); -// => PDF( 1.5 ): 0.2886751345948129 - -// Evaluate the cumulative distribution function (CDF) -console.log( 'CDF( %d ): %d', x, dist.cdf( x ) ); -// => CDF( 1.5 ): 0.21132486540518708 - -// Generate random samples -var samples = new Array( 5 ); -for ( var i = 0; i < 5; i++ ) { - samples[ i ] = dist.quantile( Math.random() ); -} -console.log( 'Samples: %s', samples.join( ', ' ) ); -// => Samples: 2.2642152512549444, 2.7489308009950834, 1.6391832278662363, 1.3555922486975812, 2.4894454832467757 - -// Calculate distribution moments -console.log( 'Skewness: %d', cosine.skewness( mu, s ) ); -// => Skewness: 0 - -console.log( 'Excess Kurtosis: %d', cosine.kurtosis( mu, s ) ); -// => Excess Kurtosis: -0.5933333333333333 - +console.log( objectKeys( cosine ) ); ``` From 790bfda571e52839d7350f991bcf356c2cb5eebe Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sun, 17 Nov 2024 15:41:15 -0500 Subject: [PATCH 4/4] chore: clean-up examples --- .../stats/base/dists/chisquare/README.md | 50 ++++++------------- .../base/dists/chisquare/examples/index.js | 30 ++++++++++- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md b/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md index 6975ccf61fd..7d4d99dadb6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/chisquare/README.md @@ -108,54 +108,36 @@ var mu = dist.mean; ```javascript +var roundn = require( '@stdlib/math/base/special/roundn' ); var chisquare = require( '@stdlib/stats/base/dists/chisquare' ); -var round = require( '@stdlib/math/base/special/round' ); -// Define degrees of freedom +// Define degrees of freedom: var k = 5.0; -// Create a chi-square distribution object -var dist = new chisquare.ChiSquare( k ); - -console.log( 'Chi-square distribution with %d degrees of freedom:', k ); - -// Calculate basic properties +// Calculate distribution properties: console.log( 'Mean: %d', chisquare.mean( k ) ); -console.log( 'Median: %d', round( chisquare.median( k ), 4 ) ); +console.log( 'Median: %d', roundn( chisquare.median( k ), -4 ) ); console.log( 'Mode: %d', chisquare.mode( k ) ); console.log( 'Variance: %d', chisquare.variance( k ) ); -console.log( 'Standard Deviation: %d', round( chisquare.stdev( k ), 4 ) ); - -// Calculate distribution shape properties -console.log( 'Skewness: %d', round( chisquare.skewness( k ), 4 ) ); -console.log( 'Excess Kurtosis: %d', round( chisquare.kurtosis( k ), 4 ) ); -console.log( 'Entropy: %d', round( chisquare.entropy( k ), 4 ) ); +console.log( 'Standard Deviation: %d', roundn( chisquare.stdev( k ), -4 ) ); +console.log( 'Skewness: %d', roundn( chisquare.skewness( k ), -4 ) ); +console.log( 'Excess Kurtosis: %d', roundn( chisquare.kurtosis( k ), -4 ) ); +console.log( 'Entropy: %d', roundn( chisquare.entropy( k ), -4 ) ); -// Evaluate probability functions +// Evaluate probability functions: var x = 3.0; console.log( '\nEvaluating at x = %d', x ); -console.log( 'PDF: %d', round( chisquare.pdf( x, k ), 4 ) ); -console.log( 'logPDF: %d', round( chisquare.logpdf( x, k ), 4 ) ); -console.log( 'CDF: %d', round( chisquare.cdf( x, k ), 4 ) ); +console.log( 'PDF: %d', roundn( chisquare.pdf( x, k ), -4 ) ); +console.log( 'logPDF: %d', roundn( chisquare.logpdf( x, k ), -4 ) ); +console.log( 'CDF: %d', roundn( chisquare.cdf( x, k ), -4 ) ); -// Calculate quantiles +// Calculate quantiles: var p = 0.7; -console.log( '\nQuantile at p = %d: %d', p, round( chisquare.quantile( p, k ), 4 ) ); +console.log( '\nQuantile at p = %d: %d', p, roundn( chisquare.quantile( p, k ), -4 ) ); -// Evaluate moment-generating function +// Evaluate moment-generating function: var t = 0.1; -console.log( 'MGF at t = %d: %d', t, round( chisquare.mgf( t, k ), 4 ) ); - -// Generate random variates -var seed = 1234; -var rand = chisquare.factory( k, { - 'seed': seed -}); -var samples = new Array( 5 ); -for ( var i = 0; i < 5; i++ ) { - samples[ i ] = round( rand(), 2 ); -} -console.log( '\nRandom samples: %s', samples.join( ', ' ) ); +console.log( 'MGF at t = %d: %d', t, roundn( chisquare.mgf( t, k ), -4 ) ); ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/chisquare/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/chisquare/examples/index.js index 93d672bacc8..95e4bf94718 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/chisquare/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/chisquare/examples/index.js @@ -18,7 +18,33 @@ 'use strict'; -var objectKeys = require( '@stdlib/utils/keys' ); +var roundn = require( '@stdlib/math/base/special/roundn' ); var chisquare = require( './../lib' ); -console.log( objectKeys( chisquare ) ); +// Define degrees of freedom: +var k = 5.0; + +// Calculate distribution properties: +console.log( 'Mean: %d', chisquare.mean( k ) ); +console.log( 'Median: %d', roundn( chisquare.median( k ), -4 ) ); +console.log( 'Mode: %d', chisquare.mode( k ) ); +console.log( 'Variance: %d', chisquare.variance( k ) ); +console.log( 'Standard Deviation: %d', roundn( chisquare.stdev( k ), -4 ) ); +console.log( 'Skewness: %d', roundn( chisquare.skewness( k ), -4 ) ); +console.log( 'Excess Kurtosis: %d', roundn( chisquare.kurtosis( k ), -4 ) ); +console.log( 'Entropy: %d', roundn( chisquare.entropy( k ), -4 ) ); + +// Evaluate probability functions: +var x = 3.0; +console.log( '\nEvaluating at x = %d', x ); +console.log( 'PDF: %d', roundn( chisquare.pdf( x, k ), -4 ) ); +console.log( 'logPDF: %d', roundn( chisquare.logpdf( x, k ), -4 ) ); +console.log( 'CDF: %d', roundn( chisquare.cdf( x, k ), -4 ) ); + +// Calculate quantiles: +var p = 0.7; +console.log( '\nQuantile at p = %d: %d', p, roundn( chisquare.quantile( p, k ), -4 ) ); + +// Evaluate moment-generating function: +var t = 0.1; +console.log( 'MGF at t = %d: %d', t, roundn( chisquare.mgf( t, k ), -4 ) );