diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md new file mode 100644 index 000000000000..a7825426cc74 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md @@ -0,0 +1,279 @@ + + +# Logarithm of Cumulative Distribution Function + +> [Wald][wald-distribution] distribution logarithm of [cumulative distribution function][cdf]. + +
+ +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. + +
+ + + +
+ +## Usage + +```javascript +var logcdf = require( '@stdlib/stats/base/dists/wald/logcdf' ); +``` + +#### logcdf( x, mu, lambda ) + +Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```javascript +var y = logcdf( 2.0, 2.0, 1.0 ); +// returns ~-0.337 + +y = logcdf( 1.0, 2.0, 1.0 ); +// returns ~-0.713 + +y = logcdf( 4.0, 2.0, 1.0 ); +// returns ~-0.136 +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = logcdf( NaN, 2.0, 1.0 ); +// returns NaN + +y = logcdf( 2.0, NaN, 1.0 ); +// returns NaN + +y = logcdf( 2.0, 2.0, NaN ); +// returns NaN +``` + +If provided `mu <= 0` or `lambda < 0`, the function returns `NaN`. + +```javascript +var y = logcdf( 2.0, 0.0, -3.0 ); +// returns NaN + +y = logcdf( 2.0, -1.0, -2.0 ); +// returns NaN + +y = logcdf( 2.0, -2.0, -1.0 ); +// returns NaN +``` + +If provided `x <= 0`, the function returns `-Infinity`. + +```javascript +var y = logcdf( 0.0, 2.0, 1.0 ); +// returns -Infinity + +y = logcdf( -1.0, 2.0, 1.0 ); +// returns -Infinity +``` + +If `lambda = 0`, the function evaluates the logarithm of the [CDF][cdf] of a [degenerate distribution][degenerate-distribution] centered at `mu`. + +```javascript +var y = logcdf( 2.0, 8.0, 0.0 ); +// returns -Infinity + +y = logcdf( 8.0, 8.0, 0.0 ); +// returns 0.0 + +y = logcdf( 10.0, 8.0, 0.0 ); +// returns 0.0 +``` + +#### logcdf.factory( mu, lambda ) + +Returns a function for evaluating the natural logarithm of the [cumulative distribution function][cdf] of a [Wald][wald-distribution] distribution with parameters `mu` and `lambda`. + +```javascript +var mylogcdf = logcdf.factory( 1.0, 1.0 ); + +var y = mylogcdf( 2.0 ); +// returns ~-0.122 + +y = mylogcdf( 8.0 ); +// returns ~-0.001 +``` + +
+ + + +
+ +## 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 logcdf = require( '@stdlib/stats/base/dists/wald/logcdf' ); + +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, ln(F(x;μ,λ)): %0.4f', x, mu, lambda, logcdf ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/wald/logcdf.h" +``` + +#### stdlib_base_dists_wald_logcdf( x, mu, lambda ) + +Evaluates the natural logarithm of 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_logcdf( 2.0, 1.0, 1.0 ); +// returns ~-0.122 +``` + +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_logcdf( const double x, const double mu, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/wald/logcdf.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_logcdf( x, mu, lambda ); + printf( "x: %lf, μ: %lf, λ: %lf, ln(F(x;μ,λ)): %lf\n", x, mu, lambda, y ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.js new file mode 100644 index 000000000000..390962b3f302 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.js @@ -0,0 +1,90 @@ +/** +* @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 logcdf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var arrayOpts; + var lambda; + var mu; + var x; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + x = uniform( 100, EPS, 100.0, arrayOpts ); + mu = uniform( 100, EPS, 50.0, arrayOpts ); + lambda = uniform( 100, EPS, 20.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = logcdf( x[ i % x.length ], mu[ i % mu.length ], lambda[ i % lambda.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(); +}); + +bench( format( '%s:factory', pkg ), function benchmark( b ) { + var arrayOpts; + var mylogcdf; + var x; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + mylogcdf = logcdf.factory( 1.0, 1.5 ); + x = uniform( 100, EPS, 10.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mylogcdf( 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/logcdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..27c59ac3c43d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.native.js @@ -0,0 +1,71 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var logcdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logcdf instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var arrayOpts; + var lambda; + var mu; + var x; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + x = uniform( 100, EPS, 100.0, arrayOpts ); + mu = uniform( 100, EPS, 50.0, arrayOpts ); + lambda = uniform( 100, EPS, 20.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = logcdf( x[ i % x.length ], mu[ i % mu.length ], lambda[ i % lambda.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/logcdf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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/logcdf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..98f51a79a407 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/benchmark.c @@ -0,0 +1,143 @@ +/** +* @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/logcdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "wald-logcdf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* 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_logcdf( 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/logcdf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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/logcdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/repl.txt new file mode 100644 index 000000000000..1e1d2d056668 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/repl.txt @@ -0,0 +1,83 @@ + +{{alias}}( x, μ, λ ) + Evaluates the natural logarithm of 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`. + + If provided `λ < 0`, the function returns `NaN`. + + Parameters + ---------- + x: number + Input value. + + μ: number + Mean parameter. + + λ: number + Shape parameter. + + Returns + ------- + out: number + Evaluated logCDF. + + Examples + -------- + > var y = {{alias}}( 2.0, 1.0, 1.0 ) + ~-0.122 + > y = {{alias}}( 0.5, 2.0, 3.0 ) + ~-2.897 + > y = {{alias}}( -1.0, 4.0, 2.0 ) + -Infinity + > y = {{alias}}( NaN, 1.0, 1.0 ) + NaN + > y = {{alias}}( 0.0, NaN, 1.0 ) + NaN + > y = {{alias}}( 0.0, 1.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 ) + -Infinity + > y = {{alias}}( 8.0, 8.0, 0.0 ) + 0.0 + > y = {{alias}}( 10.0, 8.0, 0.0 ) + 0.0 + + +{{alias}}.factory( μ, λ ) + Returns a function for evaluating the natural logarithm of the cumulative + distribution function (CDF) of a Wald distribution with mean `μ` and shape + parameter `λ`. + + Parameters + ---------- + μ: number + Mean parameter. + + λ: number + Shape parameter. + + Returns + ------- + logcdf: Function + Logarithm of cumulative distribution function (CDF). + + Examples + -------- + > var mylogcdf = {{alias}}.factory( 10.0, 2.0 ); + > var y = mylogcdf( 10.0 ) + ~-0.253 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/index.d.ts new file mode 100644 index 000000000000..a4616fbf0a4c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/index.d.ts @@ -0,0 +1,121 @@ +/* +* @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 natural logarithm of the cumulative distribution function (CDF) for a Wald distribution. +* +* @param x - input value +* @returns evaluated logCDF +*/ +type Unary = ( x: number ) => number; + +/** +* Interface for the natural logarithm of the cumulative distribution function (CDF) of a Wald distribution. +*/ +interface LogCDF { + /** + * Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. + * + * ## Notes + * + * - If provided `mu <= 0` or `lambda < 0`, the function returns `NaN`. + * + * @param x - input value + * @param mu - mean + * @param lambda - shape parameter + * @returns evaluated logCDF + * + * @example + * var y = logcdf( 2.0, 1.0, 1.0 ); + * // returns ~-0.122 + * + * @example + * var y = logcdf( 0.5, 2.0, 3.0 ); + * // returns ~-2.897 + * + * @example + * var y = logcdf( NaN, 1.0, 1.0 ); + * // returns NaN + * + * @example + * var y = logcdf( 0.0, NaN, 1.0 ); + * // returns NaN + * + * @example + * var y = logcdf( 0.0, 1.0, NaN ); + * // returns NaN + * + * @example + * // Nonpositive mean: + * var y = logcdf( 2.0, 0.0, 1.0 ); + * // returns NaN + * + * @example + * // Negative shape parameter: + * var y = logcdf( 2.0, 1.0, -1.0 ); + * // returns NaN + * + * @example + * // Degenerate distribution when `lambda = 0.0`: + * var y = logcdf( 2.0, 8.0, 0.0 ); + * // returns -Infinity + */ + ( x: number, mu: number, lambda: number ): number; + + /** + * Returns a function for evaluating the natural logarithm of the cumulative distribution function (CDF) for a Wald distribution. + * + * @param mu - mean + * @param lambda - shape parameter + * @returns function to evaluate the natural logarithm of the cumulative distribution function + * + * @example + * var mylogcdf = logcdf.factory( 10.0, 2.0 ); + * var y = mylogcdf( 10.0 ); + * // returns ~-0.253 + * + * y = mylogcdf( 12.0 ); + * // returns ~-0.213 + */ + factory( mu: number, lambda: number ): Unary; +} + +/** +* Wald distribution natural logarithm of the cumulative distribution function (CDF). +* +* @param x - input value +* @param mu - mean +* @param lambda - shape parameter +* @returns evaluated logCDF +* +* @example +* var y = logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +* +* var mylogcdf = logcdf.factory( 10.0, 2.0 ); +* y = mylogcdf( 10.0 ); +* // returns ~-0.253 +*/ +declare var logcdf: LogCDF; + + +// EXPORTS // + +export = logcdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/test.ts new file mode 100644 index 000000000000..784bffdc827a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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 logcdf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + logcdf( 2, 2, 4 ); // $ExpectType number + logcdf( 1, 2, 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than three numbers... +{ + logcdf( true, 3, 6 ); // $ExpectError + logcdf( false, 2, 4 ); // $ExpectError + logcdf( '5', 1, 2 ); // $ExpectError + logcdf( [], 1, 2 ); // $ExpectError + logcdf( {}, 2, 4 ); // $ExpectError + logcdf( ( x: number ): number => x, 2, 4 ); // $ExpectError + + logcdf( 9, true, 12 ); // $ExpectError + logcdf( 9, false, 12 ); // $ExpectError + logcdf( 5, '5', 10 ); // $ExpectError + logcdf( 8, [], 16 ); // $ExpectError + logcdf( 9, {}, 18 ); // $ExpectError + logcdf( 8, ( x: number ): number => x, 16 ); // $ExpectError + + logcdf( 9, 5, true ); // $ExpectError + logcdf( 9, 5, false ); // $ExpectError + logcdf( 5, 2, '5' ); // $ExpectError + logcdf( 8, 4, [] ); // $ExpectError + logcdf( 9, 4, {} ); // $ExpectError + logcdf( 8, 5, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + logcdf(); // $ExpectError + logcdf( 2 ); // $ExpectError + logcdf( 2, 0 ); // $ExpectError + logcdf( 2, 0, 4, 1 ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + logcdf.factory( 3, 4 ); // $ExpectType Unary +} + +// The `factory` method returns a function which returns a number... +{ + const fcn = logcdf.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 = logcdf.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 = logcdf.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... +{ + logcdf.factory( true, 3 ); // $ExpectError + logcdf.factory( false, 2 ); // $ExpectError + logcdf.factory( '5', 1 ); // $ExpectError + logcdf.factory( [], 1 ); // $ExpectError + logcdf.factory( {}, 2 ); // $ExpectError + logcdf.factory( ( x: number ): number => x, 2 ); // $ExpectError + + logcdf.factory( 9, true ); // $ExpectError + logcdf.factory( 9, false ); // $ExpectError + logcdf.factory( 5, '5' ); // $ExpectError + logcdf.factory( 8, [] ); // $ExpectError + logcdf.factory( 9, {} ); // $ExpectError + logcdf.factory( 8, ( x: number ): number => x ); // $ExpectError + + logcdf.factory( [], true ); // $ExpectError + logcdf.factory( {}, false ); // $ExpectError + logcdf.factory( false, '5' ); // $ExpectError + logcdf.factory( {}, [] ); // $ExpectError + logcdf.factory( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + logcdf.factory( 0 ); // $ExpectError + logcdf.factory( 0, 4, 8 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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/logcdf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/example.c new file mode 100644 index 000000000000..a7ef62dcc032 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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/logcdf.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_logcdf( x, mu, lambda ); + printf( "x: %lf, μ: %lf, λ: %lf, ln(F(x;μ,λ)): %lf\n", x, mu, lambda, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/index.js new file mode 100644 index 000000000000..81fc7d325ec0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/index.js @@ -0,0 +1,33 @@ +/** +* @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 logcdf = 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, ln(F(x;μ,λ)): %0.4f', x, mu, lambda, logcdf ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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 logcdf( x ) { + var t1; + var t2; + var a; + var b; + var z; + + if ( isnan( x ) ) { + return NaN; + } + if ( x <= 0.0 ) { + return NINF; + } + if ( x === PINF ) { + return 0.0; + } + z = sqrt( lambda / x ); + a = ( z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ); + b = ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ); + + // Φ(a) = 0.5 * erfc( -a / √2 ) + t1 = 0.5 * erfc( -a ); + + // exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² ), as b² - a² = 2λ/μ; computing via `erfcx` avoids overflow of the exponential term for large `λ/μ`: + t2 = 0.5 * erfcx( b ) * exp( -a * a ); + return ln( t1 + t2 ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js new file mode 100644 index 000000000000..70d6cec3346d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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 logarithm of cumulative distribution function (CDF). +* +* @module @stdlib/stats/base/dists/wald/logcdf +* +* @example +* var logcdf = require( '@stdlib/stats/base/dists/wald/logcdf' ); +* +* var y = logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +* +* var mylogcdf = logcdf.factory( 2.0, 1.0 ); +* y = mylogcdf( 2.0 ); +* // returns ~-0.337 +*/ + +// 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/logcdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js new file mode 100644 index 000000000000..02a7826776d9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js @@ -0,0 +1,122 @@ +/** +* @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 erfcx = require( '@stdlib/math/base/special/erfcx' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var erfc = require( '@stdlib/math/base/special/erfc' ); +var exp = require( '@stdlib/math/base/special/exp' ); +var ln = require( '@stdlib/math/base/special/ln' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); + + +// MAIN // + +/** +* Evaluates the natural logarithm of 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 {PositiveNumber} mu - mean +* @param {NonNegativeNumber} lambda - shape parameter +* @returns {number} evaluated logCDF +* +* @example +* var y = logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +* +* @example +* var y = logcdf( 0.5, 2.0, 3.0 ); +* // returns ~-2.897 +* +* @example +* var y = logcdf( NaN, 1.0, 1.0 ); +* // returns NaN +* +* @example +* var y = logcdf( 1.0, NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = logcdf( 1.0, 1.0, NaN ); +* // returns NaN +* +* @example +* // Non-positive mean: +* var y = logcdf( 2.0, 0.0, 1.0 ); +* // returns NaN +* +* @example +* // Negative shape parameter: +* var y = logcdf( 2.0, 1.0, -1.0 ); +* // returns NaN +* +* @example +* // Zero shape parameter (degenerate distribution): +* var y = logcdf( 1.0, 1.0, 0.0 ); +* // returns 0.0 +* +* @example +* var y = logcdf( 0.0, 1.0, 1.0 ); +* // returns -Infinity +*/ +function logcdf( x, mu, lambda ) { + var t1; + var t2; + var a; + var b; + var z; + + if ( + isnan( x ) || + isnan( mu ) || + isnan( lambda ) || + mu <= 0.0 || + lambda < 0.0 + ) { + return NaN; + } + if ( lambda === 0.0 ) { + return ( x < mu ) ? NINF : 0.0; + } + if ( x <= 0.0 ) { + return NINF; + } + if ( x === PINF ) { + return 0.0; + } + z = sqrt( lambda / x ); + a = ( z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ); + b = ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ); + + // Φ(a) = 0.5 * erfc( -a / sqrt( 2 ) ) + t1 = 0.5 * erfc( -a ); + + // exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² ), as b² - a² = 2λ/μ; computing via `erfcx` avoids overflow of the exponential term for large `λ/μ`: + t2 = 0.5 * erfcx( b ) * exp( -a * a ); + return ln( t1 + t2 ); +} + + +// EXPORTS // + +module.exports = logcdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/native.js new file mode 100644 index 000000000000..0118420b5470 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/native.js @@ -0,0 +1,83 @@ +/** +* @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 natural logarithm of 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 {PositiveNumber} mu - mean +* @param {number} lambda - shape parameter +* @returns {number} evaluated logCDF +* +* @example +* var y = logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +* +* @example +* var y = logcdf( 0.5, 2.0, 3.0 ); +* // returns ~-2.897 +* +* @example +* var y = logcdf( NaN, 1.0, 1.0 ); +* // returns NaN +* +* @example +* var y = logcdf( 1.0, NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = logcdf( 1.0, 1.0, NaN ); +* // returns NaN +* +* @example +* // Non-positive mean: +* var y = logcdf( 2.0, 0.0, 1.0 ); +* // returns NaN +* +* @example +* // Negative shape parameter: +* var y = logcdf( 2.0, 1.0, -1.0 ); +* // returns NaN +* +* @example +* // Zero shape parameter (degenerate distribution): +* var y = logcdf( 1.0, 1.0, 0.0 ); +* // returns 0.0 +* +* @example +* var y = logcdf( 0.0, 1.0, 1.0 ); +* // returns -Infinity +*/ +function logcdf( x, mu, lambda ) { + return addon( x, mu, lambda ); +} + + +// EXPORTS // + +module.exports = logcdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json new file mode 100644 index 000000000000..1a6ffa070c8b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json @@ -0,0 +1,99 @@ +{ + "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/erfcx", + "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/exp", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/erfcx", + "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/exp", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf", + "@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/erfcx", + "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/exp", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/eps" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/package.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/package.json new file mode 100644 index 000000000000..a3fb80dec351 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/base/dists/wald/logcdf", + "version": "0.0.0", + "description": "Natural logarithm of the cumulative distribution function (CDF) for a Wald distribution.", + "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", + "logcdf", + "cumulative distribution", + "distribution function", + "logarithm", + "inverse gaussian", + "inverse-gaussian", + "wald", + "univariate", + "continuous" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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/logcdf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/addon.c new file mode 100644 index 000000000000..2c546488b674 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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/logcdf.h" +#include "stdlib/math/base/napi/ternary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_wald_logcdf ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c new file mode 100644 index 000000000000..4e88555706db --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c @@ -0,0 +1,76 @@ +/** +* @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/logcdf.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/erfcx.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/math/base/special/erfc.h" +#include "stdlib/math/base/special/exp.h" +#include "stdlib/math/base/special/ln.h" +#include "stdlib/constants/float64/pinf.h" +#include "stdlib/constants/float64/ninf.h" + +/** +* Evaluates the natural logarithm of 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 logCDF +* +* @example +* double y = stdlib_base_dists_wald_logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +*/ +double stdlib_base_dists_wald_logcdf( const double x, const double mu, const double lambda ) { + double t1; + double t2; + double a; + double b; + double z; + + 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 ) ? STDLIB_CONSTANT_FLOAT64_NINF : 0.0; + } + if ( x <= 0.0 ) { + return STDLIB_CONSTANT_FLOAT64_NINF; + } + if ( x == STDLIB_CONSTANT_FLOAT64_PINF ) { + return 0.0; + } + z = stdlib_base_sqrt( lambda / x ); + a = ( z * ( ( x / mu ) - 1.0 ) ) / stdlib_base_sqrt( 2.0 ); + b = ( z * ( ( x / mu ) + 1.0 ) ) / stdlib_base_sqrt( 2.0 ); + + // Φ(a) = 0.5 * erfc( -a / sqrt( 2 ) ) + t1 = 0.5 * stdlib_base_erfc( -a ); + + // exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² ), as b² - a² = 2λ/μ; computing via `erfcx` avoids overflow of the exponential term for large `λ/μ`: + t2 = 0.5 * stdlib_base_erfcx( b ) * stdlib_base_exp( -a * a ); + return stdlib_base_ln( t1 + t2 ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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/logcdf/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json new file mode 100644 index 000000000000..e39ea0fbdc54 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"expected":[-0.7677471309208188,-0.2787086340220627,0.0,-0.29186588079971265,-0.1914971235172907,-0.12731826437327878,-0.0610086784073224,-0.19028425707461988,-0.42681525205624893,-0.27244540801438005,-0.21251158404533438,-7.845946115029059e-13,-0.03849048984358715,-0.39578618408422156,-0.1898310436301173,-0.1318845431741165,-0.40646684018544416,-0.3032891917840776,-0.055637733176745294,-8.455943621096414e-7,-0.343219796523212,-0.30141601654141464,-0.10333296295995086,-0.05455642821892258,-0.04690587719185412,-1.2720808052052244,-0.0796962282143258,-0.47193573066608335,-0.4134530021156068,-0.11314697005967272,-0.03216471247353266,-0.020954752134945673,-0.015599520523660508,-0.022494116512983355,-0.4180621901857225,-0.18835293326522334,-0.16834635837723289,-0.3472847724996076,-0.24962076409812362,-0.08246932615110435,-0.128564918241411,-0.5020499338920977,-0.29038754396175376,-0.31169717833873184,-0.06904784684357243,-0.41970306762870274,-0.13612005685448972,-0.007271828416049349,-0.00015796160625364324,-0.3311220546908127,-0.11981911864755566,-0.13022790414103966,-0.0653217646127126,-4.003896732022639e-5,-0.4620331299491943,-0.0003188154680565489,-0.38204564060956536,-0.8363929373195002,-0.9756308487481092,-4.9411845947719495e-8,-0.07582593148795107,-0.11930444004258285,-0.0668266210026477,-0.30539528705537283,-0.08481174372338386,-0.4053973718067023,-0.0006811817874303994,-0.15181102110853595,-1.1102230246251571e-15,-0.23894111947821683,-0.4055153021544522,-0.5295901072426727,-0.7862467843532569,-0.23625035118551335,-0.7486181436475855,-0.2265031845816536,-0.23736214416237184,-2.734723628742852e-5,-7.799821085523022e-7,-1.9762834684280597,-0.17720845862335044,-1.6047335064319812,-0.06880222614093277,-1.4355755358673525,-0.6239490729338388,-0.44181840911139736,-0.004426075765944797,-0.7023753511957961,-9.821689340075041e-7,-0.16860071469676394,-3.60587923479994e-6,-0.3160273270864338,-0.3911833228365226,-0.006534973023468772,-0.2151583507497586,-0.21306433776438144,-0.4856215167778689,-1.0184441802713948,-0.01465861472109714,-0.44445041735898383],"lambda":[3.4182949858077,0.9845087298645656,5.465527946273955,2.5987593899852373,1.9216955103800584,4.579307057884379,1.1343018721139326,2.849717984377608,3.2133430829381417,0.9625108956354124,3.371665659695282,2.805442223488767,4.44468565429758,4.433179917864226,2.576160379504697,2.8223135910564094,1.2429981405376247,4.0473949070773045,1.1047542930351129,5.051094499713389,1.3111616354411055,2.4791400567783675,1.9453897196172838,2.127033864180355,0.7435161144635856,5.089596050430019,0.7752557258865956,4.691790733935846,4.281872205292993,0.5634391957954256,5.132801344678098,3.29014221448661,4.448297918820132,2.195027101153086,2.688822324137505,2.765846447298146,4.354168793562432,1.0658269785567476,2.178053638839283,2.4465233576499212,1.0990075318128263,3.228971380463501,4.1765257232579,2.0902869722580726,5.045447362285321,4.047817024997428,2.2199700297012663,3.2203653321442385,2.763466252624867,2.1367585182007534,2.4745642757442203,4.858879927127423,0.9078811141958649,3.6810595480822585,0.8716694632316103,4.085871270710637,4.709679246255085,1.1092181441653954,4.733287410506161,1.1788727460919293,3.540469013320017,3.8588567647538903,1.0619959125897238,0.8854344423505351,1.8389559714572234,4.6743120740445345,2.3544039623848314,1.1756405668437453,3.9509919918045346,0.7575567061807799,1.1668854923906204,0.8918320819250132,4.696797384360636,5.2324232762413505,5.2506265556158125,5.389614103339855,1.3940498868748703,1.2958007081806506,3.0941573004056924,3.9362339077236843,0.708912296787423,2.4916859851471442,3.7517927984576716,3.7068430245034776,3.583063243333941,3.7601678800755503,5.1289404412236514,2.4361888788779726,4.833015774842675,1.4828963428654718,3.7508439675908103,2.278758223315224,3.457467368389411,5.234726366211575,5.231852707886034,3.696323350359666,2.5707934765856386,2.576901884357016,4.49598988830824,0.7690569644559482],"mu":[3.8160297895874224,5.415908329124594,0.5098294457677306,8.665746474677183,10.490841684140882,7.1991516914171445,4.032161592390338,9.070624432050852,8.95913754370084,10.146402603476993,10.3407887338936,0.6393188110327748,3.145518185330049,9.616540905114231,8.967259935062401,5.443979290251943,8.29334647693589,8.09163507594657,3.9833185116217127,1.7374280764998846,10.452407505971397,3.8370171293839834,4.809014301721888,1.4821914990086722,3.3320938535172333,1.639139987037665,2.076902173790744,7.2304256442179655,2.412671924751886,4.255038874649795,4.277911019408543,0.812347895555013,3.5602582965202876,3.067131107032048,5.704614939345904,6.508542890761502,6.385499153243318,5.455690900264028,8.28023740277153,0.5799358125122351,7.512617541092614,8.748534915987456,7.756998715695716,10.23885645518659,3.995320845136445,6.490540061067665,6.785084839722879,2.8691921705940233,1.752709849172211,7.161709560199388,5.790151123415305,4.565825012287347,3.3744926752138635,1.3665683138289182,3.816929208869981,1.369492173041193,5.378418315644382,7.906194742649857,9.504535724332658,0.7024185800711331,2.9638803445504376,6.645498718228065,4.1742419240277355,3.4434500311712366,2.2486516607363467,9.609355017691701,1.6218297864010573,7.8910398111913835,0.9104660748344702,9.6503359649901,2.4004774221277865,6.356006929162634,7.4573009069662035,5.36451840194582,9.623368354860267,8.098812331662867,10.192812496623592,0.5020784910025795,1.351259073741264,7.433207181952219,6.113145747998349,6.602175262408755,5.426094194351745,8.691377983453759,8.123292392337401,5.377197644699508,3.031751898527508,5.176441314240477,1.2760245361187845,10.008952169986545,1.6231979378457735,7.677283728015991,5.00564795025744,2.255467934246715,4.465342050489921,9.362791987802348,5.264922150484514,3.403574128136217,3.373899777469633,7.00522245725154],"x":[2.2886880843138413,4.661388669370461,15.164537825110578,8.580338485008458,13.73915494763048,14.78806163179938,14.565318272075649,13.568291100825938,6.465840749368759,6.392777340057905,14.114190165765205,7.952657002508393,9.114945824077552,8.161810069690503,13.23329832865447,11.083797993173047,4.072572698806404,8.847293054194239,15.332814992757871,15.091450707842013,5.733962582801725,4.414253408195529,11.692845103537817,3.8068812632230715,14.916144031773209,1.0340519826411827,6.049544567572894,5.834829491402029,2.541050075694834,8.926839111319834,13.913346183645592,1.8991106264926323,14.162118502537885,13.7975473492501,4.63823867808127,10.206891349779566,11.007962728402008,3.7602702308618947,9.201457611508358,1.007840623581448,14.103987083350495,5.415650665670313,8.913242428108818,8.161362544753588,9.752927151712433,5.710525221039752,13.502196663522962,14.673184141520277,14.337243800801662,6.233993636353876,12.681184607155295,8.758226788742023,11.701801914149112,9.061904964813463,2.041727696636957,6.809354705327678,5.464970651498978,1.4324613631118366,3.44743466072849,11.453329627931085,7.069475744432183,14.31014936889021,14.333518753828798,3.085512672342392,5.547598155269018,8.114922860121514,11.372559054774827,12.47228776059942,14.081165874504084,6.484826227477347,2.0262069868905974,2.1184974441980264,3.783768749367585,7.5108876362044645,4.783809857133653,11.478873751152472,9.330246900115748,3.557435343536315,14.1381728603775,1.3212892380120955,7.414683128332771,1.1483921882614285,15.3653829284134,1.8773257335438212,4.372427980998328,4.673844934708131,13.958932918188475,2.5509970305581966,9.055487743895595,14.077839259589743,14.935055984159352,6.994637543926216,4.775892906574661,8.219044669142614,6.58180954850306,13.171497792989001,3.7732884595245677,1.482575506652672,13.263404058135288,2.4905187691408806]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..8abdaad6220e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl @@ -0,0 +1,78 @@ +#!/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: log, 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( 100 ) .* 15.0 .+ 0.5; +julia> mu = rand( 100 ) .* 10.0 .+ 0.5; +julia> lambda = rand( 100 ) .* 5.0 .+ 0.5; +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 ] = log( 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/logcdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js new file mode 100644 index 000000000000..8b8f8c6f6d02 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js @@ -0,0 +1,198 @@ +/** +* @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 logcdf = factory( 1.0, 1.0 ); + t.strictEqual( typeof logcdf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the created function returns `NaN`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 1.0, 1.0 ); + y = logcdf( NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NaN, 1.0 ); + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( 1.0, NaN ); + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NaN, NaN ); + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NaN, NaN ); + y = logcdf( 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 `0` when provided `+infinity` for `x`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 1.0, 0.0 ); + y = logcdf( PINF ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + logcdf = factory( 1.0, 1.0 ); + y = logcdf( PINF ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a valid `mu` and `lambda`, the function returns a function which returns `-infinity` when provided `-infinity` for `x`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 1.0, 0.0 ); + y = logcdf( NINF ); + t.strictEqual( y, NINF, 'returns expected value' ); + + logcdf = factory( 1.0, 1.0 ); + y = logcdf( NINF ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the created function always returns `NaN`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 0.0, 1.0 ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( -1.0, 1.0 ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NINF, 1.0 ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a negative `lambda`, the created function always returns `NaN`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 0.0, -1.0 ); + + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( 0.0, NINF ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( PINF, NINF ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NINF, NINF ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NaN, NINF ); + y = logcdf( 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 logcdf; + var y; + + logcdf = factory( 2.0, 0.0 ); + + y = logcdf( 2.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = logcdf( 3.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = logcdf( 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function evaluates the logcdf for `x` given parameters `mu` and `lambda`', function test( t ) { + var expected; + var lambda; + var logcdf; + var mu; + var x; + var y; + var i; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + logcdf = factory( mu[i], lambda[i] ); + y = logcdf( 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 ], 70 ), '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/logcdf/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.js new file mode 100644 index 000000000000..b45719a84984 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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 logcdf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logcdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a factory method for generating `logcdf` functions', function test( t ) { + t.strictEqual( typeof logcdf.factory, 'function', 'exports a factory method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js new file mode 100644 index 000000000000..25f41b057266 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js @@ -0,0 +1,149 @@ +/** +* @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 logcdf = 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 logcdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = logcdf( NaN, 1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logcdf( 0.0, NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logcdf( 0.0, 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the function always returns `NaN`', function test( t ) { + var y; + + y = logcdf( 2.0, 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, -1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NINF, 1.0 ); + 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 `0`', function test( t ) { + var y = logcdf( PINF, 1.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = logcdf( PINF, 1.0, 1.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `-infinity` for `x` and a valid `mu` and `lambda`, the function returns `-infinity`', function test( t ) { + var y = logcdf( NINF, 1.0, 0.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + y = logcdf( NINF, 1.0, 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a negative `lambda`, the function always returns `NaN`', function test( t ) { + var y; + + y = logcdf( 2.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 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 = logcdf( 2.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x equal to mu' ); + + y = logcdf( 3.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x greater than mu' ); + + y = logcdf( 1.0, 2.0, 0.0 ); + t.strictEqual( y, NINF, 'returns -infinity for x smaller than mu' ); + + t.end(); +}); + +tape( 'the function evaluates the logcdf for `x` given parameters `mu` and `lambda`', 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 = logcdf( 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 ], 70 ), '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/logcdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js new file mode 100644 index 000000000000..bf24920680d0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js @@ -0,0 +1,158 @@ +/** +* @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 logcdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logcdf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logcdf, '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 = logcdf( NaN, 1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logcdf( 0.0, NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logcdf( 0.0, 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the function always returns `NaN`', opts, function test( t ) { + var y; + + y = logcdf( 2.0, 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, -1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NINF, 1.0 ); + 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 `0`', opts, function test( t ) { + var y = logcdf( PINF, 1.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = logcdf( PINF, 1.0, 1.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `-infinity` for `x` and a valid `mu` and `lambda`, the function returns `-infinity`', opts, function test( t ) { + var y = logcdf( NINF, 1.0, 0.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + y = logcdf( NINF, 1.0, 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a negative `lambda`, the function always returns `NaN`', opts, function test( t ) { + var y; + + y = logcdf( 2.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 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 = logcdf( 2.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x equal to mu' ); + + y = logcdf( 3.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x greater than mu' ); + + y = logcdf( 1.0, 2.0, 0.0 ); + t.strictEqual( y, NINF, 'returns -infinity for x smaller than mu' ); + + t.end(); +}); + +tape( 'the function evaluates the logcdf for `x` given parameters `mu` and `lambda`', opts, function test( t ) { + var expected; + var lambda; + var mu; + var x; + var y; + var i; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + y = logcdf( 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 ], 70 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +});