Skip to content

Commit

Permalink
chore: minor clean-up after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Planeshifter committed Oct 12, 2024
1 parent efbff47 commit 43e7a33
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
-->

# isSameArrayLike
# isSameTypedArrayLike

> Test if two arguments are both typed-array-like objects and have the [same values][@stdlib/assert/is-same-value].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @example
* var Int8Array = require( '@stdlib/array/int8' );
* var Int16Array = require( '@stdlib/array/int16' );
*
* var x = new Int8Array( [ 1.0, 2.0, 3.0 ] );
* var y = new Int16Array( [ 1.0, 2.0, 3.0 ] );
*
Expand All @@ -36,6 +37,7 @@
*
* @example
* var Int8Array = require( '@stdlib/array/int8' );
*
* var x = new Int8Array( [ 1.0, 2.0, 3.0 ] );
* var y = new Int8Array( [ 1.0, 2.0, 4.0 ] );
*
Expand Down
5 changes: 2 additions & 3 deletions lib/node_modules/@stdlib/iter/cunone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ var iterCuNone = require( '@stdlib/iter/cunone' );

#### iterCuNone( iterator )

Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every
iterated value is falsy.
Returns an [iterator][mdn-iterator-protocol] which cumulatively tests whether every iterated value is falsy.

```javascript
var array2iterator = require( '@stdlib/array/to-iterator' );
Expand Down Expand Up @@ -115,7 +114,7 @@ var riter = randu( opts );
// Create an iterator which applies a threshold to generated numbers:
var miter = iterMap( riter, threshold );

// Create an iterator which cumulatively tests whether every iterated value is falsy.
// Create an iterator which cumulatively tests whether every iterated value is falsy:
var it = iterCuNone( miter );

// Perform manual iteration...
Expand Down
40 changes: 19 additions & 21 deletions lib/node_modules/@stdlib/stats/base/dists/chi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ var filledarrayBy = require( '@stdlib/array/filled-by' );
var variance = require( '@stdlib/stats/base/variance' );
var linspace = require( '@stdlib/array/base/linspace' );
var rayleigh = require( '@stdlib/stats/base/dists/rayleigh' );
var absdiff = require( '@stdlib/math/base/utils/absolute-difference' );
var mean = require( '@stdlib/stats/base/mean' );
var abs = require( '@stdlib/math/base/special/abs' );
var max = require( '@stdlib/math/base/special/max' );
var chi = require( '@stdlib/stats/base/dists/chi' );

// Define the degrees of freedom parameter:
Expand All @@ -128,20 +130,20 @@ var chiCDF = chi.cdf.factory( k );
var cdf = filledarrayBy( x.length, 'float64', chiCDF );

// Output the PDF and CDF values:
console.log( 'x values:', x );
console.log( 'PDF values:', pdf );
console.log( 'CDF values:', cdf );
console.log( 'x values: ', x );
console.log( 'PDF values: ', pdf );
console.log( 'CDF values: ', cdf );

// Compute statistical properties:
var theoreticalMean = chi.mean( k );
var theoreticalVariance = chi.variance( k );
var theoreticalSkewness = chi.skewness( k );
var theoreticalKurtosis = chi.kurtosis( k );

console.log( 'Theoretical Mean:', theoreticalMean );
console.log( 'Theoretical Variance:', theoreticalVariance );
console.log( 'Skewness:', theoreticalSkewness );
console.log( 'Kurtosis:', theoreticalKurtosis );
console.log( 'Theoretical Mean: ', theoreticalMean );
console.log( 'Theoretical Variance: ', theoreticalVariance );
console.log( 'Skewness: ', theoreticalSkewness );
console.log( 'Kurtosis: ', theoreticalKurtosis );

// Generate random samples from the Chi distribution:
var rchi = chiRandomFactory( k );
Expand All @@ -152,12 +154,12 @@ var samples = filledarrayBy( n, 'float64', rchi );
var sampleMean = mean( n, samples, 1 );
var sampleVariance = variance( n, 1, samples, 1 );

console.log( 'Sample Mean:', sampleMean );
console.log( 'Sample Variance:', sampleVariance );
console.log( 'Sample Mean: ', sampleMean );
console.log( 'Sample Variance: ', sampleVariance );

// Compare sample statistics to theoretical values:
console.log( 'Difference in Mean:', abs( theoreticalMean - sampleMean ) );
console.log( 'Difference in Variance:', abs( theoreticalVariance - sampleVariance ) );
console.log( 'Difference in Mean: ', abs( theoreticalMean - sampleMean ) );
console.log( 'Difference in Variance: ', abs( theoreticalVariance - sampleVariance ) );

// Demonstrate the relationship with the Rayleigh distribution when k=2:
var rayleighPDF = rayleigh.pdf.factory( 1.0 );
Expand All @@ -175,17 +177,13 @@ var diffPDF;
var diffCDF;
var i;
for ( i = 0; i < x.length; i++ ) {
diffPDF = abs( pdf[ i ] - rayleighPDFValues[ i ] );
if ( diffPDF > maxDiffPDF ) {
maxDiffPDF = diffPDF;
}
diffCDF = abs( cdf[ i ] - rayleighCDFValues[ i ] );
if ( diffCDF > maxDiffCDF ) {
maxDiffCDF = diffCDF;
}
diffPDF = absdiff( pdf[ i ], rayleighPDFValues[ i ] );
maxDiffPDF = max( maxDiffPDF, diffPDF );
diffCDF = absdiff( cdf[ i ], rayleighCDFValues[ i ] );
maxDiffCDF = max( maxDiffCDF, diffCDF );
}
console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF:', maxDiffPDF );
console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF:', maxDiffCDF );
console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF: ', maxDiffPDF );
console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF: ', maxDiffCDF );
```

</section>
Expand Down
40 changes: 19 additions & 21 deletions lib/node_modules/@stdlib/stats/base/dists/chi/examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ var filledarrayBy = require( '@stdlib/array/filled-by' );
var variance = require( '@stdlib/stats/base/variance' );
var linspace = require( '@stdlib/array/base/linspace' );
var rayleigh = require( '@stdlib/stats/base/dists/rayleigh' );
var absdiff = require( '@stdlib/math/base/utils/absolute-difference' );
var mean = require( '@stdlib/stats/base/mean' );
var abs = require( '@stdlib/math/base/special/abs' );
var max = require( '@stdlib/math/base/special/max' );
var chi = require( './../lib' );

// Define the degrees of freedom parameter:
Expand All @@ -42,20 +44,20 @@ var chiCDF = chi.cdf.factory( k );
var cdf = filledarrayBy( x.length, 'float64', chiCDF );

// Output the PDF and CDF values:
console.log( 'x values:', x );
console.log( 'PDF values:', pdf );
console.log( 'CDF values:', cdf );
console.log( 'x values: ', x );
console.log( 'PDF values: ', pdf );
console.log( 'CDF values: ', cdf );

// Compute statistical properties:
var theoreticalMean = chi.mean( k );
var theoreticalVariance = chi.variance( k );
var theoreticalSkewness = chi.skewness( k );
var theoreticalKurtosis = chi.kurtosis( k );

console.log( 'Theoretical Mean:', theoreticalMean );
console.log( 'Theoretical Variance:', theoreticalVariance );
console.log( 'Skewness:', theoreticalSkewness );
console.log( 'Kurtosis:', theoreticalKurtosis );
console.log( 'Theoretical Mean: ', theoreticalMean );
console.log( 'Theoretical Variance: ', theoreticalVariance );
console.log( 'Skewness: ', theoreticalSkewness );
console.log( 'Kurtosis: ', theoreticalKurtosis );

// Generate random samples from the Chi distribution:
var rchi = chiRandomFactory( k );
Expand All @@ -66,12 +68,12 @@ var samples = filledarrayBy( n, 'float64', rchi );
var sampleMean = mean( n, samples, 1 );
var sampleVariance = variance( n, 1, samples, 1 );

console.log( 'Sample Mean:', sampleMean );
console.log( 'Sample Variance:', sampleVariance );
console.log( 'Sample Mean: ', sampleMean );
console.log( 'Sample Variance: ', sampleVariance );

// Compare sample statistics to theoretical values:
console.log( 'Difference in Mean:', abs( theoreticalMean - sampleMean ) );
console.log( 'Difference in Variance:', abs( theoreticalVariance - sampleVariance ) );
console.log( 'Difference in Mean: ', abs( theoreticalMean - sampleMean ) );
console.log( 'Difference in Variance: ', abs( theoreticalVariance - sampleVariance ) );

// Demonstrate the relationship with the Rayleigh distribution when k=2:
var rayleighPDF = rayleigh.pdf.factory( 1.0 );
Expand All @@ -89,14 +91,10 @@ var diffPDF;
var diffCDF;
var i;
for ( i = 0; i < x.length; i++ ) {
diffPDF = abs( pdf[ i ] - rayleighPDFValues[ i ] );
if ( diffPDF > maxDiffPDF ) {
maxDiffPDF = diffPDF;
}
diffCDF = abs( cdf[ i ] - rayleighCDFValues[ i ] );
if ( diffCDF > maxDiffCDF ) {
maxDiffCDF = diffCDF;
}
diffPDF = absdiff( pdf[ i ], rayleighPDFValues[ i ] );
maxDiffPDF = max( maxDiffPDF, diffPDF );
diffCDF = absdiff( cdf[ i ], rayleighCDFValues[ i ] );
maxDiffCDF = max( maxDiffCDF, diffCDF );
}
console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF:', maxDiffPDF );
console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF:', maxDiffCDF );
console.log( 'Maximum difference between Chi(k=2) PDF and Rayleigh PDF: ', maxDiffPDF );
console.log( 'Maximum difference between Chi(k=2) CDF and Rayleigh CDF: ', maxDiffCDF );
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ var interarrivalTimes = randomExponential( numCustomers, lambda, {
'dtype': 'float64'
});

console.log( 'Simulated interarrival times for ' + numCustomers + ' customers:' );
console.log( 'Simulated interarrival times for ' + numCustomers + ' customers: ' );
console.log( interarrivalTimes );

// Calculate cumulative arrival times by computing the cumulative sum of interarrival times:
var arrivalTimes = new Float64Array( interarrivalTimes.length );
dcusum( interarrivalTimes.length, 0.0, interarrivalTimes, 1, arrivalTimes, 1 );

console.log( '\nCustomer arrival times:' );
console.log( '\nCustomer arrival times: ' );
console.log( arrivalTimes );

// Probability that a customer arrives within two minutes:
Expand All @@ -153,7 +153,7 @@ console.log( 'PDF at x = 1: ' + out.toFixed(4) );

// Evaluate the MGF at t = 0.1:
out = dist.mgf( 0.1 );
console.log( 'MGF at t = 0.5: ' + out.toFixed(4) );
console.log( 'MGF at t = 0.1: ' + out.toFixed(4) );
```

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ var interarrivalTimes = randomExponential( numCustomers, lambda, {
'dtype': 'float64'
});

console.log( 'Simulated interarrival times for ' + numCustomers + ' customers:' );
console.log( 'Simulated interarrival times for ' + numCustomers + ' customers: ' );
console.log( interarrivalTimes );

// Calculate cumulative arrival times by computing the cumulative sum of interarrival times:
var arrivalTimes = new Float64Array( interarrivalTimes.length );
dcusum( interarrivalTimes.length, 0.0, interarrivalTimes, 1, arrivalTimes, 1 );

console.log( '\nCustomer arrival times:' );
console.log( '\nCustomer arrival times: ' );
console.log( arrivalTimes );

// Probability that a customer arrives within two minutes:
Expand All @@ -62,4 +62,4 @@ console.log( 'PDF at x = 1: ' + out.toFixed(4) );

// Evaluate the MGF at t = 0.1:
out = dist.mgf( 0.1 );
console.log( 'MGF at t = 0.5: ' + out.toFixed(4) );
console.log( 'MGF at t = 0.1: ' + out.toFixed(4) );
38 changes: 19 additions & 19 deletions lib/node_modules/@stdlib/stats/base/dists/geometric/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,20 @@ var geometricCDF = geometric.cdf.factory( p );
var cdf = filledarrayBy( x.length, 'float64', geometricCDF );

// Output the PMF and CDF values:
console.log( 'x values:', x );
console.log( 'PMF values:', pmf );
console.log( 'CDF values:', cdf );
console.log( 'x values: ', x );
console.log( 'PMF values: ', pmf );
console.log( 'CDF values: ', cdf );

// Compute statistical properties:
var theoreticalMean = geometric.mean( p );
var theoreticalVariance = geometric.variance( p );
var theoreticalSkewness = geometric.skewness( p );
var theoreticalKurtosis = geometric.kurtosis( p );

console.log( 'Theoretical Mean:', theoreticalMean );
console.log( 'Theoretical Variance:', theoreticalVariance );
console.log( 'Skewness:', theoreticalSkewness );
console.log( 'Kurtosis:', theoreticalKurtosis );
console.log( 'Theoretical Mean: ', theoreticalMean );
console.log( 'Theoretical Variance: ', theoreticalVariance );
console.log( 'Skewness: ', theoreticalSkewness );
console.log( 'Kurtosis: ', theoreticalKurtosis );

// Generate random samples from the geometric distribution:
var rgeom = geometricRandomFactory( p );
Expand All @@ -160,19 +160,19 @@ var samples = filledarrayBy( n, 'float64', rgeom );
var sampleMean = mean( n, samples, 1 );
var sampleVariance = variance( n, 1, samples, 1 );

console.log( 'Sample Mean:', sampleMean );
console.log( 'Sample Variance:', sampleVariance );
console.log( 'Sample Mean: ', sampleMean );
console.log( 'Sample Variance: ', sampleVariance );

// Demonstrate the memoryless property:
var s = 2.0;
var t = 3.0;
var prob1 = ( 1.0 - geometric.cdf( s + t - 1.0, p ) ) /
( 1.0 - geometric.cdf( s - 1.0, p ));
( 1.0 - geometric.cdf( s - 1.0, p ) );
var prob2 = 1.0 - geometric.cdf( t - 1.0, p );

console.log( 'P(X > s + t | X > s):', prob1 );
console.log( 'P(X > t):', prob2 );
console.log( 'Difference:', abs( prob1 - prob2 ) );
console.log( 'P(X > s + t | X > s): ', prob1 );
console.log( 'P(X > t): ', prob2 );
console.log( 'Difference: ', abs( prob1 - prob2 ) );

// Demonstrate that the sum of k independent geometric random variables follows a negative binomial distribution:
var k = 5;
Expand All @@ -194,14 +194,14 @@ var sumSampleVariance = variance( n, 1, sumSamples, 1 );
var nbMean = negativeBinomial.mean( k, p );
var nbVariance = negativeBinomial.variance( k, p );

console.log( 'Sum Sample Mean:', sumSampleMean );
console.log( 'Sum Sample Variance:', sumSampleVariance );
console.log( 'Negative Binomial Mean:', nbMean );
console.log( 'Negative Binomial Variance:', nbVariance );
console.log( 'Sum Sample Mean: ', sumSampleMean );
console.log( 'Sum Sample Variance: ', sumSampleVariance );
console.log( 'Negative Binomial Mean: ', nbMean );
console.log( 'Negative Binomial Variance: ', nbVariance );

// Compare sample statistics to theoretical values:
console.log( 'Difference in Mean:', abs( nbMean - sumSampleMean ) );
console.log( 'Difference in Variance:', abs( nbVariance - sumSampleVariance ) );
console.log( 'Difference in Mean: ', abs( nbMean - sumSampleMean ) );
console.log( 'Difference in Variance: ', abs( nbVariance - sumSampleVariance ) );
```

</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ var geometricCDF = geometric.cdf.factory( p );
var cdf = filledarrayBy( x.length, 'float64', geometricCDF );

// Output the PMF and CDF values:
console.log( 'x values:', x );
console.log( 'PMF values:', pmf );
console.log( 'CDF values:', cdf );
console.log( 'x values: ', x );
console.log( 'PMF values: ', pmf );
console.log( 'CDF values: ', cdf );

// Compute statistical properties:
var theoreticalMean = geometric.mean( p );
var theoreticalVariance = geometric.variance( p );
var theoreticalSkewness = geometric.skewness( p );
var theoreticalKurtosis = geometric.kurtosis( p );

console.log( 'Theoretical Mean:', theoreticalMean );
console.log( 'Theoretical Variance:', theoreticalVariance );
console.log( 'Skewness:', theoreticalSkewness );
console.log( 'Kurtosis:', theoreticalKurtosis );
console.log( 'Theoretical Mean: ', theoreticalMean );
console.log( 'Theoretical Variance: ', theoreticalVariance );
console.log( 'Skewness: ', theoreticalSkewness );
console.log( 'Kurtosis: ', theoreticalKurtosis );

// Generate random samples from the geometric distribution:
var rgeom = geometricRandomFactory( p );
Expand All @@ -66,19 +66,19 @@ var samples = filledarrayBy( n, 'float64', rgeom );
var sampleMean = mean( n, samples, 1 );
var sampleVariance = variance( n, 1, samples, 1 );

console.log( 'Sample Mean:', sampleMean );
console.log( 'Sample Variance:', sampleVariance );
console.log( 'Sample Mean: ', sampleMean );
console.log( 'Sample Variance: ', sampleVariance );

// Demonstrate the memoryless property:
var s = 2.0;
var t = 3.0;
var prob1 = ( 1.0 - geometric.cdf( s + t - 1.0, p ) ) /
( 1.0 - geometric.cdf( s - 1.0, p ));
( 1.0 - geometric.cdf( s - 1.0, p ) );
var prob2 = 1.0 - geometric.cdf( t - 1.0, p );

console.log( 'P(X > s + t | X > s):', prob1 );
console.log( 'P(X > t):', prob2 );
console.log( 'Difference:', abs( prob1 - prob2 ) );
console.log( 'P(X > s + t | X > s): ', prob1 );
console.log( 'P(X > t): ', prob2 );
console.log( 'Difference: ', abs( prob1 - prob2 ) );

// Demonstrate that the sum of k independent geometric random variables follows a negative binomial distribution:
var k = 5;
Expand All @@ -100,11 +100,11 @@ var sumSampleVariance = variance( n, 1, sumSamples, 1 );
var nbMean = negativeBinomial.mean( k, p );
var nbVariance = negativeBinomial.variance( k, p );

console.log( 'Sum Sample Mean:', sumSampleMean );
console.log( 'Sum Sample Variance:', sumSampleVariance );
console.log( 'Negative Binomial Mean:', nbMean );
console.log( 'Negative Binomial Variance:', nbVariance );
console.log( 'Sum Sample Mean: ', sumSampleMean );
console.log( 'Sum Sample Variance: ', sumSampleVariance );
console.log( 'Negative Binomial Mean: ', nbMean );
console.log( 'Negative Binomial Variance: ', nbVariance );

// Compare sample statistics to theoretical values:
console.log( 'Difference in Mean:', abs( nbMean - sumSampleMean ) );
console.log( 'Difference in Variance:', abs( nbVariance - sumSampleVariance ) );
console.log( 'Difference in Mean: ', abs( nbMean - sumSampleMean ) );
console.log( 'Difference in Variance: ', abs( nbVariance - sumSampleVariance ) );

1 comment on commit 43e7a33

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage Report

Package Statements Branches Functions Lines
assert/is-same-typed-array-like $\color{green}122/122$
$\color{green}+100.00\%$
$\color{green}6/6$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}122/122$
$\color{green}+100.00\%$
iter/cunone $\color{green}205/205$
$\color{green}+100.00\%$
$\color{green}17/17$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}205/205$
$\color{green}+100.00\%$
stats/base/dists/chi $\color{green}150/150$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}0/0$
$\color{green}+100.00\%$
$\color{green}150/150$
$\color{green}+100.00\%$
stats/base/dists/exponential $\color{green}177/177$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}0/0$
$\color{green}+100.00\%$
$\color{green}177/177$
$\color{green}+100.00\%$
stats/base/dists/geometric $\color{green}177/177$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}0/0$
$\color{green}+100.00\%$
$\color{green}177/177$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.