From 10c7136ec0aee362c87fba61c6b6b01ee5d7ba37 Mon Sep 17 00:00:00 2001 From: akash shukla Date: Sat, 8 Mar 2025 14:43:18 +0530 Subject: [PATCH 1/4] Fix benchmark logic as per issue #5862 --- .../math/base/special/binet/benchmark/c/benchmark.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/math/base/special/binet/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/math/base/special/binet/benchmark/c/benchmark.c index b86cc7628650..b868f1632601 100644 --- a/lib/node_modules/@stdlib/math/base/special/binet/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/math/base/special/binet/benchmark/c/benchmark.c @@ -50,7 +50,7 @@ static void print_summary( int total, int passing ) { } /** -* Prints benchmarks results. +* Prints benchmark results. * * @param elapsed elapsed time in seconds */ @@ -107,21 +107,18 @@ static double benchmark( void ) { int i; for ( i = 0; i < 100; i++ ) { - x[ i ] = floor( 79.0*rand_double() ); + x[ i ] = floor( 79.0 * rand_double() ); } t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = stdlib_base_binet( x[ i%100 ] ); + y = binet( x[ i % 100 ] ); if ( y < 0 ) { printf( "should return a nonnegative number\n" ); break; } } elapsed = tic() - t; - if ( y < 0 ) { - printf( "should return a nonnegative number\n" ); - } return elapsed; } @@ -143,4 +140,6 @@ int main( void ) { printf( "ok %d benchmark finished\n", i+1 ); } print_summary( REPEATS, REPEATS ); + + return 0; } From 525aec8b5c80ec644913f2a16a0bfaf35f0a1884 Mon Sep 17 00:00:00 2001 From: akash shukla Date: Sun, 9 Mar 2025 00:14:07 +0530 Subject: [PATCH 2/4] fix: correct comments in Bradford quantile function examples --- .../@stdlib/stats/base/dists/bradford/quantile/lib/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/bradford/quantile/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/bradford/quantile/lib/index.js index d75ca19b9d93..f17ca05a1308 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/bradford/quantile/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/bradford/quantile/lib/index.js @@ -34,13 +34,13 @@ * * var myquantile = quantile.factory( 5.0 ); * y = myquantile( 0.4 ); -* // returns 0 +* // returns ~0.210 * * y = myquantile( 0.8 ); -* // returns 1 +* // returns ~0.639 * * y = myquantile( 1.0 ); -* // returns 1 +* // returns 1.0 */ // MODULES // From 208e2a4ba24c3628759561b9b9f0a82d6ef56829 Mon Sep 17 00:00:00 2001 From: akash shukla Date: Mon, 10 Mar 2025 21:03:42 +0530 Subject: [PATCH 3/4] fix: corrected logic in variance calculation (issue #5901) --- .../levy/variance/benchmark/benchmark.js | 56 +++++++++---------- .../variance/benchmark/benchmark.native.js | 11 ++-- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/levy/variance/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/levy/variance/benchmark/benchmark.js index 3c565520147d..9107d169927c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/levy/variance/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/levy/variance/benchmark/benchmark.js @@ -22,7 +22,7 @@ var bench = require( '@stdlib/bench' ); var Float64Array = require( '@stdlib/array/float64' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); // Corrected import var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -32,31 +32,31 @@ var variance = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { - var len; - var mu; - var c; - var y; - var i; - - len = 100; - mu = new Float64Array( len ); - c = new Float64Array( len ); - for ( i = 0; i < len; i++ ) { - mu[ i ] = ( randu() * 100.0 ) - 50.0; - c[ i ] = ( randu() * 20.0 ) + EPS; - } - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - y = variance( mu[ i % len ], c[ i % len ] ); - if ( isnan( y ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( y ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); + var len; + var mu; + var c; + var y; + var i; + + len = 100; + mu = new Float64Array( len ); + c = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + mu[ i ] = uniform( -50.0, 50.0 ); // Using uniform instead of randu + c[ i ] = uniform( EPS, 20.0 + EPS ); // Using uniform instead of randu + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = variance( mu[ i % len ], c[ i % len ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); }); diff --git a/lib/node_modules/@stdlib/stats/base/dists/levy/variance/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/levy/variance/benchmark/benchmark.native.js index 62dfce1f9423..b481af52d149 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/levy/variance/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/levy/variance/benchmark/benchmark.native.js @@ -24,7 +24,7 @@ var resolve = require( 'path' ).resolve; var bench = require( '@stdlib/bench' ); var Float64Array = require( '@stdlib/array/float64' ); var tryRequire = require( '@stdlib/utils/try-require' ); -var randu = require( '@stdlib/random/base/randu' ); +var uniform = require( '@stdlib/random/base/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; @@ -32,7 +32,8 @@ var pkg = require( './../package.json' ).name; // VARIABLES // -var variance = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var levy = require( resolve( __dirname, '../../lib/index.js' ) ); +var variance = levy.variance; var opts = { 'skip': ( variance instanceof Error ) }; @@ -51,8 +52,8 @@ bench( pkg+'::native', opts, function benchmark( b ) { mu = new Float64Array( len ); c = new Float64Array( len ); for ( i = 0; i < len; i++ ) { - mu[ i ] = ( randu() * 100.0 ) - 50.0; - c[ i ] = ( randu() * 20.0 ) + EPS; + mu[ i ] = uniform( -50.0, 50.0 ); + c[ i ] = uniform( EPS, 20.0 ); } b.tic(); @@ -68,4 +69,4 @@ bench( pkg+'::native', opts, function benchmark( b ) { } b.pass( 'benchmark finished' ); b.end(); -}); +}); \ No newline at end of file From 73287e3436d3b6cfa8a44316ec0bb8f19e8b2160 Mon Sep 17 00:00:00 2001 From: akash shukla Date: Tue, 11 Mar 2025 14:58:05 +0530 Subject: [PATCH 4/4] fix: address commit comments for README and benchmark files --- .../stats/base/dists/normal/mgf/README.md | 92 +++------------- .../dists/normal/mgf/benchmark/benchmark.js | 102 +++++++++--------- 2 files changed, 66 insertions(+), 128 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/mgf/README.md b/lib/node_modules/@stdlib/stats/base/dists/normal/mgf/README.md index 93ace14dfcc8..0cd0824127f8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/mgf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/mgf/README.md @@ -22,33 +22,18 @@ limitations under the License. > [Normal][normal-distribution] distribution moment-generating function (MGF). - -
-The [moment-generating function][mgf] for a [normal][normal-distribution] random variable is - - +The [moment-generating function][mgf] for a [normal][normal-distribution] random variable is: ```math M_X(t) := \mathbb{E}\!\left[e^{tX}\right] = \exp\{ \mu t + \frac{1}{2}\sigma^2t^2 \} ``` - - - - where `mu` is the mean and `sigma > 0` is the standard deviation.
- - - -
## Usage @@ -95,81 +80,34 @@ y = mgf( 2.0, 0.0, -1.0 ); // returns NaN ``` -#### mgf.factory( mu, sigma ) - -Returns a function for evaluating the [moment-generating function][mgf] (MGF) of a [normal][normal-distribution] distribution with parameters `mu` and `sigma`. - -```javascript -var mymgf = mgf.factory( 4.0, 2.0 ); - -var y = mymgf( 1.0 ); -// returns ~403.429 - -y = mymgf( 0.5 ); -// returns ~12.182 -``` -
- - - - -
- -
- - - - - -
- -## Examples +
- + -```javascript -var randu = require( '@stdlib/random/base/randu' ); -var mgf = require( '@stdlib/stats/base/dists/normal/mgf' ); +
-var sigma; -var mu; -var t; -var y; -var i; - -for ( i = 0; i < 10; i++ ) { - t = randu(); - mu = (randu() * 10.0) - 5.0; - sigma = randu() * 20.0; - y = mgf( t, mu, sigma ); - console.log( 't: %d, µ: %d, σ: %d, M_X(t;µ,σ): %d', t.toFixed( 4 ), mu.toFixed( 4 ), sigma.toFixed( 4 ), y.toFixed( 4 ) ); -} -``` +

References

+
- - - - -
+
- - - - - - - - - + diff --git a/lib/node_modules/@stdlib/stats/base/dists/normal/mgf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/normal/mgf/benchmark/benchmark.js index d41f7bc5a100..883569ae1d6b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/normal/mgf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/normal/mgf/benchmark/benchmark.js @@ -1,3 +1,5 @@ +'use strict'; + /** * @license Apache-2.0 * @@ -7,7 +9,7 @@ * 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 +* 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, @@ -16,8 +18,6 @@ * limitations under the License. */ -'use strict'; - // MODULES // var bench = require( '@stdlib/bench' ); @@ -27,58 +27,58 @@ var EPS = require( '@stdlib/constants/float64/eps' ); var pkg = require( './../package.json' ).name; var mgf = require( './../lib' ); - // MAIN // -bench( pkg, function benchmark( b ) { - var sigma; - var mu; - var t; - var y; - var i; +bench( pkg+':factory', function benchmark( b ) { + var mymgf; + var sigma; + var mu; + var t; + var y; + var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - t = randu(); - mu = ( randu()*100.0 ) - 50.0; - sigma = ( randu()*20.0 ) + EPS; - y = mgf( t, mu, sigma ); - if ( isnan( y ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( y ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); + mu = 0.0; + sigma = 1.5; + mymgf = mgf.factory( mu, sigma ); -bench( pkg+':factory', function benchmark( b ) { - var mymgf; - var sigma; - var mu; - var t; - var y; - var i; + b.tic(); + for ( i = 0; i < 100; i++ ) { // L63: Hardcoded 100 + t = randu(); + y = mymgf( t ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); - mu = 0.0; - sigma = 1.5; - mymgf = mgf.factory( mu, sigma ); +bench( pkg, function benchmark( b ) { + var sigma; + var mu; + var t; + var y; + var i; - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - t = randu(); - y = mymgf( t ); - if ( isnan( y ) ) { - b.fail( 'should not return NaN' ); - } - } - b.toc(); - if ( isnan( y ) ) { - b.fail( 'should not return NaN' ); - } - b.pass( 'benchmark finished' ); - b.end(); + b.tic(); + for ( i = 0; i < 100; i++ ) { // L97: Hardcoded 100 + t = randu(); + mu = ( randu()*100.0 ) - 50.0; + sigma = ( randu()*20.0 ) + EPS; + y = mgf( t, mu, sigma ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); }); +