diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/README.md new file mode 100644 index 000000000000..8c4fc5c3c186 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/README.md @@ -0,0 +1,256 @@ + + +# Mean + +> [Wald][wald-distribution] distribution [expected value][mean]. + + + +
+ +The [expected value][mean] for a [Wald][wald-distribution] random variable with mean `μ` and shape parameter `λ > 0` is + + + +```math +\mathbb{E}\left[ X \right] = \mu +``` + + + + + +
+ + + + + +
+ +## Usage + +```javascript +var mean = require( '@stdlib/stats/base/dists/wald/mean' ); +``` + +#### mean( mu, lambda ) + +Returns the [expected value][mean] for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```javascript +var y = mean( 2.0, 1.0 ); +// returns 2.0 + +y = mean( 0.0, 1.0 ); +// returns NaN + +y = mean( -1.0, 4.0 ); +// returns NaN +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = mean( NaN, 1.0 ); +// returns NaN + +y = mean( 0.0, NaN ); +// returns NaN +``` + +If provided `mu <= 0` or `lambda <= 0`, the function returns `NaN`. + +```javascript +var y = mean( 0.0, 0.0 ); +// returns NaN + +y = mean( 0.0, -1.0 ); +// returns NaN + +y = mean( -1.0, 0.0 ); +// returns NaN +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## 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 mean = require( '@stdlib/stats/base/dists/wald/mean' ); + +var opts = { + 'dtype': 'float64' +}; +var mu = uniform( 10, EPS, 10.0, opts ); +var lambda = uniform( 10, EPS, 20.0, opts ); + +logEachMap( 'µ: %0.4f, λ: %0.4f, E(X;µ,λ): %0.4f', mu, lambda, mean ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/wald/mean.h" +``` + +#### stdlib_base_dists_wald_mean( mu, lambda ) + +Returns the [expected value][mean] for a [Wald][wald-distribution] distribution with mean `mu` and shape parameter `lambda`. + +```c +double out = stdlib_base_dists_wald_mean( 2.0, 1.0 ); +// returns 2.0 +``` + +The function accepts the following arguments: + +- **mu**: `[in] double` mean. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_wald_mean( const double mu, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/wald/mean.h" +#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 y; + int i; + + for ( i = 0; i < 10; i++ ) { + mu = random_uniform( 0.1, 5.0 ); + lambda = random_uniform( 0.1, 20.0 ); + y = stdlib_base_dists_wald_mean( mu, lambda ); + printf( "µ: %.4f, λ: %.4f, Mean(X;µ,λ): %.4f\n", mu, lambda, y ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/benchmark/benchmark.js new file mode 100644 index 000000000000..dd53b851ad54 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/benchmark/benchmark.js @@ -0,0 +1,59 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var mean = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var lambda; + var opts; + var mu; + var y; + var i; + + opts = { + 'dtype': 'float64' + }; + mu = uniform( 100, EPS, 100.0, opts ); + lambda = uniform( 100, EPS, 20.0, opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mean( mu[ i % 100 ], lambda[ i % 100 ] ); + 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/mean/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/benchmark/benchmark.native.js new file mode 100644 index 000000000000..529f081d381c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/benchmark/benchmark.native.js @@ -0,0 +1,69 @@ +/** +* @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 format = require( '@stdlib/string/format' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var mean = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mean instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var arrayOpts; + var lambda; + var mu; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + mu = uniform( 100, EPS, 100.0, arrayOpts ); + lambda = uniform( 100, EPS, 20.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mean( mu[ i % 100 ], lambda[ i % 100 ] ); + 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/mean/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/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/mean/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/benchmark/c/benchmark.c new file mode 100644 index 000000000000..1a4a2fa23df5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/benchmark/c/benchmark.c @@ -0,0 +1,140 @@ +/** +* @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/mean.h" +#include +#include +#include +#include +#include + +#define NAME "wald-mean" +#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 elapsed; + double lambda[ 100 ]; + double mu[ 100 ]; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + mu[ i ] = random_uniform( 0.1, 10.0 ); + lambda[ i ] = random_uniform( 0.1, 10.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_wald_mean( 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/mean/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/binding.gyp new file mode 100644 index 000000000000..f343843f5bd2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/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 for the add-on: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Set optimization level: + '-O3', + ], + + # C specific flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific 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 flags: + 'cflags': [ + # Generate position-independent code (PIC): + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target + + # Target to copy the add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Specify the target type: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be built before moving to a standard location: + '<(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 + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/docs/repl.txt new file mode 100644 index 000000000000..30595320e8e9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/docs/repl.txt @@ -0,0 +1,40 @@ + +{{alias}}( μ, λ ) + Returns the expected value of a Wald distribution with mean `μ` and + shape parameter `λ`. + + If provided `NaN` as any argument, the function returns `NaN`. + + If provided `μ <= 0` or `λ <= 0` the function returns `NaN`. + + Parameters + ---------- + μ: number + Mean parameter. + + λ: number + Shape parameter. + + Returns + ------- + out: number + Expected value. + + Examples + -------- + > var y = {{alias}}( 4.0, 2.0 ) + 4.0 + > y = {{alias}}( 0.0, 1.0 ) + NaN + > y = {{alias}}( 1.0, 0.0 ) + NaN + > y = {{alias}}( NaN, 1.0 ) + NaN + > y = {{alias}}( 0.0, NaN ) + NaN + > y = {{alias}}( 0.0, 0.0 ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/docs/types/index.d.ts new file mode 100644 index 000000000000..12e6f02811dc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/docs/types/index.d.ts @@ -0,0 +1,61 @@ +/* +* @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 + +/** +* Returns the expected value for a Wald distribution with mean `mu` and shape parameter `lambda`. +* +* ## Notes +* +* - If provided `mu <= 0` or `lambda <= 0`, the function returns `NaN`. +* +* @param mu - mean +* @param lambda - shape parameter +* @returns expected value +* +* @example +* var y = mean( 5.0, 2.0 ); +* // returns 5.0 +* +* @example +* var y = mean( 0.0, 1.0 ); +* // returns NaN +* +* @example +* var y = mean( 1.0, 0.0 ); +* // returns NaN +* +* @example +* var y = mean( NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = mean( 0.0, NaN ); +* // returns NaN +* +* @example +* var y = mean( 0.0, 0.0 ); +* // returns NaN +*/ +declare function mean( mu: number, lambda: number ): number; + + +// EXPORTS // + +export = mean; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/docs/types/test.ts new file mode 100644 index 000000000000..584afe7a8543 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @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 mean = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + mean( 5, 2 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + mean( true, 3 ); // $ExpectError + mean( false, 2 ); // $ExpectError + mean( '5', 1 ); // $ExpectError + mean( [], 1 ); // $ExpectError + mean( {}, 2 ); // $ExpectError + mean( ( x: number ): number => x, 2 ); // $ExpectError + + mean( 9, true ); // $ExpectError + mean( 9, false ); // $ExpectError + mean( 5, '5' ); // $ExpectError + mean( 8, [] ); // $ExpectError + mean( 9, {} ); // $ExpectError + mean( 8, ( x: number ): number => x ); // $ExpectError + + mean( [], true ); // $ExpectError + mean( {}, false ); // $ExpectError + mean( false, '5' ); // $ExpectError + mean( {}, [] ); // $ExpectError + mean( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + mean(); // $ExpectError + mean( 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/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/mean/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/examples/c/example.c new file mode 100644 index 000000000000..bd1fc1f63b32 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/examples/c/example.c @@ -0,0 +1,41 @@ +/** +* @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/mean.h" +#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 y; + int i; + + for ( i = 0; i < 10; i++ ) { + mu = random_uniform( 0.1, 10.0 ); + lambda = random_uniform( 0.1, 20.0 ); + y = stdlib_base_dists_wald_mean( mu, lambda ); + printf( "µ: %.4f, λ: %.4f, Mean(X;µ,λ): %.4f\n", mu, lambda, y ); + } +} + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/examples/index.js new file mode 100644 index 000000000000..05d0707d539f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/examples/index.js @@ -0,0 +1,32 @@ +/** +* @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 mean = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var mu = uniform( 10, EPS, 10.0, opts ); +var lambda = uniform( 10, EPS, 20.0, opts ); + +logEachMap( 'µ: %0.4f, λ: %0.4f, E(X;µ,λ): %0.4f', mu, lambda, mean ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/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': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "dist", + "moments", + "wald", + "inverse gaussian", + "inverse-gaussian", + "continuous", + "mean", + "average", + "avg", + "expected", + "univariate" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/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/mean/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/src/addon.c new file mode 100644 index 000000000000..921bcaca4890 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/src/addon.c @@ -0,0 +1,23 @@ +/** +* @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/mean.h" +#include "stdlib/math/base/napi/binary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_wald_mean ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/src/main.c new file mode 100644 index 000000000000..580c2746f1e8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/src/main.c @@ -0,0 +1,43 @@ +/** +* @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/mean.h" +#include "stdlib/math/base/assert/is_nan.h" + +/** +* Returns the expected value for a Wald distribution with mean `mu` and shape parameter `lambda`. +* +* @param mu mean +* @param lambda shape parameter +* @return expected value +* +* @example +* double y = stdlib_base_dists_wald_mean( 0.0, 1.0 ); +* // returns NaN +*/ +double stdlib_base_dists_wald_mean( const double mu, const double lambda ) { + if ( + stdlib_base_is_nan( mu ) || + stdlib_base_is_nan( lambda ) || + lambda <= 0.0 || + mu <= 0.0 + ) { + return 0.0/0.0; // NaN + } + return mu; +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/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/mean/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/fixtures/julia/data.json new file mode 100644 index 000000000000..cfbe8ef7b6da --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"expected":[9.332225166166651,4.889545882546147,8.398178040760154,8.28051688606067,10.037308954804253,2.502718542102402,7.361144462873464,4.6290650686210615,3.876004579200079,6.422275131670353,5.847241707222778,6.366914991757955,6.3136965687091315,1.2616538066411815,4.603872427242848,6.537353892173539,8.152422851677493,1.0464547963763833,2.710612560595008,5.944344069327309,0.6086555872000572,0.9402142643524798,1.8975149191791791,2.5592660212610725,8.411190477424839,1.4511014402516482,4.2799661543123335,2.512582270176002,5.478377943405063,6.625790372383061,8.036417885893009,1.1434235434431035,7.248202965261169,8.544775430784588,6.5271560990783035,1.3854073031905918,3.7908552390293435,1.815739884828775,4.825403589669921,5.960258859303156,3.925089029468621,2.959680175704071,1.7875516365929784,6.213426082693141,8.64994577208829,3.9929816134159095,7.035341816019935,5.139750121604752,6.747818783777024,5.693593444380466,7.05406684061938,4.450504155891876,5.252334634220371,9.944308223267468,9.689955196930264,6.153056956375431,4.9280542385342905,2.7205997321763338,2.249596354937495,6.750055582351145,3.635697451623767,6.020983582313165,2.0717837310856453,8.981456445786328,3.3955035997359415,3.195439266997708,3.840112632688915,9.099141700744402,4.696500733424958,7.94650546435074,5.2091615442465065,7.0753291610803855,2.740360721587835,9.234198915716275,3.6722035577834906,10.427889780083783,4.740324983370824,8.842418004545316,6.979281384206059,4.802591338824032,1.2394947382676298,5.485967425903818,6.57451079630462,6.8115020527796055,9.467064551440531,1.5936804087224317,6.171478312926959,2.0670836797282597,1.8768815259656886,2.357093610486099,8.092423494889843,7.126466335129598,2.039090122605643,1.83883305304474,2.2139656913364543,5.313101099755819,10.313940850710054,6.407997714085795,4.90624429117303,6.326134887572925],"lambda":[2.4381925339491883,2.628465773755839,2.012417715510364,4.908152011660872,5.437712855580483,3.5147627620188313,3.5654756243202126,1.8864035976287563,3.7214821935143028,3.561295494770946,3.99299654368766,4.182714373347759,2.4322312368001797,1.0850379207148493,4.923607937241683,5.331454019181694,2.885192532622818,1.483219707457349,2.9188646901231543,3.6952372936097966,4.044363988019289,2.2253627070979007,0.7157494318796016,2.5543836806138067,3.491759685024702,4.175978377393404,1.1971987046049544,1.4297733585547903,3.3168607368505656,1.7768518171807341,3.050144075381506,3.5717388711090257,2.9973851576862938,4.921262332163632,2.0709001666268954,4.021963050650139,1.8658212960501874,2.626395603412256,3.4583673042203102,2.187448743710048,3.7608721257528988,4.909961938230089,4.309411892351908,4.847204812153579,3.3013301053257162,3.735041861540103,3.9436456488137104,1.0593494505193513,3.5335201403084366,1.815217279102599,4.438149145243953,2.5166107154618116,1.7890831926346662,0.6945042774788941,0.8330606603588548,4.474369071322663,4.365752800064446,3.433469757679817,5.187358162841649,1.444228760121607,1.3943371916314646,3.472040323569132,3.3563074908211323,5.137951285727967,1.6930458678935019,5.340337861356611,0.5945486754970865,2.0903826812135193,4.866339711556141,5.444112989230162,2.95153432830598,5.210912576640788,3.643765833412289,3.450363742570289,1.9534999609813204,3.419278729046406,4.571560172147398,4.138778622086694,0.9524871199264641,2.0320347697315673,2.395740547765334,2.3449989306891252,4.903041379839658,3.949913109763868,3.633227998396955,2.1386778304411327,4.8926733895923045,4.595379354367254,3.563893013691468,1.9479695009488813,2.825428629673149,4.153716960254766,5.034786199791013,3.7156836571853247,1.6200482700114267,1.2675216445740574,4.4435733332893,3.8831446700592065,5.337445608606271,4.497655899808191],"mu":[9.332225166166651,4.889545882546147,8.398178040760154,8.28051688606067,10.037308954804253,2.502718542102402,7.361144462873464,4.6290650686210615,3.876004579200079,6.422275131670353,5.847241707222778,6.366914991757955,6.3136965687091315,1.2616538066411815,4.603872427242848,6.537353892173539,8.152422851677493,1.0464547963763833,2.710612560595008,5.944344069327309,0.6086555872000572,0.9402142643524798,1.8975149191791791,2.5592660212610725,8.411190477424839,1.4511014402516482,4.2799661543123335,2.512582270176002,5.478377943405063,6.625790372383061,8.036417885893009,1.1434235434431035,7.248202965261169,8.544775430784588,6.5271560990783035,1.3854073031905918,3.7908552390293435,1.815739884828775,4.825403589669921,5.960258859303156,3.925089029468621,2.959680175704071,1.7875516365929784,6.213426082693141,8.64994577208829,3.9929816134159095,7.035341816019935,5.139750121604752,6.747818783777024,5.693593444380466,7.05406684061938,4.450504155891876,5.252334634220371,9.944308223267468,9.689955196930264,6.153056956375431,4.9280542385342905,2.7205997321763338,2.249596354937495,6.750055582351145,3.635697451623767,6.020983582313165,2.0717837310856453,8.981456445786328,3.3955035997359415,3.195439266997708,3.840112632688915,9.099141700744402,4.696500733424958,7.94650546435074,5.2091615442465065,7.0753291610803855,2.740360721587835,9.234198915716275,3.6722035577834906,10.427889780083783,4.740324983370824,8.842418004545316,6.979281384206059,4.802591338824032,1.2394947382676298,5.485967425903818,6.57451079630462,6.8115020527796055,9.467064551440531,1.5936804087224317,6.171478312926959,2.0670836797282597,1.8768815259656886,2.357093610486099,8.092423494889843,7.126466335129598,2.039090122605643,1.83883305304474,2.2139656913364543,5.313101099755819,10.313940850710054,6.407997714085795,4.90624429117303,6.326134887572925]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..dd137b329ab9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/fixtures/julia/runner.jl @@ -0,0 +1,73 @@ +#!/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: mean, InverseGaussian +import JSON + +""" + gen( mu, lambda, name ) + +Generate fixture data and write to file. + +# Arguments + +* `mu`: mean parameter +* `lambda`: shape parameter +* `name::AbstractString`: output filename + +# Examples + +``` julia +julia> mu = rand( 1000 ) .* 10.0 .+ 0.1; +julia> lambda = rand( 1000 ) .* 5.0 .+ 0.1; +julia> gen( mu, lambda, "data.json" ); +``` +""" +function gen( mu, lambda, name ) + z = Array{Float64}( undef, length(mu) ); + for i in eachindex(mu) + z[ i ] = mean( InverseGaussian( mu[i], lambda[i] ) ); + end + + # Store data to be written to file as a collection: + data = Dict([ + ("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: +mu = rand( 100 ) .* 10.0 .+ 0.5; +lambda = rand( 100 ) .* 5.0 .+ 0.5; +gen( mu, lambda, "data.json" ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/test.js new file mode 100644 index 000000000000..d71b01199f7d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/test.js @@ -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. +*/ + +'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 mean = 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 mean, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = mean( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = mean( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = mean( NaN, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `lambda`, the function returns `NaN`', function test( t ) { + var y; + + y = mean( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the function returns `NaN`', function test( t ) { + var y; + + y = mean( 0.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( -1.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, PINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the expected value of a Wald distribution', function test( t ) { + var expected; + var lambda; + var mu; + var y; + var i; + + expected = data.expected; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < mu.length; i++ ) { + y = mean( mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 20 ), 'within tolerance. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/test.native.js new file mode 100644 index 000000000000..20c76ab8ba72 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mean/test/test.native.js @@ -0,0 +1,130 @@ +/** +* @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 mean = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mean instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mean, '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 = mean( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = mean( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = mean( NaN, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `lambda`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = mean( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = mean( 0.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( -1.0, 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, PINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( NINF, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the expected value of a Wald distribution', opts, function test( t ) { + var expected; + var lambda; + var mu; + var y; + var i; + + expected = data.expected; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < mu.length; i++ ) { + y = mean( mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[i], 20 ), 'within tolerance. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +});