From 8d24de80ec97678acb72e69834ee1e84f7ec9c59 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Mon, 12 Jan 2026 20:32:11 +0530 Subject: [PATCH 1/9] feat: add initial setup --- .../stats/base/dists/wald/cdf/README.md | 269 ++++++++++++++++++ .../dists/wald/cdf/benchmark/benchmark.js | 84 ++++++ .../wald/cdf/benchmark/benchmark.native.js | 68 +++++ .../base/dists/wald/cdf/benchmark/c/Makefile | 146 ++++++++++ .../dists/wald/cdf/benchmark/c/benchmark.c | 144 ++++++++++ .../dists/wald/cdf/benchmark/r/DESCRIPTION | 9 + .../dists/wald/cdf/benchmark/r/benchmark.R | 109 +++++++ .../stats/base/dists/wald/cdf/binding.gyp | 170 +++++++++++ .../stats/base/dists/wald/cdf/docs/repl.txt | 79 +++++ .../base/dists/wald/cdf/docs/types/index.d.ts | 115 ++++++++ .../base/dists/wald/cdf/docs/types/test.ts | 119 ++++++++ .../base/dists/wald/cdf/examples/c/Makefile | 146 ++++++++++ .../base/dists/wald/cdf/examples/c/example.c | 44 +++ .../base/dists/wald/cdf/examples/index.js | 36 +++ .../stats/base/dists/wald/cdf/include.gypi | 53 ++++ .../stdlib/stats/base/dists/wald/cdf.h | 38 +++ .../stats/base/dists/wald/cdf/lib/factory.js | 99 +++++++ .../stats/base/dists/wald/cdf/lib/index.js | 51 ++++ .../stats/base/dists/wald/cdf/lib/main.js | 111 ++++++++ .../stats/base/dists/wald/cdf/lib/native.js | 73 +++++ .../stats/base/dists/wald/cdf/manifest.json | 93 ++++++ .../stats/base/dists/wald/cdf/package.json | 71 +++++ .../stats/base/dists/wald/cdf/src/Makefile | 70 +++++ .../stats/base/dists/wald/cdf/src/addon.c | 22 ++ .../stats/base/dists/wald/cdf/src/main.c | 80 ++++++ .../wald/cdf/test/fixtures/julia/REQUIRE | 3 + .../wald/cdf/test/fixtures/julia/data.json | 1 + .../wald/cdf/test/fixtures/julia/runner.jl | 77 +++++ .../base/dists/wald/cdf/test/test.cdf.js | 172 +++++++++++ .../base/dists/wald/cdf/test/test.factory.js | 221 ++++++++++++++ .../stats/base/dists/wald/cdf/test/test.js | 38 +++ .../base/dists/wald/cdf/test/test.native.js | 181 ++++++++++++ 32 files changed, 2992 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/r/DESCRIPTION create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/r/benchmark.R create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/include/stdlib/stats/base/dists/wald/cdf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/factory.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/REQUIRE create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/data.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/runner.jl create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.cdf.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md new file mode 100644 index 000000000000..e171a0202015 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md @@ -0,0 +1,269 @@ + + +# Cumulative Distribution Function + +> [Wald][wald-distribution] distribution [cumulative distribution function][cdf]. + +
+ +The [cumulative distribution function][cdf] for a [Wald][wald-distribution] random variable is + +
+ + + +
+ +## Usage + +```javascript +var cdf = require( '@stdlib/stats/base/dists/wald/cdf' ); +``` + +#### cdf( x, mu, lambda ) + +Evaluates the [cumulative distribution function][cdf] (CDF) for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```javascript +var y = cdf( 2.0, 2.0, 1.0 ); +// returns ~0.713 + +y = cdf( 1.0, 2.0, 1.0 ); +// returns ~0.490 + +y = cdf( 4.0, 2.0, 1.0 ); +// returns ~0.873 +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = cdf( NaN, 2.0, 1.0 ); +// returns NaN + +y = cdf( 2.0, NaN, 1.0 ); +// returns NaN + +y = cdf( 2.0, 2.0, NaN ); +// returns NaN +``` + +If provided `mu <= 0` or `lambda < 0`, the function returns `NaN`. + +```javascript +var y = cdf( 2.0, 0.0, -3.0 ); +// returns NaN + +y = cdf( 2.0, -1.0, -2.0 ); +// returns NaN + +y = cdf( 2.0, -2.0, -1.0 ); +// returns NaN +``` + +If provided `x <= 0`, the function returns `0`. + +```javascript +var y = cdf( 0.0, 2.0, 1.0 ); +// returns 0.0 + +y = cdf( -1.0, 2.0, 1.0 ); +// returns 0.0 +``` + +If `lambda = 0`, the function evaluates the [CDF][cdf] of a [degenerate distribution][degenerate-distribution] centered at `mu`. + +```javascript +var y = cdf( 2.0, 8.0, 0.0 ); +// returns 0.0 + +y = cdf( 8.0, 8.0, 0.0 ); +// returns 1.0 + +y = cdf( 10.0, 8.0, 0.0 ); +// returns 1.0 +``` + +#### cdf.factory( mu, lambda ) + +Returns a function for evaluating the [cumulative distribution function][cdf] of a wald distribution with parameters `mu` and `lambda`. + +```javascript +var mycdf = cdf.factory( 1.0, 1.0 ); + +var y = mycdf( 2.0 ); +// returns ~0.885 + +y = mycdf( 8.0 ); +// returns ~0.998 +``` + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var cdf = require( '@stdlib/stats/base/dists/wald/cdf' ); + +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 10, EPS, 10.0, opts ); +var mu = uniform( 10, EPS, 10.0, opts ); +var lambda = uniform( 10, EPS, 20.0, opts ); + +logEachMap( 'x: %0.4f, µ: %0.4f, λ: %0.4f, f(x;µ,λ): %0.4f', x, mu, lambda, cdf ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/wald/cdf.h" +``` + +#### stdlib_base_dists_wald_cdf( x, mu, lambda ) + +Evaluates the [cumulative distribution function][cdf] (CDF) for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```c +double out = stdlib_base_dists_wald_cdf( 2.0, 1.0, 1.0 ); +// returns ~0.885 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **mu**: `[in] double` mean. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_wald_cdf( const double x, const double mu, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/wald/cdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double lambda; + double mu; + double x; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + x = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + mu = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + lambda = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + y = stdlib_base_dists_wald_cdf( x, mu, lambda ); + printf( "x: %lf, µ: %lf, λ: %lf, F(x;µ,λ): %lf\n", x, mu, lambda, y ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.js new file mode 100644 index 000000000000..34176004bd94 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var cdf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var lambda; + var len; + var mu; + var x; + var y; + var i; + + len = 100; + x = uniform( len, EPS, 100.0 ); + mu = uniform( len, EPS, 50.0 ); + lambda = uniform( len, EPS, 20.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cdf( x[ i % len ], mu[ i % len ], lambda[ 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(); +}); + +bench( format( '%s:factory', pkg ), function benchmark( b ) { + var mycdf; + var x; + var y; + var i; + + mycdf = cdf.factory( 1.0, 1.5 ); + x = uniform( 100, EPS, 10.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mycdf( x[ i % x.length ] ); + 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/wald/cdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..61a993e8c908 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var cdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cdf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var lambda; + var len; + var mu; + var x; + var y; + var i; + + len = 100; + x = uniform( len, EPS, 100.0 ); + mu = uniform( len, EPS, 50.0 ); + lambda = uniform( len, EPS, 20.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cdf( x[ i % len ], mu[ i % len ], lambda[ 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/wald/cdf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/c/Makefile new file mode 100644 index 000000000000..7b114bb8537f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..e57aa87cdc64 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/c/benchmark.c @@ -0,0 +1,144 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +#include "stdlib/stats/base/dists/wald/cdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "wald-cdf" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define LEN 100 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double lambda[ 100 ]; + double mu[ 100 ]; + double x[ 100 ]; + double elapsed; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 100.0 ); + mu[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 50.0 ); + lambda[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_wald_cdf( x[ i%100 ], mu[ i%100 ], lambda[ i%100 ] ); + if ( y != y ) { + printf( "should not return NaN\n" ); + break; + } + } + elapsed = tic() - t; + if ( y != y ) { + printf( "should not return NaN\n" ); + } + return elapsed; +} + +/** +* Main execution sequence. +*/ +int main( void ) { + double elapsed; + int i; + + // Use the current time to seed the random number generator: + srand( time( NULL ) ); + + print_version(); + for ( i = 0; i < REPEATS; i++ ) { + printf( "# c::%s\n", NAME ); + elapsed = benchmark(); + print_results( elapsed ); + printf( "ok %d benchmark finished\n", i+1 ); + } + print_summary( REPEATS, REPEATS ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/r/DESCRIPTION b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/r/DESCRIPTION new file mode 100644 index 000000000000..e494f25a67d1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/r/DESCRIPTION @@ -0,0 +1,9 @@ +Package: dinvgauss-benchmarks +Title: Benchmarks +Version: 0.0.0 +Authors@R: person("stdlib", "js", role = c("aut","cre")) +Description: Benchmarks. +Depends: R (>=3.4.0) +Imports: + microbenchmark +LazyData: true diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/r/benchmark.R b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/r/benchmark.R new file mode 100644 index 000000000000..48173180ff4c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/r/benchmark.R @@ -0,0 +1,109 @@ +#!/usr/bin/env Rscript +# +# @license Apache-2.0 +# +# Copyright (c) 2026 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. + +# Set the precision to 16 digits: +options( digits = 16L ); + +#' Run benchmarks. +#' +#' @examples +#' main(); +main <- function() { + # Define benchmark parameters: + name <- "dist-wald-cdf"; + iterations <- 1000000L; + repeats <- 3L; + + #' Print the TAP version. + #' + #' @examples + #' print_version(); + print_version <- function() { + cat( "TAP version 13\n" ); + } + + #' Print the TAP summary. + #' + #' @param total Total number of tests. + #' @param passing Total number of passing tests. + #' + #' @examples + #' print_summary( 3, 3 ); + print_summary <- function( total, passing ) { + cat( "#\n" ); + cat( paste0( "1..", total, "\n" ) ); # TAP plan + cat( paste0( "# total ", total, "\n" ) ); + cat( paste0( "# pass ", passing, "\n" ) ); + cat( "#\n" ); + cat( "# ok\n" ); + } + + #' Print benchmark results. + #' + #' @param iterations Number of iterations. + #' @param elapsed Elapsed time in seconds. + #' + #' @examples + #' print_results( 10000L, 0.131009101868 ); + print_results <- function( iterations, elapsed ) { + rate <- iterations / elapsed; + cat( " ---\n" ); + cat( paste0( " iterations: ", iterations, "\n" ) ); + cat( paste0( " elapsed: ", elapsed, "\n" ) ); + cat( paste0( " rate: ", rate, "\n" ) ); + cat( " ...\n" ); + } + + #' Run a benchmark. + #' + #' ## Notes + #' + #' * We compute and return a total "elapsed" time, rather than the minimum + #' evaluation time, to match benchmark results in other languages (e.g., + #' Python). + #' + #' + #' @param iterations Number of Iterations. + #' @return Elapsed time in seconds. + #' + #' @examples + #' elapsed <- benchmark( 10000L ); + benchmark <- function( iterations ) { + # Run the benchmarks: + results <- microbenchmark::microbenchmark( dinvgauss( runif( 1, .Machine$double.eps, 100.0 ), runif( 1, .Machine$double.eps, 50.0 ), runif( 1, .Machine$double.eps, 20.0 ) ), times = iterations ); + + # Sum all the raw timing results to get a total "elapsed" time: + elapsed <- sum( results$time ); + + # Convert the elapsed time from nanoseconds to seconds: + elapsed <- elapsed / 1.0e9; + + return( elapsed ); + } + + print_version(); + for ( i in 1:repeats ) { + cat( paste0( "# r::", name, "\n" ) ); + elapsed <- benchmark( iterations ); + print_results( iterations, elapsed ); + cat( paste0( "ok ", i, " benchmark finished", "\n" ) ); + } + print_summary( repeats, repeats ); +} + +main(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt new file mode 100644 index 000000000000..102612f01ab8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt @@ -0,0 +1,79 @@ + +{{alias}}( x, μ, λ ) + Evaluates the cumulative distribution function (CDF) for a Wald + distribution with mean `μ` and shape parameter `λ` at a value `x`. + + If provided `NaN` as any argument, the function returns `NaN`. + + If provided `λ <= 0`, the function returns `NaN`. + + Parameters + ---------- + x: number + Input value. + + μ: number + Mean parameter. + + λ: number + Shape parameter. + + Returns + ------- + out: number + Evaluated CDF. + + Examples + -------- + > var y = {{alias}}( 2.0, 1.0, 1.0 ) + ~0.885 + > y = {{alias}}( 0.5, 2.0, 3.0 ) + ~0.055 + > y = {{alias}}( -1.0, 4.0, 2.0 ) + 0.0 + > y = {{alias}}( NaN, 0.0, 1.0 ) + NaN + > y = {{alias}}( 0.0, NaN, 1.0 ) + NaN + > y = {{alias}}( 0.0, 0.0, NaN ) + NaN + + // Negative shape parameter: + > y = {{alias}}( 2.0, 1.0, -1.0 ) + NaN + + // Degenerate distribution when `λ = 0.0`: + > y = {{alias}}( 2.0, 8.0, 0.0 ) + 1.0 + > y = {{alias}}( 8.0, 8.0, 0.0 ) + 1.0 + > y = {{alias}}( 10.0, 8.0, 0.0 ) + 1.0 + + +{{alias}}.factory( μ, λ ) + Returns a function for evaluating the cumulative distribution function (CDF) + of a normal distribution with mean `μ` and shape parameter `λ`. + + Parameters + ---------- + μ: number + Mean parameter. + + λ: number + Shape parameter. + + Returns + ------- + cdf: Function + Cumulative distribution function (CDF). + + Examples + -------- + > var myCDF = {{alias}}.factory( 10.0, 2.0 ); + > var y = myCDF( 10.0 ) + ~0.776 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts new file mode 100644 index 000000000000..9d0ca23fd43c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts @@ -0,0 +1,115 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +// TypeScript Version: 4.1 + +/** +* Evaluates the cumulative distribution function (CDF) for a Wald distribution. +* +* @param x - input value +* @returns evaluated CDF +*/ +type Unary = ( x: number ) => number; + +/** +* Interface for the cumulative distribution function (CDF) of a Wald distribution. +*/ +interface CDF { + /** + * Evaluates the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. + * + * ## Notes + * + * - If provided `lambda <= 0`, the function returns `NaN`. + * + * @param x - input value + * @param mu - mean + * @param lambda - shape parameter + * @returns evaluated cumulative distribution function + * + * @example + * var y = cdf( 2.0, 1.0, 1.0 ); + * // returns ~0.885 + * + * @example + * var y = cdf( 0.5, 2.0, 3.0 ); + * // returns ~0.055 + * + * @example + * var y = cdf( -1.0, 4.0, 2.0 ); + * // returns NaN + * + * @example + * var y = cdf( NaN, 0.0, 1.0 ); + * // returns NaN + * + * @example + * var y = cdf( 0.0, NaN, 1.0 ); + * // returns NaN + * + * @example + * var y = cdf( 0.0, 0.0, NaN ); + * // returns NaN + * + * @example + * // Negative shape parameter: + * var y = cdf( 2.0, 0.0, -1.0 ); + * // returns NaN + */ + ( x: number, mu: number, sigma: number ): number; + + /** + * Returns a function for evaluating the cumulative distribution function (CDF) for a Wald distribution. + * + * @param mu - mean + * @param lambda - shape parameter + * @returns function to evaluate the cumulative distribution function + * + * @example + * var myCDF = cdf.factory( 10.0, 2.0 ); + * var y = myCDF( 10.0 ); + * // returns ~0.776 + * + * y = myCDF( 12.0 ); + * // returns ~0.807 + */ + factory( mu: number, lambda: number ): Unary; +} + +/** +* Normal distribution cumulative distribution function (CDF). +* +* @param x - input value +* @param mu - mean +* @param lambda - shape parameter +* @returns evaluated CDF +* +* @example +* var y = cdf( 2.0, 1.0, 1.0 ); +* // returns ~0.885 +* +* var myCDF = cdf.factory( 10.0, 2.0 ); +* y = myCDF( 10.0 ); +* // returns ~0.776 +*/ +declare var cdf: CDF; + + +// EXPORTS // + +export = cdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/test.ts new file mode 100644 index 000000000000..68240f51cfb8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/test.ts @@ -0,0 +1,119 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +import cdf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + cdf( 2, 2, 4 ); // $ExpectType number + cdf( 1, 2, 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than three numbers... +{ + cdf( true, 3, 6 ); // $ExpectError + cdf( false, 2, 4 ); // $ExpectError + cdf( '5', 1, 2 ); // $ExpectError + cdf( [], 1, 2 ); // $ExpectError + cdf( {}, 2, 4 ); // $ExpectError + cdf( ( x: number ): number => x, 2, 4 ); // $ExpectError + + cdf( 9, true, 12 ); // $ExpectError + cdf( 9, false, 12 ); // $ExpectError + cdf( 5, '5', 10 ); // $ExpectError + cdf( 8, [], 16 ); // $ExpectError + cdf( 9, {}, 18 ); // $ExpectError + cdf( 8, ( x: number ): number => x, 16 ); // $ExpectError + + cdf( 9, 5, true ); // $ExpectError + cdf( 9, 5, false ); // $ExpectError + cdf( 5, 2, '5' ); // $ExpectError + cdf( 8, 4, [] ); // $ExpectError + cdf( 9, 4, {} ); // $ExpectError + cdf( 8, 5, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cdf(); // $ExpectError + cdf( 2 ); // $ExpectError + cdf( 2, 0 ); // $ExpectError + cdf( 2, 0, 4, 1 ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + cdf.factory( 3, 4 ); // $ExpectType Unary +} + +// The `factory` method returns a function which returns a number... +{ + const fcn = cdf.factory( 3, 4 ); + fcn( 2 ); // $ExpectType number +} + +// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... +{ + const fcn = cdf.factory( 3, 4 ); + fcn( true ); // $ExpectError + fcn( false ); // $ExpectError + fcn( '5' ); // $ExpectError + fcn( [] ); // $ExpectError + fcn( {} ); // $ExpectError + fcn( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... +{ + const fcn = cdf.factory( 3, 4 ); + fcn(); // $ExpectError + fcn( 2, 0 ); // $ExpectError + fcn( 2, 0, 1 ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided values other than two numbers... +{ + cdf.factory( true, 3 ); // $ExpectError + cdf.factory( false, 2 ); // $ExpectError + cdf.factory( '5', 1 ); // $ExpectError + cdf.factory( [], 1 ); // $ExpectError + cdf.factory( {}, 2 ); // $ExpectError + cdf.factory( ( x: number ): number => x, 2 ); // $ExpectError + + cdf.factory( 9, true ); // $ExpectError + cdf.factory( 9, false ); // $ExpectError + cdf.factory( 5, '5' ); // $ExpectError + cdf.factory( 8, [] ); // $ExpectError + cdf.factory( 9, {} ); // $ExpectError + cdf.factory( 8, ( x: number ): number => x ); // $ExpectError + + cdf.factory( [], true ); // $ExpectError + cdf.factory( {}, false ); // $ExpectError + cdf.factory( false, '5' ); // $ExpectError + cdf.factory( {}, [] ); // $ExpectError + cdf.factory( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + cdf.factory( 0 ); // $ExpectError + cdf.factory( 0, 4, 8 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/c/example.c new file mode 100644 index 000000000000..14a77c0aec07 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/c/example.c @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +#include "stdlib/stats/base/dists/wald/cdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double lambda; + double mu; + double x; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + x = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + mu = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + lambda = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + y = stdlib_base_dists_wald_cdf( x, mu, lambda ); + printf( "x: %lf, µ: %lf, λ: %lf, F(x;µ,λ): %lf\n", x, mu, lambda, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js new file mode 100644 index 000000000000..83b0b0d40adf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var cdf = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 10, EPS, 10.0, opts ); +var mu = uniform( 10, EPS, 10.0, opts ); +var lambda = uniform( 10, EPS, 20.0, opts ); + +logEachMap( 'x: %0.4f, µ: %0.4f, λ: %0.4f, f(x;µ,λ): %0.4f', x, mu, lambda, cdf ); + + +console.log( cdf( 2.0, 1.0, 1.0 ) ); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + */ + function cdf( x ) { + var z; + var t1; + var t2; + + if ( isnan( x ) ) { + return NaN; + } + if ( x <= 0.0 ) { + return 0.0; + } + z = sqrt( lambda / x ); + t1 = phi( z * ( x / mu - 1.0 ) ); + t2 = C * phi( -z * ( x / mu + 1.0 ) ); + return t1 + t2; + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/index.js new file mode 100644 index 000000000000..24beed461783 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/index.js @@ -0,0 +1,51 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Wald distribution cumulative distribution function (CDF). +* +* @module @stdlib/stats/base/dists/wald/cdf +* +* @example +* var cdf = require( '@stdlib/stats/base/dists/wald/cdf' ); +* +* var y = cdf( 2.0, 1.0, 1.0 ); +* // returns ~0.885 +* +* var myCDF = cdf.factory( 2.0, 1.0 ); +* y = myCDF( 2.0 ); +* // returns ~0.713 +*/ + +// 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; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js new file mode 100644 index 000000000000..6b21debece0c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js @@ -0,0 +1,111 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 exp = require( '@stdlib/math/base/special/exp' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var normalCDF = require( '@stdlib/stats/base/dists/normal/cdf' ).factory + + +// MAIN // + +/** +* Evaluates the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. +* +* @param {number} x - input value +* @param {number} mu - mean +* @param {NonNegativeNumber} lambda - shape parameter +* @returns {Probability} evaluated cumulative distribution function +* +* @example +* var y = cdf( 2.0, 1.0, 1.0 ); +* // returns ~0.885 +* +* @example +* var y = cdf( 0.5, 2.0, 3.0 ); +* // returns ~0.055 +* +* @example +* var y = cdf( NaN, 1.0, 1.0 ); +* // returns NaN +* +* @example +* var y = cdf( 1.0, NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = cdf( 1.0, 1.0, NaN ); +* // returns NaN +* +* @example +* // Non-positive mean: +* var y = cdf( 2.0, 0.0, 1.0 ); +* // returns NaN +* +* @example +* // Negative shape parameter: +* var y = cdf( 2.0, 1.0, -1.0 ); +* // returns NaN +* +* @example +* // Zero shape parameter (degenerate distribution): +* var y = cdf( 1.0, 1.0, 0.0 ); +* // returns 1.0 +* +* @example +* var y = cdf( 0.0, 1.0, 1.0 ); +* // returns 0.0 +*/ +function cdf( x, mu, lambda ) { + var C; + var z; + var t1; + var t2; + var phi; + + if ( + isnan( x ) || + isnan( mu ) || + isnan( lambda ) || + mu <= 0.0 || + lambda < 0.0 + ) { + return NaN; + } + if ( lambda == 0.0 ) { + return ( x < mu ) ? 0.0 : 1.0; + } + if ( x <= 0.0 ) { + return 0.0; + } + phi = normalCDF( 0.0, 1.0 ); + C = exp( 2.0 * lambda / mu ); + z = sqrt( lambda / x ); + t1 = phi( z * ( x / mu - 1.0 ) ); + t2 = C * phi( -z * ( x / mu + 1.0 ) ); + return t1 + t2; +} + + +// EXPORTS // + +module.exports = cdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js new file mode 100644 index 000000000000..8e359426b4f5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js @@ -0,0 +1,73 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. +* +* @private +* @param {number} x - input value +* @param {number} mu - mean +* @param {number} lambda - shape parameter +* @returns {Probability} evaluated cumulative distribution function +* +* @example +* var y = cdf( 2.0, 1.0, 1.0 ); +* // returns ~0.855 +* +* @example +* var y = cdf( 0.5, 2.0, 3.0 ); +* // returns ~0.055 +* +* @example +* var y = cdf( -1.0, 4.0, 2.0 ); +* // returns NaN +* +* @example +* var y = cdf( NaN, 0.0, 1.0 ); +* // returns NaN +* +* @example +* var y = cdf( 0.0, NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = cdf( 0.0, 0.0, NaN ); +* // returns NaN +* +* @example +* // Negative shape parameter: +* var y = cdf( 2.0, 0.0, -1.0 ); +* // returns NaN +*/ +function cdf( x, mu, lambda ) { + return addon( x, mu, lambda ); +} + + +// EXPORTS // + +module.exports = cdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json new file mode 100644 index 000000000000..65af662cb405 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json @@ -0,0 +1,93 @@ +{ + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/ternary", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/exp", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/constants/float64/pinf" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/exp", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/eps" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/exp", + "@stdlib/stats/base/dists/normal/cdf", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/eps" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json new file mode 100644 index 000000000000..6d8c93d9a825 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/stats/base/dists/wald/cdf", + "version": "0.0.0", + "description": "Wald distribution cumulative distribution function (CDF).", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "dist", + "probability", + "cdf", + "cumulative distribution", + "distribution function", + "inverse", + "gaussian", + "wald", + "univariate", + "continuous" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/addon.c new file mode 100644 index 000000000000..3ae24c620f82 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +#include "stdlib/stats/base/dists/wald/cdf.h" +#include "stdlib/math/base/napi/ternary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_wald_cdf ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c new file mode 100644 index 000000000000..ee8e8fb2766f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c @@ -0,0 +1,80 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +*/ + +#include "stdlib/stats/base/dists/wald/cdf.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/math/base/special/exp.h" +#include "stdlib/math/base/special/erfc.h" +#include "stdlib/stats/base/dists/normal/cdf.h" +#include "stdlib/constants/float64/pinf.h" + +/** +* Evaluates the standard normal CDF Φ(x). +* +* Φ(x) = 0.5 * erfc( -x / sqrt(2) ) +* +* @param x input value +* @return Standard noraml CDF +*/ +static double stdnormal_cdf( const double x ) { + return 0.5 * stdlib_base_erfc( -x * ( x / stdlib_base_sqrt( 2.0 ) ) ); +} + +/** +* Evaluates the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. +* +* @param x input value +* @param mu mean +* @param lambda shape parameter +* @return evaluated cumulative distribution function +* +* @example +* double y = stdlib_base_dists_wald_cdf( 2.0, 1.0, 1.0 ); +* // returns ~0.885 +*/ +double stdlib_base_dists_wald_cdf( const double x, const double mu, const double lambda ) { + double C; + double z; + double t1; + double t2; + + if ( + stdlib_base_is_nan( x ) || + stdlib_base_is_nan( mu ) || + stdlib_base_is_nan( lambda ) || + mu <= 0.0 || + lambda < 0.0 + ) { + return 0.0/0.0; // NaN + } + if ( lambda == 0.0 ) { + return ( x < mu ) ? 0.0 : 1.0; + } + if ( x <= 0.0 ) { + return 0.0; + } + if ( x == STDLIB_CONSTANT_FLOAT64_PINF ) { + return 1.0; + } + C = stdlib_base_exp( 2.0 * lambda / mu ); + z = stdlib_base_sqrt( lambda / x ); + t1 = stdnormal_cdf( z * ( x / mu - 1.0 ) ); + t2 = C * stdnormal_cdf( -z * ( x / mu + 1.0 ) ); + return t1 + t2; +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/REQUIRE @@ -0,0 +1,3 @@ +Distributions 0.23.8 +julia 1.5 +JSON 0.21 diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/data.json new file mode 100644 index 000000000000..ddb9531d856f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"expected":[0.956031860972232,0.7222410074214104,0.8388262233512366,0.8063887690741013,0.8993139816208725,0.8754608601606477,0.999857458956787,0.5446625611270753,0.9999219753683246,0.7007193572895988,0.05086146646705278,0.9609072030079305,0.9252233812473168,0.7958070715252243,0.8856198861175603,0.8616320127365377,0.5569342708856,0.6376098409431302,0.8121774439437746,0.5858488156886867,0.8171722709992562,0.6660520279350101,0.768927369212703,0.8409556904974325,0.3930698331676592,0.9089425375062343,0.800636475911108,0.9423977609194308,0.9732221977795502,0.8791812378672993,0.7866151725297192,0.6962333142145349,0.98350473578428,0.5792110472701381,0.7789599352514637,0.8630046536813258,0.9234734033401704,0.93882411947924,0.8684156693232986,0.41248050205809866,0.9192555074415594,0.9592077588644018,0.8394361950927777,0.860700802122654,0.9999999999949734,0.996688525144456,0.8918301639069863,0.847082670992373,0.7535769524105298,0.7924197892407122,0.9741000985461694,0.9996560104745966,0.9218095060200042,0.9710744180680723,0.7018774730314714,0.7405146608193169,0.27411061858629243,0.7333264345523395,0.9999999987532546,0.8914927886458963,0.7883964267140454,0.9999999942442925,0.9135916155064817,1.0,0.4319246946453399,0.9250238576511429,0.7860620958440139,0.6831537509896327,0.80676499801222,0.9939896265478079,0.9324940259747342,0.8793211283380593,0.6514949014453674,0.764372969376012,0.9009677859775579,0.658985893632694,0.8725109653410115,0.5214717769434215,0.9783763207358217,0.9563876792800233,0.9999999975726171,0.9092384901183699,0.9998834526817215,0.9481714276277563,0.8415257350164043,0.8882108308915957,0.7087396828351278,0.9999999999863065,0.874653119480443,0.9314179379685698,0.9986242241761004,0.9999999998862069,1.0,0.9244768544152053,0.9980933741882426,0.7448978634354545,1.0,0.9999914987850471,0.7974936479566863,0.9726371937648199],"x":[13.339281437460926,8.912977822167623,7.957102979390953,12.35436075718989,12.339969578719508,9.426438819747993,7.668296686294445,2.1692153609558864,3.4011347534176264,4.316025794292218,0.9229530194288167,12.963376756163369,12.579123639323475,9.42877594141134,13.138345132228055,14.638348080601085,3.2260969229502034,1.9913522817051794,12.776384124822453,5.024551384281849,2.7721049432643445,2.3868544647055563,5.257862949798037,13.812211159458977,2.4862822750483264,14.590746978893641,6.4403741375779155,12.611340074957582,6.457315339899419,13.825962721789326,4.452905814552913,7.692526981282094,10.546791344686156,3.1270439637182728,4.834256558797152,6.077225515583834,14.585076117850093,7.962641893506339,10.58892375842925,3.0697152886318437,13.33067599052857,15.01262679185554,5.152307422328827,8.872690692769739,15.154656348820843,9.01678384855629,12.393058949720189,12.06997916590109,8.003819435019004,11.948335659807748,13.713030468065579,5.1479634590575944,15.340185710069127,6.9659536427799145,3.0455122037183604,4.905635731970286,0.6814221257735477,4.215139415441513,10.11901634772521,14.889324187414767,8.156143098870603,11.271219164804084,5.202777507536254,15.229988224497541,1.9923931965184833,13.904761893546372,8.021688402301471,6.589330870271463,9.787917171979615,11.198896805725724,4.617404483308332,11.210732912052421,4.064462822290395,5.6565954384854065,10.46528011160431,5.1957240537306,11.974906110785032,3.680827180042188,12.591779723408235,9.011386213102261,15.050092105608336,13.426827000980886,14.794174426259755,14.377462361122904,8.558162962971371,12.638995058209323,2.4246318923228096,3.9757011380532896,13.369756594138892,13.845018861840108,11.299472587885253,11.644206825711048,15.377602790237713,15.468280067699677,9.38039592535914,7.1861475106420345,6.961492820897222,13.69799515148088,10.549343020608445,13.861341125809924],"lambda":[5.417493694832523,3.5238789952256355,3.5826503423369296,4.184161736888616,0.8192276763027957,3.8234223345936043,5.24402809615151,2.309116620114125,4.931035351845412,3.697177902023129,4.501040152049077,0.824316365749665,1.2608698335750619,3.898962176748363,1.9071768838155563,1.0661200524023957,1.737892413325985,1.0848520354174775,3.0524265066226564,4.53590051159232,1.5104329780565457,0.7030050012556267,4.170922611811294,4.18321781425974,4.493616146773953,1.5484848673662235,1.0672123408307272,2.550969419066164,4.240019299144688,2.1981332587295075,0.6206860389947129,5.135115262868535,3.0702149233353544,1.5707969073148815,1.5000651539453742,1.5176015099584297,3.5864184276547055,1.0268631923725597,0.8463599628736713,4.548706801031815,2.875127608083551,0.6875958040761105,1.3430356528748306,1.0547237778575038,2.9663969613697834,4.698529152765462,0.5210199539475586,2.173072691108242,2.7356096134666825,2.752535763924649,1.7634914482320796,3.7626355853845452,0.5800087175995862,4.959236947028113,1.525834277516708,0.7858374963721533,1.2274214567711716,0.7113886242245666,5.43845371287312,0.7690464980421842,1.4177051259025553,5.232575917856365,1.0883665720453035,5.1262093477379915,3.854078463131324,0.6832137945767492,2.0050045722480188,3.6146711847936275,1.9224041853642089,1.433517350792024,1.2181291874967266,3.7132086033156604,2.2047841616030497,4.234870757836539,5.488042283848636,2.1830671389382292,0.8362336779732822,3.4350849308482485,1.5279102835798999,5.377250049346257,3.160931851557253,3.4603513066608573,2.2861637737327833,4.603233814395376,1.5377032103904522,1.4260707211992152,0.988941315869017,5.382372903686453,5.414570172697367,3.7333515739305314,1.1346820229529104,2.1663751137306297,3.6307189578704184,1.1245714812983527,2.011184331744004,4.334090729997929,4.6898987995397,3.135883299543926,1.6494665397527486,0.6962598250060021],"mu":[4.5771270178283565,9.3038859744059,4.751722281845909,8.622974877299928,5.365916778152899,4.803906912583415,1.5325534802851288,3.2224329281058823,0.8644822375289214,4.011919264456063,6.823244256201491,2.778350896580743,4.150228657173185,6.766276040985014,6.042580299851276,10.208458752908047,8.658156905045317,2.835350340487461,9.145377871783827,6.887255654961294,1.8038160785970498,5.147573707948909,3.992401134498663,8.176927813847698,4.793060487504502,5.568353900405826,5.758055021819357,4.050259728920674,2.2345142248166567,6.647223601651859,5.341113052143289,7.635005091794672,2.623011728366624,7.510277907433075,3.969683058783067,3.212129974556723,5.481133786015191,2.418478449916674,6.403403094251223,6.376906389977452,5.037231671293051,3.095048794125324,3.0990537808571776,5.13411445216048,0.9674224972726893,2.1326067610011186,7.245593011100204,7.202350251207326,7.384763227640857,9.867527626581284,2.9942318005224298,1.1199702230489568,5.41025396282806,2.500518259740811,3.221200261662754,10.194295014059612,2.6719688263393477,9.034951928168692,1.1548691956614061,7.804069225669068,7.982762972431228,1.2588672904070015,2.0276911410334892,0.7361314763042155,3.2147938658289905,4.523033556030375,6.728967197191859,7.363485284959012,7.692277686051631,1.759800837729782,1.6645332784000517,5.51699948211175,5.365498592468808,4.367273775239145,4.948392272389236,7.829106616414316,7.2822988911752935,6.61862674845449,2.5674119529149104,3.38556043542913,1.1554783727393232,5.514779981695591,1.6138025966888931,4.9021119688877945,5.315381522103928,5.762061122219851,2.6969213971232806,0.6069810825927209,6.836374954246834,5.043637672806245,1.310431194116007,0.7800923422731771,0.8212929183510083,5.040283626021764,1.5125599301679544,6.054329705696015,0.5186875283592192,1.4946400377219333,10.083078015018645,2.4084751094236774]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..ac4ece6b1b62 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/fixtures/julia/runner.jl @@ -0,0 +1,77 @@ +#!/usr/bin/env julia +# +# @license Apache-2.0 +# +# Copyright (c) 2026 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. + +import Distributions: cdf, InverseGaussian +import JSON + +""" + gen( x, mu, lambda, name ) + +Generate fixture data and write to file. + +# Arguments + +* `x`: input value +* `mu`: mean +* `lambda`: shape parameter +* `name::AbstractString`: output filename + +# Examples + +``` julia +julia> x = rand( 1000 ) .* 15.0 .+ 0.1; +julia> mu = rand( 1000 ) .* 10.0 .+ 0.1; +julia> lambda = rand( 1000 ) .* 5.0 .+ 0.1; +julia> gen( x, mu, lambda, "data.json" ); +``` +""" +function gen( x, mu, lambda, name ) + z = Array{Float64}( undef, length(x) ); + for i in eachindex(x) + z[ i ] = cdf( InverseGaussian( mu[i], lambda[i] ), x[i] ); + end + + # Store data to be written to file as a collection: + data = Dict([ + ("x", x), + ("mu", mu), + ("lambda", lambda), + ("expected", z) + ]); + + # Based on the script directory, create an output filepath: + filepath = joinpath( dir, name ); + + # Write the data to the output filepath as JSON: + outfile = open( filepath, "w" ); + write( outfile, JSON.json(data) ); + write( outfile, "\n" ); + close( outfile ); +end + +# Get the filename: +file = @__FILE__; + +# Extract the directory in which this file resides: +dir = dirname( file ); + +# Generate fixtures: +x = rand( 100 ) .* 15.0 .+ 0.5; +mu = rand( 100 ) .* 10.0 .+ 0.5; +lambda = rand( 100 ) .* 5.0 .+ 0.5; +gen( x, mu, lambda, "data.json" ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.cdf.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.cdf.js new file mode 100644 index 000000000000..89e9143ce208 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.cdf.js @@ -0,0 +1,172 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var cdf = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = cdf( NaN, 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = cdf( 0.0, NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = cdf( 0.0, 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `+infinity` for `x` and a valid `mu` and `lambda`, the function returns `1`', function test( t ) { + var y = cdf( PINF, 1.0, 0.0 ); + t.strictEqual( y, 1.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `-infinity` for `x` and a valid `mu` and `lambda`, the function returns `0`', function test( t ) { + var y = cdf( NINF, 1.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a negative `lambda`, the function always returns `NaN`', function test( t ) { + var y; + + y = cdf( 2.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 0.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 2.0, 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 2.0, PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 2.0, NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 2.0, NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `lambda` equals `0`, the function evaluates a degenerate distribution centered at `mu`', function test( t ) { + var y; + + y = cdf( 2.0, 2.0, 0.0 ); + t.strictEqual( y, 1.0, 'returns 1 for x equal to mu' ); + + y = cdf( 3.0, 2.0, 0.0 ); + t.strictEqual( y, 1.0, 'returns 1 for x greater than mu' ); + + y = cdf( 1.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x smaller than mu' ); + + t.end(); +}); + +tape( 'the function evaluates the cdf for `x` (given positive `mu`)', function test( t ) { + var expected; + var lambda; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + y = cdf( x[i], mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); + +tape( 'the function evaluates the cdf for `x` ', function test( t ) { + var expected; + var lambda; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + y = cdf( x[i], mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); + +tape( 'the function evaluates the cdf for `x` (given negative `mu`)', function test( t ) { + var expected; + var lambda; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + y = cdf( x[i], mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 250 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js new file mode 100644 index 000000000000..1af3f6c9c633 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js @@ -0,0 +1,221 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var factory = require( './../lib/factory.js' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a function', function test( t ) { + var cdf = factory( 0.0, 1.0 ); + t.strictEqual( typeof cdf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the created function returns `NaN`', function test( t ) { + var cdf; + var y; + + cdf = factory( 0.0, 1.0 ); + y = cdf( NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + cdf = factory( NaN, 1.0 ); + y = cdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + cdf = factory( 1.0, NaN ); + y = cdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + cdf = factory( NaN, NaN ); + y = cdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + cdf = factory( NaN, NaN ); + y = cdf( NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a valid `mu` and `lambda`, the function returns a function which returns `1` when provided `+infinity` for `x`', function test( t ) { + var cdf; + var y; + + cdf = factory( 1.0, 0.0 ); + y = cdf( PINF ); + t.strictEqual( y, 1.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a valid `mu` and `lambda`, the function returns a function which returns `0` when provided `-infinity` for `x`', function test( t ) { + var cdf; + var y; + + cdf = factory( 1.0, 0.0 ); + y = cdf( NINF ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a negative `lambda`, the created function always returns `NaN`', function test( t ) { + var cdf; + var y; + + cdf = factory( 0.0, -1.0 ); + + y = cdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + cdf = factory( 0.0, NINF ); + y = cdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + cdf = factory( PINF, NINF ); + y = cdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + cdf = factory( NINF, NINF ); + y = cdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + cdf = factory( NaN, NINF ); + y = cdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `lambda` equals `0`, the created function evaluates a degenerate distribution centered at `mu`', function test( t ) { + var cdf; + var y; + + cdf = factory( 2.0, 0.0 ); + + y = cdf( 2.0, 2.0, 0.0 ); + t.strictEqual( y, 1.0, 'returns 1 for x equal to mu' ); + + y = cdf( 3.0, 2.0, 0.0 ); + t.strictEqual( y, 1.0, 'returns 1 for x greater than mu' ); + + y = cdf( 1.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x smaller than mu' ); + + t.end(); +}); + +tape( 'the created function evaluates the cdf (given positive `mu`)', function test( t ) { + var expected; + var lambda; + var cdf; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + cdf = factory( mu[i], lambda[i] ); + y = cdf( x[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); + +tape( 'the created function evaluates the cdf (given negative `mu`)', function test( t ) { + var expected; + var lambda; + var cdf; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + cdf = factory( mu[i], lambda[i] ); + y = cdf( x[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); + +tape( 'the created function evaluates the cdf (given large `lambda`)', function test( t ) { + var expected; + var lambda; + var cdf; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + cdf = factory( mu[i], lambda[i] ); + y = cdf( x[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 250 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.js new file mode 100644 index 000000000000..85a2b4b63e97 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 tape = require( 'tape' ); +var cdf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a factory method for generating `cdf` functions', function test( t ) { + t.strictEqual( typeof cdf.factory, 'function', 'exports a factory method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.native.js new file mode 100644 index 000000000000..c08398cb7c84 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.native.js @@ -0,0 +1,181 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// VARIABLES // + +var cdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( cdf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { + var y = cdf( NaN, 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = cdf( 0.0, NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = cdf( 0.0, 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `+infinity` for `x` and a valid `mu` and `lambda`, the function returns `1`', opts, function test( t ) { + var y = cdf( PINF, 1.0, 0.0 ); + t.strictEqual( y, 1.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `-infinity` for `x` and a valid `mu` and `lambda`, the function returns `0`', opts, function test( t ) { + var y = cdf( NINF, 1.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a negative `lambda`, the function always returns `NaN`', opts, function test( t ) { + var y; + + y = cdf( 2.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 0.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 2.0, 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 2.0, PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 2.0, NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = cdf( 2.0, NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `lambda` equals `0`, the function evaluates a degenerate distribution centered at `mu`', opts, function test( t ) { + var y; + + y = cdf( 2.0, 2.0, 0.0 ); + t.strictEqual( y, 1.0, 'returns 1 for x equal to mu' ); + + y = cdf( 3.0, 2.0, 0.0 ); + t.strictEqual( y, 1.0, 'returns 1 for x greater than mu' ); + + y = cdf( 1.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x smaller than mu' ); + + t.end(); +}); + +tape( 'the function evaluates the cdf for `x` (given positive `mu`)', opts, function test( t ) { + var expected; + var lambda; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + y = cdf( x[i], mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); + +tape( 'the function evaluates the cdf for `x` ', opts, function test( t ) { + var expected; + var lambda; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + y = cdf( x[i], mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); + +tape( 'the function evaluates the cdf for `x` (given negative `mu`)', opts, function test( t ) { + var expected; + var lambda; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + y = cdf( x[i], mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 250 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); From ddc6da233d1dea3eee63d08c8cf0944a4ff2032c Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 00:15:32 +0530 Subject: [PATCH 2/9] chore: updating tests --- .../stats/base/dists/wald/cdf/README.md | 6 +- .../stats/base/dists/wald/cdf/docs/repl.txt | 2 +- .../base/dists/wald/cdf/docs/types/index.d.ts | 8 +-- .../base/dists/wald/cdf/examples/index.js | 5 +- .../stats/base/dists/wald/cdf/lib/factory.js | 18 +++--- .../stats/base/dists/wald/cdf/lib/main.js | 9 ++- .../stats/base/dists/wald/cdf/manifest.json | 8 +-- .../stats/base/dists/wald/cdf/package.json | 32 +++++++++-- .../stats/base/dists/wald/cdf/src/main.c | 23 +------- .../base/dists/wald/cdf/test/test.cdf.js | 48 +--------------- .../base/dists/wald/cdf/test/test.factory.js | 56 +------------------ .../base/dists/wald/cdf/test/test.native.js | 52 +---------------- 12 files changed, 63 insertions(+), 204 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md index e171a0202015..530783dbd66a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md @@ -44,7 +44,7 @@ Evaluates the [cumulative distribution function][cdf] (CDF) for a [Wald][wald-di ```javascript var y = cdf( 2.0, 2.0, 1.0 ); -// returns ~0.713 +// returns ~0.714 y = cdf( 1.0, 2.0, 1.0 ); // returns ~0.490 @@ -113,7 +113,7 @@ var y = mycdf( 2.0 ); // returns ~0.885 y = mycdf( 8.0 ); -// returns ~0.998 +// returns ~1.000 ``` @@ -133,7 +133,7 @@ var EPS = require( '@stdlib/constants/float64/eps' ); var cdf = require( '@stdlib/stats/base/dists/wald/cdf' ); var opts = { - 'dtype': 'float64' + 'dtype': 'float64' }; var x = uniform( 10, EPS, 10.0, opts ); var mu = uniform( 10, EPS, 10.0, opts ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt index 102612f01ab8..d83453c77bfb 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt @@ -44,7 +44,7 @@ // Degenerate distribution when `λ = 0.0`: > y = {{alias}}( 2.0, 8.0, 0.0 ) - 1.0 + 0.0 > y = {{alias}}( 8.0, 8.0, 0.0 ) 1.0 > y = {{alias}}( 10.0, 8.0, 0.0 ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts index 9d0ca23fd43c..f784182b65ec 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts @@ -55,7 +55,7 @@ interface CDF { * // returns NaN * * @example - * var y = cdf( NaN, 0.0, 1.0 ); + * var y = cdf( NaN, 0.0, 0.0 ); * // returns NaN * * @example @@ -83,10 +83,10 @@ interface CDF { * @example * var myCDF = cdf.factory( 10.0, 2.0 ); * var y = myCDF( 10.0 ); - * // returns ~0.776 + * // returns ~0.777 * * y = myCDF( 12.0 ); - * // returns ~0.807 + * // returns ~0.808 */ factory( mu: number, lambda: number ): Unary; } @@ -105,7 +105,7 @@ interface CDF { * * var myCDF = cdf.factory( 10.0, 2.0 ); * y = myCDF( 10.0 ); -* // returns ~0.776 +* // returns ~0.777 */ declare var cdf: CDF; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js index 83b0b0d40adf..19eee46bee86 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js @@ -32,5 +32,6 @@ var lambda = uniform( 10, EPS, 20.0, opts ); logEachMap( 'x: %0.4f, µ: %0.4f, λ: %0.4f, f(x;µ,λ): %0.4f', x, mu, lambda, cdf ); - -console.log( cdf( 2.0, 1.0, 1.0 ) ); \ No newline at end of file +var CDF = cdf.factory( 1.0, 1.0 ); +var y = CDF( 2.0 ); +console.log( y ); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/factory.js index d7f3507c0908..3f877989e61f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/factory.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/factory.js @@ -25,7 +25,7 @@ var degenerate = require( '@stdlib/stats/base/dists/degenerate/cdf' ).factory; var isnan = require( '@stdlib/math/base/assert/is-nan' ); var exp = require( '@stdlib/math/base/special/exp' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); -var normalCDF = require( '@stdlib/stats/base/dists/normal/cdf' ).factory; +var erfc = require( '@stdlib/math/base/special/erfc' ); // MAIN // @@ -40,14 +40,13 @@ var normalCDF = require( '@stdlib/stats/base/dists/normal/cdf' ).factory; * @example * var cdf = factory( 1.0, 1.0 ); * var y = cdf( 2.0 ); -* // returns ~0.801 +* // returns ~0.885 * * y = cdf( 0.5 ); -* // returns ~0.241 +* // returns ~0.365 */ function factory( mu, lambda ) { var C; - var phi; if ( isnan( mu ) || @@ -60,8 +59,7 @@ function factory( mu, lambda ) { if ( lambda === 0.0 ) { return degenerate( mu ); } - phi = normalCDF( 0.0, 1.0 ); - C = exp( 2.0 * lambda / mu ); + C = exp( 2.0 * ( lambda / mu ) ); return cdf; /** @@ -76,9 +74,9 @@ function factory( mu, lambda ) { * // returns */ function cdf( x ) { - var z; var t1; var t2; + var z; if ( isnan( x ) ) { return NaN; @@ -87,8 +85,10 @@ function factory( mu, lambda ) { return 0.0; } z = sqrt( lambda / x ); - t1 = phi( z * ( x / mu - 1.0 ) ); - t2 = C * phi( -z * ( x / mu + 1.0 ) ); + + // Φ(a) = 0.5 * erfc( -a / √2 ) + t1 = 0.5 * erfc( - ( z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ) ); + t2 = C * 0.5 * erfc( ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ) ); return t1 + t2; } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js index 6b21debece0c..ed7d9a48d6d8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js @@ -23,7 +23,7 @@ var exp = require( '@stdlib/math/base/special/exp' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); -var normalCDF = require( '@stdlib/stats/base/dists/normal/cdf' ).factory +var erfc = require( '@stdlib/math/base/special/erfc' ); // MAIN // @@ -80,7 +80,6 @@ function cdf( x, mu, lambda ) { var z; var t1; var t2; - var phi; if ( isnan( x ) || @@ -97,11 +96,11 @@ function cdf( x, mu, lambda ) { if ( x <= 0.0 ) { return 0.0; } - phi = normalCDF( 0.0, 1.0 ); C = exp( 2.0 * lambda / mu ); z = sqrt( lambda / x ); - t1 = phi( z * ( x / mu - 1.0 ) ); - t2 = C * phi( -z * ( x / mu + 1.0 ) ); + // Φ(a) = 0.5 * erfc( -a / sqrt( 2 ) ) + t1 = 0.5 * erfc( ( -z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ) ); + t2 = C * 0.5 * erfc( ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ) ); return t1 + t2; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json index 65af662cb405..bac0a75b4acf 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json @@ -42,9 +42,7 @@ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/special/erfc", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/exp", - "@stdlib/stats/base/dists/normal/cdf", - "@stdlib/constants/float64/pinf" + "@stdlib/math/base/special/exp" ] }, { @@ -63,8 +61,6 @@ "@stdlib/math/base/special/erfc", "@stdlib/math/base/special/sqrt", "@stdlib/math/base/special/exp", - "@stdlib/stats/base/dists/normal/cdf", - "@stdlib/constants/float64/pinf", "@stdlib/constants/float64/eps" ] }, @@ -84,8 +80,6 @@ "@stdlib/math/base/special/erfc", "@stdlib/math/base/special/sqrt", "@stdlib/math/base/special/exp", - "@stdlib/stats/base/dists/normal/cdf", - "@stdlib/constants/float64/pinf", "@stdlib/constants/float64/eps" ] } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json index 6d8c93d9a825..42d3d8221d57 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json @@ -2,6 +2,33 @@ "name": "@stdlib/stats/base/dists/wald/cdf", "version": "0.0.0", "description": "Wald distribution cumulative distribution function (CDF).", + "main": "./lib", + "scripts": {}, + "devDependencies": { + "babel-cli": "^6.9.0", + "babel-plugin-add-module-exports": "^0.2.1", + "babel-plugin-transform-regenerator": "^6.9.0", + "babel-preset-es2015": "^6.9.0", + "bake-cli": "^0.1.6", + "eslint": "^2.10.2", + "eslint-config-standard": "^5.3.1", + "eslint-plugin-promise": "^1.1.0", + "eslint-plugin-standard": "^1.3.2", + "mocha": "^2.5.2", + "standard-version": "^2.2.1", + "watchd": "github:mklabs/watchd" + }, + "bake": { + "description": "Scaffold a basic ES6 setup", + "scripts": { + "start": "echo Starting generation of default template", + "prestart": "echo prestart", + "poststart": "echo poststart", + "install": "npm install --loglevel warn --cache-min Infinity", + "preinstall": "echo Installing dependencies ...", + "postinstall": "npm ls --depth 0" + } + }, "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -13,7 +40,6 @@ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" } ], - "main": "./lib", "gypfile": true, "directories": { "benchmark": "./benchmark", @@ -25,7 +51,6 @@ "test": "./test" }, "types": "./docs/types", - "scripts": {}, "homepage": "https://github.com/stdlib-js/stdlib", "repository": { "type": "git", @@ -35,7 +60,6 @@ "url": "https://github.com/stdlib-js/stdlib/issues" }, "dependencies": {}, - "devDependencies": {}, "engines": { "node": ">=0.10.0", "npm": ">2.7.0" @@ -68,4 +92,4 @@ "univariate", "continuous" ] -} +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c index ee8e8fb2766f..3d5da492e35d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c @@ -21,20 +21,6 @@ #include "stdlib/math/base/special/sqrt.h" #include "stdlib/math/base/special/exp.h" #include "stdlib/math/base/special/erfc.h" -#include "stdlib/stats/base/dists/normal/cdf.h" -#include "stdlib/constants/float64/pinf.h" - -/** -* Evaluates the standard normal CDF Φ(x). -* -* Φ(x) = 0.5 * erfc( -x / sqrt(2) ) -* -* @param x input value -* @return Standard noraml CDF -*/ -static double stdnormal_cdf( const double x ) { - return 0.5 * stdlib_base_erfc( -x * ( x / stdlib_base_sqrt( 2.0 ) ) ); -} /** * Evaluates the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. @@ -69,12 +55,9 @@ double stdlib_base_dists_wald_cdf( const double x, const double mu, const double if ( x <= 0.0 ) { return 0.0; } - if ( x == STDLIB_CONSTANT_FLOAT64_PINF ) { - return 1.0; - } - C = stdlib_base_exp( 2.0 * lambda / mu ); + C = stdlib_base_exp( 2.0 * ( lambda / mu ) ); z = stdlib_base_sqrt( lambda / x ); - t1 = stdnormal_cdf( z * ( x / mu - 1.0 ) ); - t2 = C * stdnormal_cdf( -z * ( x / mu + 1.0 ) ); + t1 = 0.5 * stdlib_base_erfc( ( -z * ( ( x / mu ) - 1.0 ) ) / stdlib_base_sqrt( 2.0 ) ); + t2 = C * 0.5 * stdlib_base_erfc( ( z * ( ( x / mu ) + 1.0 ) ) / stdlib_base_sqrt( 2.0 ) ); return t1 + t2; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.cdf.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.cdf.js index 89e9143ce208..f69df5087afd 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.cdf.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.cdf.js @@ -102,7 +102,7 @@ tape( 'if provided `lambda` equals `0`, the function evaluates a degenerate dist t.end(); }); -tape( 'the function evaluates the cdf for `x` (given positive `mu`)', function test( t ) { +tape( 'the function evaluates the cdf for `x` given parameters `mu` and `lambda`', function test( t ) { var expected; var lambda; var mu; @@ -124,49 +124,3 @@ tape( 'the function evaluates the cdf for `x` (given positive `mu`)', function t } t.end(); }); - -tape( 'the function evaluates the cdf for `x` ', function test( t ) { - var expected; - var lambda; - var mu; - var i; - var x; - var y; - - expected = data.expected; - x = data.x; - mu = data.mu; - lambda = data.lambda; - for ( i = 0; i < x.length; i++ ) { - y = cdf( x[i], mu[i], lambda[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); - } else { - t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); - } - } - t.end(); -}); - -tape( 'the function evaluates the cdf for `x` (given negative `mu`)', function test( t ) { - var expected; - var lambda; - var mu; - var i; - var x; - var y; - - expected = data.expected; - x = data.x; - mu = data.mu; - lambda = data.lambda; - for ( i = 0; i < x.length; i++ ) { - y = cdf( x[i], mu[i], lambda[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); - } else { - t.ok( isAlmostSameValue( y, expected[i], 250 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); - } - } - t.end(); -}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js index 1af3f6c9c633..1c62a8aa16da 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js @@ -145,64 +145,14 @@ tape( 'if `lambda` equals `0`, the created function evaluates a degenerate distr t.end(); }); -tape( 'the created function evaluates the cdf (given positive `mu`)', function test( t ) { +tape( 'the function evaluates the cdf for `x` given parameters `mu` and `lambda`', function test( t ) { var expected; var lambda; var cdf; var mu; - var i; - var x; - var y; - - expected = data.expected; - x = data.x; - mu = data.mu; - lambda = data.lambda; - for ( i = 0; i < x.length; i++ ) { - cdf = factory( mu[i], lambda[i] ); - y = cdf( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); - } else { - t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); - } - } - t.end(); -}); - -tape( 'the created function evaluates the cdf (given negative `mu`)', function test( t ) { - var expected; - var lambda; - var cdf; - var mu; - var i; var x; var y; - - expected = data.expected; - x = data.x; - mu = data.mu; - lambda = data.lambda; - for ( i = 0; i < x.length; i++ ) { - cdf = factory( mu[i], lambda[i] ); - y = cdf( x[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); - } else { - t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); - } - } - t.end(); -}); - -tape( 'the created function evaluates the cdf (given large `lambda`)', function test( t ) { - var expected; - var lambda; - var cdf; - var mu; var i; - var x; - var y; expected = data.expected; x = data.x; @@ -212,9 +162,9 @@ tape( 'the created function evaluates the cdf (given large `lambda`)', function cdf = factory( mu[i], lambda[i] ); y = cdf( x[i] ); if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - t.ok( isAlmostSameValue( y, expected[i], 250 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 1500 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.native.js index c08398cb7c84..3c041e090429 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.native.js @@ -111,59 +111,13 @@ tape( 'if provided `lambda` equals `0`, the function evaluates a degenerate dist t.end(); }); -tape( 'the function evaluates the cdf for `x` (given positive `mu`)', opts, function test( t ) { +tape( 'the function evaluates the cdf for `x` given parameters `mu` and `lambda`', opts, function test( t ) { var expected; var lambda; var mu; - var i; - var x; - var y; - - expected = data.expected; - x = data.x; - mu = data.mu; - lambda = data.lambda; - for ( i = 0; i < x.length; i++ ) { - y = cdf( x[i], mu[i], lambda[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); - } else { - t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); - } - } - t.end(); -}); - -tape( 'the function evaluates the cdf for `x` ', opts, function test( t ) { - var expected; - var lambda; - var mu; - var i; var x; var y; - - expected = data.expected; - x = data.x; - mu = data.mu; - lambda = data.lambda; - for ( i = 0; i < x.length; i++ ) { - y = cdf( x[i], mu[i], lambda[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); - } else { - t.ok( isAlmostSameValue( y, expected[i], 1600 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); - } - } - t.end(); -}); - -tape( 'the function evaluates the cdf for `x` (given negative `mu`)', opts, function test( t ) { - var expected; - var lambda; - var mu; var i; - var x; - var y; expected = data.expected; x = data.x; @@ -172,9 +126,9 @@ tape( 'the function evaluates the cdf for `x` (given negative `mu`)', opts, func for ( i = 0; i < x.length; i++ ) { y = cdf( x[i], mu[i], lambda[i] ); if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - t.ok( isAlmostSameValue( y, expected[i], 250 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + t.ok( isAlmostSameValue( y, expected[i], 1500 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); From 1448183961a507dcfa0415468e46bcb488da2024 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 00:38:48 +0530 Subject: [PATCH 3/9] chore: update package.json --- .../stats/base/dists/wald/cdf/README.md | 2 +- .../stats/base/dists/wald/cdf/docs/repl.txt | 2 +- .../base/dists/wald/cdf/examples/index.js | 4 --- .../stats/base/dists/wald/cdf/lib/factory.js | 2 +- .../stats/base/dists/wald/cdf/lib/main.js | 2 +- .../stats/base/dists/wald/cdf/package.json | 32 +++---------------- .../stats/base/dists/wald/cdf/src/main.c | 2 +- 7 files changed, 9 insertions(+), 37 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md index 530783dbd66a..20f39b30be4e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md @@ -113,7 +113,7 @@ var y = mycdf( 2.0 ); // returns ~0.885 y = mycdf( 8.0 ); -// returns ~1.000 +// returns ~0.999 ``` diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt index d83453c77bfb..eeae58503edb 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt @@ -72,7 +72,7 @@ -------- > var myCDF = {{alias}}.factory( 10.0, 2.0 ); > var y = myCDF( 10.0 ) - ~0.776 + ~0.777 See Also -------- diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js index 19eee46bee86..10e12f42c78f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/examples/index.js @@ -31,7 +31,3 @@ var mu = uniform( 10, EPS, 10.0, opts ); var lambda = uniform( 10, EPS, 20.0, opts ); logEachMap( 'x: %0.4f, µ: %0.4f, λ: %0.4f, f(x;µ,λ): %0.4f', x, mu, lambda, cdf ); - -var CDF = cdf.factory( 1.0, 1.0 ); -var y = CDF( 2.0 ); -console.log( y ); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/factory.js index 3f877989e61f..60d68bad3870 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/factory.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/factory.js @@ -87,7 +87,7 @@ function factory( mu, lambda ) { z = sqrt( lambda / x ); // Φ(a) = 0.5 * erfc( -a / √2 ) - t1 = 0.5 * erfc( - ( z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ) ); + t1 = 0.5 * erfc( ( -z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ) ); t2 = C * 0.5 * erfc( ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ) ); return t1 + t2; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js index ed7d9a48d6d8..5e8a93a440b3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js @@ -86,7 +86,7 @@ function cdf( x, mu, lambda ) { isnan( mu ) || isnan( lambda ) || mu <= 0.0 || - lambda < 0.0 + lambda <= 0.0 ) { return NaN; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json index 42d3d8221d57..6d8c93d9a825 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/package.json @@ -2,33 +2,6 @@ "name": "@stdlib/stats/base/dists/wald/cdf", "version": "0.0.0", "description": "Wald distribution cumulative distribution function (CDF).", - "main": "./lib", - "scripts": {}, - "devDependencies": { - "babel-cli": "^6.9.0", - "babel-plugin-add-module-exports": "^0.2.1", - "babel-plugin-transform-regenerator": "^6.9.0", - "babel-preset-es2015": "^6.9.0", - "bake-cli": "^0.1.6", - "eslint": "^2.10.2", - "eslint-config-standard": "^5.3.1", - "eslint-plugin-promise": "^1.1.0", - "eslint-plugin-standard": "^1.3.2", - "mocha": "^2.5.2", - "standard-version": "^2.2.1", - "watchd": "github:mklabs/watchd" - }, - "bake": { - "description": "Scaffold a basic ES6 setup", - "scripts": { - "start": "echo Starting generation of default template", - "prestart": "echo prestart", - "poststart": "echo poststart", - "install": "npm install --loglevel warn --cache-min Infinity", - "preinstall": "echo Installing dependencies ...", - "postinstall": "npm ls --depth 0" - } - }, "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -40,6 +13,7 @@ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" } ], + "main": "./lib", "gypfile": true, "directories": { "benchmark": "./benchmark", @@ -51,6 +25,7 @@ "test": "./test" }, "types": "./docs/types", + "scripts": {}, "homepage": "https://github.com/stdlib-js/stdlib", "repository": { "type": "git", @@ -60,6 +35,7 @@ "url": "https://github.com/stdlib-js/stdlib/issues" }, "dependencies": {}, + "devDependencies": {}, "engines": { "node": ">=0.10.0", "npm": ">2.7.0" @@ -92,4 +68,4 @@ "univariate", "continuous" ] -} \ No newline at end of file +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c index 3d5da492e35d..fc045239c576 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c @@ -45,7 +45,7 @@ double stdlib_base_dists_wald_cdf( const double x, const double mu, const double stdlib_base_is_nan( mu ) || stdlib_base_is_nan( lambda ) || mu <= 0.0 || - lambda < 0.0 + lambda <= 0.0 ) { return 0.0/0.0; // NaN } From 86d287242736a719e8a6f92814a052faa68841b9 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 00:51:08 +0530 Subject: [PATCH 4/9] chore: updating return values --- .../@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts | 4 ---- .../@stdlib/stats/base/dists/wald/cdf/lib/index.js | 2 +- .../@stdlib/stats/base/dists/wald/cdf/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts index f784182b65ec..60ad58ae4f75 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts @@ -51,10 +51,6 @@ interface CDF { * // returns ~0.055 * * @example - * var y = cdf( -1.0, 4.0, 2.0 ); - * // returns NaN - * - * @example * var y = cdf( NaN, 0.0, 0.0 ); * // returns NaN * diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/index.js index 24beed461783..0855c01e086e 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/index.js @@ -31,7 +31,7 @@ * * var myCDF = cdf.factory( 2.0, 1.0 ); * y = myCDF( 2.0 ); -* // returns ~0.713 +* // returns ~0.714 */ // MODULES // diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js index 5e8a93a440b3..ed7d9a48d6d8 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js @@ -86,7 +86,7 @@ function cdf( x, mu, lambda ) { isnan( mu ) || isnan( lambda ) || mu <= 0.0 || - lambda <= 0.0 + lambda < 0.0 ) { return NaN; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c index fc045239c576..3d5da492e35d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c @@ -45,7 +45,7 @@ double stdlib_base_dists_wald_cdf( const double x, const double mu, const double stdlib_base_is_nan( mu ) || stdlib_base_is_nan( lambda ) || mu <= 0.0 || - lambda <= 0.0 + lambda < 0.0 ) { return 0.0/0.0; // NaN } From 92c79526266a67cad7de40c4db07033a1f66d7c9 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 08:56:43 +0530 Subject: [PATCH 5/9] chore: clean up --- .../@stdlib/stats/base/dists/wald/cdf/docs/repl.txt | 2 +- .../stats/base/dists/wald/cdf/docs/types/index.d.ts | 2 +- .../@stdlib/stats/base/dists/wald/cdf/lib/main.js | 7 ++++--- .../@stdlib/stats/base/dists/wald/cdf/lib/native.js | 4 ---- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt index eeae58503edb..d8ece6cda689 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt @@ -53,7 +53,7 @@ {{alias}}.factory( μ, λ ) Returns a function for evaluating the cumulative distribution function (CDF) - of a normal distribution with mean `μ` and shape parameter `λ`. + of a wald distribution with mean `μ` and shape parameter `λ`. Parameters ---------- diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts index 60ad58ae4f75..87203ffb937c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts @@ -67,7 +67,7 @@ interface CDF { * var y = cdf( 2.0, 0.0, -1.0 ); * // returns NaN */ - ( x: number, mu: number, sigma: number ): number; + ( x: number, mu: number, lambda: number ): number; /** * Returns a function for evaluating the cumulative distribution function (CDF) for a Wald distribution. diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js index ed7d9a48d6d8..16365efa2d2c 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js @@ -76,10 +76,10 @@ var erfc = require( '@stdlib/math/base/special/erfc' ); * // returns 0.0 */ function cdf( x, mu, lambda ) { - var C; - var z; var t1; var t2; + var C; + var z; if ( isnan( x ) || @@ -90,7 +90,7 @@ function cdf( x, mu, lambda ) { ) { return NaN; } - if ( lambda == 0.0 ) { + if ( lambda === 0.0 ) { return ( x < mu ) ? 0.0 : 1.0; } if ( x <= 0.0 ) { @@ -98,6 +98,7 @@ function cdf( x, mu, lambda ) { } C = exp( 2.0 * lambda / mu ); z = sqrt( lambda / x ); + // Φ(a) = 0.5 * erfc( -a / sqrt( 2 ) ) t1 = 0.5 * erfc( ( -z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ) ); t2 = C * 0.5 * erfc( ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ) ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js index 8e359426b4f5..9ca3128d7eb0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js @@ -43,10 +43,6 @@ var addon = require( './../src/addon.node' ); * // returns ~0.055 * * @example -* var y = cdf( -1.0, 4.0, 2.0 ); -* // returns NaN -* -* @example * var y = cdf( NaN, 0.0, 1.0 ); * // returns NaN * From 480cfb0ac3b7500c7e60f7d2aa0f61ea08722ecb Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 08:59:19 +0530 Subject: [PATCH 6/9] chore: updating return value --- .../@stdlib/stats/base/dists/wald/cdf/lib/native.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js index 9ca3128d7eb0..69ff3b4e453d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/native.js @@ -36,7 +36,7 @@ var addon = require( './../src/addon.node' ); * * @example * var y = cdf( 2.0, 1.0, 1.0 ); -* // returns ~0.855 +* // returns ~0.885 * * @example * var y = cdf( 0.5, 2.0, 3.0 ); From 13b639df96eca7a5ffdb484f91f6505654a32514 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 12:16:10 +0530 Subject: [PATCH 7/9] chore: apply suggested changes --- .../@stdlib/stats/base/dists/wald/cdf/README.md | 10 ++++++++++ .../stats/base/dists/wald/cdf/benchmark/benchmark.js | 2 +- .../base/dists/wald/cdf/benchmark/benchmark.native.js | 2 +- .../@stdlib/stats/base/dists/wald/cdf/docs/repl.txt | 2 ++ .../stats/base/dists/wald/cdf/docs/types/index.d.ts | 4 ++-- .../@stdlib/stats/base/dists/wald/cdf/lib/main.js | 4 ++++ .../@stdlib/stats/base/dists/wald/cdf/manifest.json | 5 ++++- .../@stdlib/stats/base/dists/wald/cdf/src/main.c | 4 ++++ .../stats/base/dists/wald/cdf/test/test.factory.js | 6 +++--- 9 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md index 20f39b30be4e..817d341ddc91 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/README.md @@ -26,6 +26,16 @@ limitations under the License. The [cumulative distribution function][cdf] for a [Wald][wald-distribution] random variable is + + +```math +F(x;\mu,\lambda) = \Phi\!\left(\sqrt{\frac{\lambda}{x}}\left(\frac{x}{\mu}-1\right)\right) + \exp\!\left(\frac{2\lambda}{\mu}\right)\,\Phi\!\left(-\sqrt{\frac{\lambda}{x}}\left(\frac{x}{\mu}+1\right)\right) +``` + + + +where `µ > 0` is the mean and `λ > 0` is the shape parameter. + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.js index 34176004bd94..598c51a7e667 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.js @@ -46,7 +46,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = cdf( x[ i % len ], mu[ i % len ], lambda[ i % len ]); + y = cdf( x[ i % len ], mu[ i % len ], lambda[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js index 61a993e8c908..d2df93f87788 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js @@ -54,7 +54,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = cdf( x[ i % len ], mu[ i % len ], lambda[ i % len ]); + y = cdf( x[ i % len ], mu[ i % len ], lambda[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt index d8ece6cda689..63956c0dee6b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/repl.txt @@ -5,6 +5,8 @@ If provided `NaN` as any argument, the function returns `NaN`. + If provided `μ <= 0`, the function returns `NaN`. + If provided `λ <= 0`, the function returns `NaN`. Parameters diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts index 87203ffb937c..333117d08d2b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/docs/types/index.d.ts @@ -35,7 +35,7 @@ interface CDF { * * ## Notes * - * - If provided `lambda <= 0`, the function returns `NaN`. + * - If provided `lambda < 0`, the function returns `NaN`. * * @param x - input value * @param mu - mean @@ -88,7 +88,7 @@ interface CDF { } /** -* Normal distribution cumulative distribution function (CDF). +* Wald distribution cumulative distribution function (CDF). * * @param x - input value * @param mu - mean diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js index 16365efa2d2c..f096a259f4ae 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js @@ -24,6 +24,7 @@ var exp = require( '@stdlib/math/base/special/exp' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var erfc = require( '@stdlib/math/base/special/erfc' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); // MAIN // @@ -96,6 +97,9 @@ function cdf( x, mu, lambda ) { if ( x <= 0.0 ) { return 0.0; } + if ( x === PINF ) { + return 1.0; + } C = exp( 2.0 * lambda / mu ); z = sqrt( lambda / x ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json index bac0a75b4acf..9b4c576a0994 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/manifest.json @@ -42,7 +42,8 @@ "@stdlib/math/base/assert/is-nan", "@stdlib/math/base/special/erfc", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/exp" + "@stdlib/math/base/special/exp", + "@stdlib/constants/float64/pinf" ] }, { @@ -61,6 +62,7 @@ "@stdlib/math/base/special/erfc", "@stdlib/math/base/special/sqrt", "@stdlib/math/base/special/exp", + "@stdlib/constants/float64/pinf", "@stdlib/constants/float64/eps" ] }, @@ -80,6 +82,7 @@ "@stdlib/math/base/special/erfc", "@stdlib/math/base/special/sqrt", "@stdlib/math/base/special/exp", + "@stdlib/constants/float64/pinf", "@stdlib/constants/float64/eps" ] } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c index 3d5da492e35d..a828b5f07b7d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c @@ -21,6 +21,7 @@ #include "stdlib/math/base/special/sqrt.h" #include "stdlib/math/base/special/exp.h" #include "stdlib/math/base/special/erfc.h" +#include "stdlib/constants/float64/pinf.h" /** * Evaluates the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. @@ -55,6 +56,9 @@ double stdlib_base_dists_wald_cdf( const double x, const double mu, const double if ( x <= 0.0 ) { return 0.0; } + if ( x == STDLIB_CONSTANT_FLOAT64_PINF ) { + return 1.0; + } C = stdlib_base_exp( 2.0 * ( lambda / mu ) ); z = stdlib_base_sqrt( lambda / x ); t1 = 0.5 * stdlib_base_erfc( ( -z * ( ( x / mu ) - 1.0 ) ) / stdlib_base_sqrt( 2.0 ) ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js index 1c62a8aa16da..32a12fd929cf 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/test/test.factory.js @@ -134,13 +134,13 @@ tape( 'if `lambda` equals `0`, the created function evaluates a degenerate distr cdf = factory( 2.0, 0.0 ); y = cdf( 2.0, 2.0, 0.0 ); - t.strictEqual( y, 1.0, 'returns 1 for x equal to mu' ); + t.strictEqual( y, 1.0, 'returns expected value' ); y = cdf( 3.0, 2.0, 0.0 ); - t.strictEqual( y, 1.0, 'returns 1 for x greater than mu' ); + t.strictEqual( y, 1.0, 'returns expected value' ); y = cdf( 1.0, 2.0, 0.0 ); - t.strictEqual( y, 0.0, 'returns 0 for x smaller than mu' ); + t.strictEqual( y, 0.0, 'returns expected value' ); t.end(); }); From 8c7437df99f365407dcf58fdb9eb5abc82d6cf3d Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Tue, 13 Jan 2026 12:20:52 +0530 Subject: [PATCH 8/9] chore: clean up --- lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js | 2 +- lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js index f096a259f4ae..7b87b92364a4 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/lib/main.js @@ -98,7 +98,7 @@ function cdf( x, mu, lambda ) { return 0.0; } if ( x === PINF ) { - return 1.0; + return 1.0; } C = exp( 2.0 * lambda / mu ); z = sqrt( lambda / x ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c index a828b5f07b7d..baa0b1a89380 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/src/main.c @@ -57,7 +57,7 @@ double stdlib_base_dists_wald_cdf( const double x, const double mu, const double return 0.0; } if ( x == STDLIB_CONSTANT_FLOAT64_PINF ) { - return 1.0; + return 1.0; } C = stdlib_base_exp( 2.0 * ( lambda / mu ) ); z = stdlib_base_sqrt( lambda / x ); From 96d00bfe4f23980591d30457e925d2956d5eef61 Mon Sep 17 00:00:00 2001 From: Neeraj Pathak Date: Fri, 16 Jan 2026 18:52:30 +0530 Subject: [PATCH 9/9] chore: update native benchmarks to use format --- .../stats/base/dists/wald/cdf/benchmark/benchmark.native.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js index d2df93f87788..14747ce4c0f2 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/cdf/benchmark/benchmark.native.js @@ -26,6 +26,7 @@ var uniform = require( '@stdlib/random/array/uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); var EPS = require( '@stdlib/constants/float64/eps' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; @@ -39,7 +40,7 @@ var opts = { // MAIN // -bench( pkg+'::native', opts, function benchmark( b ) { +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { var lambda; var len; var mu;