diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/README.md new file mode 100644 index 000000000000..40a0361ea065 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/README.md @@ -0,0 +1,279 @@ + + +# Logarithm of Probability Density Function + +> [Wald][wald-distribution] distribution logarithm of [probability density function][pdf]. + +
+ +The [probability density function][pdf] for a [Wald][wald-distribution] random variable is + + + +```math +f(x;\mu,\lambda) = \sqrt{\frac{\lambda}{2\pi x^3}}\,\exp\!\left(-\frac{\lambda(x-\mu)^2}{2\mu^2 x}\right) +``` + + + +where `μ > 0` is the mean and `λ > 0` is the shape parameter. + +
+ + + +
+ +## Usage + +```javascript +var logpdf = require( '@stdlib/stats/base/dists/wald/logpdf' ); +``` + +#### logpdf( x, mu, lambda ) + +Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```javascript +var y = logpdf( 2.0, 2.0, 1.0 ); +// returns ~-1.959 + +y = logpdf( 1.0, 2.0, 1.0 ); +// returns ~-1.044 + +y = logpdf( 4.0, 2.0, 1.0 ); +// returns ~-3.123 +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = logpdf( NaN, 2.0, 1.0 ); +// returns NaN + +y = logpdf( 2.0, NaN, 1.0 ); +// returns NaN + +y = logpdf( 2.0, 2.0, NaN ); +// returns NaN +``` + +If provided `mu <= 0` or `lambda < 0`, the function returns `NaN`. + +```javascript +var y = logpdf( 2.0, 0.0, -3.0 ); +// returns NaN + +y = logpdf( 2.0, -1.0, -2.0 ); +// returns NaN + +y = logpdf( 2.0, -2.0, -1.0 ); +// returns NaN +``` + +If provided `x <= 0`, the function returns `-Infinity`. + +```javascript +var y = logpdf( 0.0, 2.0, 1.0 ); +// returns -Infinity + +y = logpdf( -1.0, 2.0, 1.0 ); +// returns -Infinity +``` + +If `lambda = 0`, the function evaluates the logarithm of the [PDF][pdf] of a [degenerate distribution][degenerate-distribution] centered at `mu`. + +```javascript +var y = logpdf( 2.0, 8.0, 0.0 ); +// returns -Infinity + +y = logpdf( 8.0, 8.0, 0.0 ); +// returns Infinity + +y = logpdf( 10.0, 8.0, 0.0 ); +// returns -Infinity +``` + +#### logpdf.factory( mu, lambda ) + +Returns a function for evaluating the natural logarithm of the [probability density function][pdf] of a [Wald][wald-distribution] distribution with parameters `mu` and `lambda`. + +```javascript +var mylogpdf = logpdf.factory( 1.0, 1.0 ); + +var y = mylogpdf( 2.0 ); +// returns ~-2.209 + +y = mylogpdf( 8.0 ); +// returns ~-7.101 +``` + +
+ + + +
+ +## 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 logpdf = require( '@stdlib/stats/base/dists/wald/logpdf' ); + +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, logpdf ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/wald/logpdf.h" +``` + +#### stdlib_base_dists_wald_logpdf( x, mu, lambda ) + +Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```c +double out = stdlib_base_dists_wald_logpdf( 2.0, 1.0, 1.0 ); +// returns ~-2.209 +``` + +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_logpdf( const double x, const double mu, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/wald/logpdf.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_logpdf( 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/logpdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/benchmark/benchmark.js new file mode 100644 index 000000000000..849c238ea6ce --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 logpdf = 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 = logpdf( 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 mylogpdf; + var x; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + mylogpdf = logpdf.factory( 1.0, 1.5 ); + x = uniform( 100, EPS, 10.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mylogpdf( 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/logpdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..9aecf7d7bc88 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 logpdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logpdf 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 = logpdf( 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/logpdf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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/logpdf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..5b62d5022b31 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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/logpdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "wald-logpdf" +#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_logpdf( 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/logpdf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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/logpdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/docs/repl.txt new file mode 100644 index 000000000000..b334900c183a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/docs/repl.txt @@ -0,0 +1,81 @@ + +{{alias}}( x, μ, λ ) + Evaluates the natural logarithm of the probability density function + (PDF) 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 logPDF. + + Examples + -------- + > var y = {{alias}}( 2.0, 1.0, 1.0 ) + ~-2.209 + > y = {{alias}}( 0.5, 2.0, 3.0 ) + ~-1.017 + > 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 ) + Infinity + > y = {{alias}}( 10.0, 8.0, 0.0 ) + -Infinity + + +{{alias}}.factory( μ, λ ) + Returns a function for evaluating the natural logarithm of the probability + density function (PDF) of a Wald distribution with mean `μ` and shape + parameter `λ`. + + Parameters + ---------- + μ: number + Mean parameter. + + λ: number + Shape parameter. + + Returns + ------- + logpdf: Function + Logarithm of probability density function (PDF). + + Examples + -------- + > var mylogpdf = {{alias}}.factory( 10.0, 2.0 ); + > var y = mylogpdf( 10.0 ) + ~-4.026 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/docs/types/index.d.ts new file mode 100644 index 000000000000..d492aa4d097d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 probability density function (PDF) for a Wald distribution. +* +* @param x - input value +* @returns evaluated logPDF +*/ +type Unary = ( x: number ) => number; + +/** +* Interface for the natural logarithm of the probability density function (PDF) of a Wald distribution. +*/ +interface LogPDF { + /** + * Evaluates the natural logarithm of the probability density function (PDF) 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 logPDF + * + * @example + * var y = logpdf( 2.0, 1.0, 1.0 ); + * // returns ~-2.209 + * + * @example + * var y = logpdf( 0.5, 2.0, 3.0 ); + * // returns ~-1.017 + * + * @example + * var y = logpdf( NaN, 1.0, 1.0 ); + * // returns NaN + * + * @example + * var y = logpdf( 0.0, NaN, 1.0 ); + * // returns NaN + * + * @example + * var y = logpdf( 0.0, 1.0, NaN ); + * // returns NaN + * + * @example + * // Nonpositive mean: + * var y = logpdf( 2.0, 0.0, 1.0 ); + * // returns NaN + * + * @example + * // Negative shape parameter: + * var y = logpdf( 2.0, 1.0, -1.0 ); + * // returns NaN + * + * @example + * // Degenerate distribution when `lambda = 0.0`: + * var y = logpdf( 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 probability density function (PDF) for a Wald distribution. + * + * @param mu - mean + * @param lambda - shape parameter + * @returns function to evaluate the natural logarithm of the probability density function + * + * @example + * var mylogpdf = logpdf.factory( 10.0, 2.0 ); + * var y = mylogpdf( 10.0 ); + * // returns ~-4.026 + * + * y = mylogpdf( 12.0 ); + * // returns ~-4.303 + */ + factory( mu: number, lambda: number ): Unary; +} + +/** +* Wald distribution natural logarithm of the probability density function (PDF). +* +* @param x - input value +* @param mu - mean +* @param lambda - shape parameter +* @returns evaluated logPDF +* +* @example +* var y = logpdf( 2.0, 1.0, 1.0 ); +* // returns ~-2.209 +* +* var mylogpdf = logpdf.factory( 10.0, 2.0 ); +* y = mylogpdf( 10.0 ); +* // returns ~-4.026 +*/ +declare var logpdf: LogPDF; + + +// EXPORTS // + +export = logpdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/docs/types/test.ts new file mode 100644 index 000000000000..d3dd8d5a61ba --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 logpdf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + logpdf( 2, 2, 4 ); // $ExpectType number + logpdf( 1, 2, 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than three numbers... +{ + logpdf( true, 3, 6 ); // $ExpectError + logpdf( false, 2, 4 ); // $ExpectError + logpdf( '5', 1, 2 ); // $ExpectError + logpdf( [], 1, 2 ); // $ExpectError + logpdf( {}, 2, 4 ); // $ExpectError + logpdf( ( x: number ): number => x, 2, 4 ); // $ExpectError + + logpdf( 9, true, 12 ); // $ExpectError + logpdf( 9, false, 12 ); // $ExpectError + logpdf( 5, '5', 10 ); // $ExpectError + logpdf( 8, [], 16 ); // $ExpectError + logpdf( 9, {}, 18 ); // $ExpectError + logpdf( 8, ( x: number ): number => x, 16 ); // $ExpectError + + logpdf( 9, 5, true ); // $ExpectError + logpdf( 9, 5, false ); // $ExpectError + logpdf( 5, 2, '5' ); // $ExpectError + logpdf( 8, 4, [] ); // $ExpectError + logpdf( 9, 4, {} ); // $ExpectError + logpdf( 8, 5, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + logpdf(); // $ExpectError + logpdf( 2 ); // $ExpectError + logpdf( 2, 0 ); // $ExpectError + logpdf( 2, 0, 4, 1 ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + logpdf.factory( 3, 4 ); // $ExpectType Unary +} + +// The `factory` method returns a function which returns a number... +{ + const fcn = logpdf.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 = logpdf.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 = logpdf.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... +{ + logpdf.factory( true, 3 ); // $ExpectError + logpdf.factory( false, 2 ); // $ExpectError + logpdf.factory( '5', 1 ); // $ExpectError + logpdf.factory( [], 1 ); // $ExpectError + logpdf.factory( {}, 2 ); // $ExpectError + logpdf.factory( ( x: number ): number => x, 2 ); // $ExpectError + + logpdf.factory( 9, true ); // $ExpectError + logpdf.factory( 9, false ); // $ExpectError + logpdf.factory( 5, '5' ); // $ExpectError + logpdf.factory( 8, [] ); // $ExpectError + logpdf.factory( 9, {} ); // $ExpectError + logpdf.factory( 8, ( x: number ): number => x ); // $ExpectError + + logpdf.factory( [], true ); // $ExpectError + logpdf.factory( {}, false ); // $ExpectError + logpdf.factory( false, '5' ); // $ExpectError + logpdf.factory( {}, [] ); // $ExpectError + logpdf.factory( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + logpdf.factory( 0 ); // $ExpectError + logpdf.factory( 0, 4, 8 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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/logpdf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/examples/c/example.c new file mode 100644 index 000000000000..d86c86571f9d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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/logpdf.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_logpdf( 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/logpdf/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/examples/index.js new file mode 100644 index 000000000000..41dcac2d4cc7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 logpdf = 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, logpdf ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 logpdf( x ) { + var v; + if ( isnan( x ) ) { + return NaN; + } + if ( x <= 0.0 || x === PINF ) { + return NINF; + } + v = x - mu; + return 0.5 * ( ln( lambda ) - ( LN_TWO_PI + ( 3.0 * ln( x ) ) ) - ( ( lambda * v * v ) / ( mu * mu * x ) ) ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/lib/index.js new file mode 100644 index 000000000000..f48cdf6e1d20 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 probability density function (PDF). +* +* @module @stdlib/stats/base/dists/wald/logpdf +* +* @example +* var logpdf = require( '@stdlib/stats/base/dists/wald/logpdf' ); +* +* var y = logpdf( 2.0, 1.0, 1.0 ); +* // returns ~-2.209 +* +* var mylogpdf = logpdf.factory( 2.0, 1.0 ); +* y = mylogpdf( 2.0 ); +* // returns ~-1.959 +*/ + +// 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/logpdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/lib/main.js new file mode 100644 index 000000000000..f56813ff4d81 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/lib/main.js @@ -0,0 +1,103 @@ +/** +* @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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var ln = require( '@stdlib/math/base/special/ln' ); +var LN_TWO_PI = require( '@stdlib/constants/float64/ln-two-pi' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); + + +// MAIN // + +/** +* Evaluates the natural logarithm of the probability density function (PDF) 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 logPDF +* +* @example +* var y = logpdf( 2.0, 1.0, 1.0 ); +* // returns ~-2.209 +* +* @example +* var y = logpdf( 0.5, 2.0, 3.0 ); +* // returns ~-1.017 +* +* @example +* var y = logpdf( NaN, 1.0, 1.0 ); +* // returns NaN +* +* @example +* var y = logpdf( 1.0, NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = logpdf( 1.0, 1.0, NaN ); +* // returns NaN +* +* @example +* // Non-positive mean: +* var y = logpdf( 2.0, 0.0, 1.0 ); +* // returns NaN +* +* @example +* // Negative shape parameter: +* var y = logpdf( 2.0, 1.0, -1.0 ); +* // returns NaN +* +* @example +* // Zero shape parameter (degenerate distribution): +* var y = logpdf( 1.0, 1.0, 0.0 ); +* // returns Infinity +* +* @example +* var y = logpdf( 0.0, 1.0, 1.0 ); +* // returns -Infinity +*/ +function logpdf( x, mu, lambda ) { + var v; + if ( + isnan( x ) || + isnan( mu ) || + isnan( lambda ) || + mu <= 0.0 || + lambda < 0.0 + ) { + return NaN; + } + if ( lambda === 0.0 ) { + return ( x === mu ) ? PINF : NINF; + } + if ( x <= 0.0 || x === PINF ) { + return NINF; + } + v = x - mu; + return 0.5 * ( ln( lambda ) - ( LN_TWO_PI + ( 3.0 * ln( x ) ) ) - ( ( lambda * v * v ) / ( mu * mu * x ) ) ); +} + + +// EXPORTS // + +module.exports = logpdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/lib/native.js new file mode 100644 index 000000000000..bd6c0d3d4ab9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 probability density function (PDF) 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 logPDF +* +* @example +* var y = logpdf( 2.0, 1.0, 1.0 ); +* // returns ~-2.209 +* +* @example +* var y = logpdf( 0.5, 2.0, 3.0 ); +* // returns ~-1.017 +* +* @example +* var y = logpdf( NaN, 1.0, 1.0 ); +* // returns NaN +* +* @example +* var y = logpdf( 1.0, NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = logpdf( 1.0, 1.0, NaN ); +* // returns NaN +* +* @example +* // Non-positive mean: +* var y = logpdf( 2.0, 0.0, 1.0 ); +* // returns NaN +* +* @example +* // Negative shape parameter: +* var y = logpdf( 2.0, 1.0, -1.0 ); +* // returns NaN +* +* @example +* // Zero shape parameter (degenerate distribution): +* var y = logpdf( 1.0, 1.0, 0.0 ); +* // returns Infinity +* +* @example +* var y = logpdf( 0.0, 1.0, 1.0 ); +* // returns -Infinity +*/ +function logpdf( x, mu, lambda ) { + return addon( x, mu, lambda ); +} + + +// EXPORTS // + +module.exports = logpdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/manifest.json new file mode 100644 index 000000000000..4bd5a6fbe257 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/manifest.json @@ -0,0 +1,90 @@ +{ + "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/ln", + "@stdlib/constants/float64/ln-two-pi", + "@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/ln", + "@stdlib/constants/float64/ln-two-pi", + "@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/ln", + "@stdlib/constants/float64/ln-two-pi", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/eps" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/package.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/package.json new file mode 100644 index 000000000000..ef6c7d5143c7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/base/dists/wald/logpdf", + "version": "0.0.0", + "description": "Natural logarithm of the probability density function (PDF) 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", + "pdf", + "logpdf", + "density", + "density function", + "logarithm", + "inverse gaussian", + "inverse-gaussian", + "wald", + "univariate", + "continuous" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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/logpdf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/src/addon.c new file mode 100644 index 000000000000..3424f34bd62a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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/logpdf.h" +#include "stdlib/math/base/napi/ternary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_wald_logpdf ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/src/main.c new file mode 100644 index 000000000000..6f980ed3e03a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/src/main.c @@ -0,0 +1,58 @@ +/** +* @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/logpdf.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/ln.h" +#include "stdlib/constants/float64/ln_two_pi.h" +#include "stdlib/constants/float64/pinf.h" +#include "stdlib/constants/float64/ninf.h" + +/** +* Evaluates the natural logarithm of the probability density function (PDF) 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 logPDF +* +* @example +* double y = stdlib_base_dists_wald_logpdf( 2.0, 1.0, 1.0 ); +* // returns ~-2.209 +*/ +double stdlib_base_dists_wald_logpdf( const double x, const double mu, const double lambda ) { + double v; + + 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_PINF : STDLIB_CONSTANT_FLOAT64_NINF; + } + if ( x <= 0.0 || x == STDLIB_CONSTANT_FLOAT64_PINF ) { + return STDLIB_CONSTANT_FLOAT64_NINF; + } + v = x - mu; + return 0.5 * ( stdlib_base_ln( lambda ) - ( STDLIB_CONSTANT_FLOAT64_LN_TWO_PI + ( 3.0 * stdlib_base_ln( x ) ) ) - ( ( lambda * v * v ) / ( mu * mu * x ) ) ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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/logpdf/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/fixtures/julia/data.json new file mode 100644 index 000000000000..af645789b732 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"expected":[-1.807356083766194,-3.7661876830471717,-4.09713952499646,-4.759875657168522,-1.435126244867679,-16.106102316430118,-3.5208010885749395,-4.6532484952404145,-3.9705125997818618,-4.731760216344789,-6.434275471300456,-3.930158626753529,-6.779220239094343,-4.769728385385832,-2.7090028005277293,-5.774116869662516,-3.8473949774033795,-1.3341796455155586,-3.399972265790514,-4.482601656535909,-2.7875520402374185,-1.9988705978491446,-4.546287907509452,-4.173410287832915,-4.434652718779226,-4.6570700428119105,-8.115448060901599,-2.673045062561434,-2.2376587054617714,-1.9822173136487486,-3.4139941507376554,-3.7060180924212696,-5.831901695256952,-3.410607071572126,-3.6488818569286052,-3.6046283842273574,-7.9478216935434745,-3.2165468646198776,-4.242523409247204,-1.5916372201464113,-3.078503363560462,-4.1129148038845615,-3.071257898639816,-3.7468156802413772,-4.128905023648782,-3.6666440527105593,-5.006424962458075,-4.870331584287318,-3.811441550441342,-3.8179639625980424,-4.492214719853926,-4.066358920385641,-2.221836410791899,-4.344237015730915,-5.865207986933859,-3.304487030353284,-2.962458872609372,-4.379261380826107,-1.5534406469448974,-5.541273973165811,-1.5358219992492863,-3.458192854155716,-2.119164060705691,-4.173383337179523,-1.5992318279489712,-5.521480875603727,-4.991650820085336,-3.569375315389194,-2.411455262394331,-2.3515691537828567,-3.424106071201136,-3.8160964981177554,-4.051705076848215,-2.2575151677186254,-3.846422441477871,-4.027576013880456,-1.776626180739711,-27.21179071242486,-5.643471706543188,-3.3760613154288452,-14.687664843959805,-3.539747703695054,-0.49282525156488555,-2.015042532620259,-1.996186513545724,-4.390160437755958,-8.337066318522536,-8.308429197681814,-3.874084653389918,-3.722499338080903,-5.463946601644408,-3.7984665113559326,-4.732499909224339,-2.305379177092935,-4.522220397929102,-5.34010790085401,-0.5047024576196902,-1.8880394072051447,-4.170591799956805,-8.40802666226443],"lambda":[2.0829780438523584,0.788907128812072,0.5826502094988851,0.9721255686101145,2.020432143043645,3.018307030660872,2.006869344300821,2.2022445556748886,0.727341999866994,0.9765600363108202,3.7627741407380433,3.1922707138048603,3.674457614801312,2.7772363489845686,4.181275984054642,2.2776056027422222,5.489907609816406,5.441388113344254,5.470206185697659,3.3889697837781867,1.1401322980733826,2.7627937417264943,2.2524588602360485,5.3014497413613615,3.856388882907787,1.2710760932100869,1.1112024981174264,1.9816031978517707,5.171772717386017,3.8034600449409086,4.760080771219022,1.604557701358534,1.2733675539669487,4.335883274471257,1.3986353010990822,2.1194909193500795,3.62985934370937,3.0825208253988308,2.7467678008483247,3.2199558674952358,1.5168342429393162,4.146350531099111,2.3061044907784094,2.443858700792048,4.357298768198664,2.068019582062124,0.8148320122801662,2.0405077322363434,4.444833310471711,2.553262439265859,4.732912191058152,0.6117839818626221,2.999565405234149,2.899310024112763,4.957139712891404,1.7508514525157832,1.3084022581265877,4.395145146161421,4.084011425310193,2.66011547049649,2.620457038240386,2.529892602007581,2.4301217459075612,2.455774125489231,5.11381643736844,0.9254570870204022,3.1864837549071705,1.8515788200851375,2.073533381124295,4.913262047558962,1.9876693411997677,1.3002216632116803,1.8462432401630164,4.5746152786971805,2.3503458821358,4.729319495474027,1.7016281735168306,5.048222406832838,2.1721232506085535,4.456945118492067,4.307459697650853,1.4868522257332262,2.9523430791772767,5.22062131730879,1.4442888866046366,0.5775533131284145,2.2473154515946248,1.8382838399540542,3.399759857747699,2.022013686153964,2.3651643880557063,3.1499185329405432,1.1568521200736415,4.942645117699139,2.461220955553476,1.1855235852543684,4.512101035468202,1.888274489844044,4.53217853652334,2.6910847663058552],"mu":[2.705237690570664,2.0174185780538507,4.417259267740106,8.11891999203111,6.178756905960784,1.0632565759477515,3.8105702759192788,3.564024081250132,5.447388409031971,7.070987346686483,2.2364258830406767,6.837012896133256,1.991731815145717,1.7237895391234188,5.092679884031784,1.423750955246907,5.8635279772478786,3.720313000116036,7.008589520428778,8.406632072798587,7.338859663851698,4.935112916816286,3.6961735784164933,7.674104304299979,7.726989404662392,1.2105227320374718,0.9698475188861895,6.782276075147356,8.678096295599731,9.53183814495321,9.49577690159986,4.496437906106843,2.386848587695935,5.610148555537841,7.937922064133462,3.2496812036224663,1.426129410893719,4.309878423785049,6.491257694247297,8.660354708596122,2.836328503943237,6.166297598480408,2.416601854085255,1.7097289582798032,10.029057080236784,10.179938830987073,8.515524448890524,4.1516779754854465,7.041293012179984,3.6988612193791734,4.092013386101564,8.329848314190336,6.307429014985896,2.5428293703708587,2.0966709881458687,7.676191873374184,1.1573758635074256,6.576032336457545,3.626464297908541,3.4970166228592356,9.78121926483119,9.182356712432584,7.447023634537737,3.101451644430602,3.5305529245756224,2.064015394005236,3.1271574996548908,6.779999122170629,5.596291764936209,5.181625640055231,7.230624442446645,6.543239585065949,5.956977016530007,5.919825419002402,4.46811141593913,3.086206781032314,9.253407837164355,1.1000442580720022,2.4164332491515568,10.077099434346303,0.9388582399014374,10.341401932289752,1.3225452186660565,6.144427539482325,6.734786455990657,7.486865822204306,1.1549852068187123,1.7271123117967997,7.981817033600624,3.5209311084887966,2.7332305896316162,4.1284402781605865,8.874680593439903,5.973217503081442,4.714281127005082,3.6124732477482198,1.3335169945054755,2.9840768863904996,9.72611298310989,1.0579872988825152],"x":[2.2929635764394347,5.382691519258584,6.888942297260575,12.718088941088066,1.2824888081653363,11.109735091063529,6.740275544960681,11.455919428090947,6.8612040729196835,12.41609496320854,10.909138434072561,10.62908655149402,10.146404129292808,6.370627669761742,5.310926809721271,6.8044592940375574,10.95650786032364,1.6542913692430372,9.05481028384292,15.367015603287474,3.5267671359094797,2.684009525007249,11.17610861515396,14.0088116968333,15.118471390167379,5.282677724788488,8.63015579067391,3.9256122719296958,3.492601395573761,0.7424532211306801,8.870063168231834,7.295510762296818,13.993647708357887,8.257437909127617,6.893814090846924,6.799596705772302,7.747337928114624,6.469558014970721,12.128906323767566,1.0739539270874432,4.6392348233914635,12.140369804993643,4.764210128678875,4.933531814762607,13.687396911709108,7.922625518545036,14.131051917259073,13.626554586545689,10.863381413567739,8.126185346686302,11.54971736167793,6.914612521611113,3.1823810784990645,8.009714306849368,8.241126032116671,5.880460361188619,2.97522060822683,14.287392932662257,2.2282185498050993,15.446681652794261,0.6663897122189256,7.3727145802564245,2.631006648457358,8.69571958476866,2.5868120012691973,11.753293747434382,11.483885528233369,7.185014604970533,3.334172571684492,4.3787014111985805,6.675975309457076,7.520736793030265,9.662483466812127,3.8636429315753364,8.647305569908605,8.04279467338117,1.6900780340901234,13.244116775228921,11.873235308043416,8.427609338387212,6.525107336621665,6.480288544072877,1.0307966435527152,3.165931741252435,2.0741401944664823,8.421658020022289,7.773777252730126,15.031921631578331,10.655394530426864,7.353281665295917,12.42189371229788,8.643769631836154,13.248342299218448,4.133462822881555,12.47909935781141,15.363599290845745,1.247410432371154,2.3276779417607747,14.146211886306677,6.285842982964795]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..272494b63bad --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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: logpdf, 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 ] = logpdf( 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/logpdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/test.factory.js new file mode 100644 index 000000000000..b88c7c6f4625 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 logpdf = factory( 1.0, 1.0 ); + t.strictEqual( typeof logpdf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the created function returns `NaN`', function test( t ) { + var logpdf; + var y; + + logpdf = factory( 1.0, 1.0 ); + y = logpdf( NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( NaN, 1.0 ); + y = logpdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( 1.0, NaN ); + y = logpdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( NaN, NaN ); + y = logpdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( NaN, NaN ); + y = logpdf( 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 `-infinity` when provided `+infinity` for `x`', function test( t ) { + var logpdf; + var y; + + logpdf = factory( 1.0, 0.0 ); + y = logpdf( PINF ); + t.strictEqual( y, NINF, 'returns expected value' ); + + logpdf = factory( 1.0, 1.0 ); + y = logpdf( PINF ); + t.strictEqual( y, NINF, '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 logpdf; + var y; + + logpdf = factory( 1.0, 0.0 ); + y = logpdf( NINF ); + t.strictEqual( y, NINF, 'returns expected value' ); + + logpdf = factory( 1.0, 1.0 ); + y = logpdf( 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 logpdf; + var y; + + logpdf = factory( 0.0, 1.0 ); + y = logpdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( -1.0, 1.0 ); + y = logpdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( NINF, 1.0 ); + y = logpdf( 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 logpdf; + var y; + + logpdf = factory( 0.0, -1.0 ); + + y = logpdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( 0.0, NINF ); + y = logpdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( PINF, NINF ); + y = logpdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( NINF, NINF ); + y = logpdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( NaN, NINF ); + y = logpdf( 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 logpdf; + var y; + + logpdf = factory( 2.0, 0.0 ); + + y = logpdf( 2.0 ); + t.strictEqual( y, PINF, 'returns expected value' ); + + y = logpdf( 3.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + y = logpdf( 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function evaluates the logpdf for `x` given parameters `mu` and `lambda`', function test( t ) { + var expected; + var lambda; + var logpdf; + 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++ ) { + logpdf = factory( mu[i], lambda[i] ); + y = logpdf( 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 ], 2 ), '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/logpdf/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/test.js new file mode 100644 index 000000000000..c8fb79a7c82a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 logpdf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logpdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a factory method for generating `logpdf` functions', function test( t ) { + t.strictEqual( typeof logpdf.factory, 'function', 'exports a factory method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/test.main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/test.main.js new file mode 100644 index 000000000000..e4e298f48c8b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 logpdf = 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 logpdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = logpdf( NaN, 1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logpdf( 0.0, NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logpdf( 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 = logpdf( 2.0, 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, -1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 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 `-infinity`', function test( t ) { + var y = logpdf( PINF, 1.0, 0.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + y = logpdf( PINF, 1.0, 1.0 ); + t.strictEqual( y, NINF, '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 = logpdf( NINF, 1.0, 0.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + y = logpdf( 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 = logpdf( 2.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 0.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 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 = logpdf( 2.0, 2.0, 0.0 ); + t.strictEqual( y, PINF, 'returns +infinity for x equal to mu' ); + + y = logpdf( 3.0, 2.0, 0.0 ); + t.strictEqual( y, NINF, 'returns -infinity for x greater than mu' ); + + y = logpdf( 1.0, 2.0, 0.0 ); + t.strictEqual( y, NINF, 'returns -infinity for x smaller than mu' ); + + t.end(); +}); + +tape( 'the function evaluates the logpdf 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 = logpdf( 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 ], 2 ), '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/logpdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/test/test.native.js new file mode 100644 index 000000000000..b1036c7e5935 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logpdf/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 logpdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logpdf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logpdf, '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 = logpdf( NaN, 1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logpdf( 0.0, NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logpdf( 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 = logpdf( 2.0, 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, -1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 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 `-infinity`', opts, function test( t ) { + var y = logpdf( PINF, 1.0, 0.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + y = logpdf( PINF, 1.0, 1.0 ); + t.strictEqual( y, NINF, '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 = logpdf( NINF, 1.0, 0.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + y = logpdf( 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 = logpdf( 2.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 0.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 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 = logpdf( 2.0, 2.0, 0.0 ); + t.strictEqual( y, PINF, 'returns +infinity for x equal to mu' ); + + y = logpdf( 3.0, 2.0, 0.0 ); + t.strictEqual( y, NINF, 'returns -infinity for x greater than mu' ); + + y = logpdf( 1.0, 2.0, 0.0 ); + t.strictEqual( y, NINF, 'returns -infinity for x smaller than mu' ); + + t.end(); +}); + +tape( 'the function evaluates the logpdf 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 = logpdf( 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 ], 2 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +});