diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/README.md new file mode 100644 index 000000000000..768b6df18671 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/README.md @@ -0,0 +1,254 @@ + + +# Mode + +> [Wald][wald-distribution] distribution [mode][mode]. + + + +
+ +The [mode][mode] for a [Wald][wald-distribution] random variable with mean `μ` and shape parameter `λ > 0` is + + + +```math +\mathop{\mathrm{mode}}\left( X \right) = \mu \cdot \frac{\sqrt{4\lambda^2 + 9\mu^2} - 3\mu}{2\lambda} +``` + + + + + +where `μ > 0` is the mean and `λ > 0` is the shape parameter. + +
+ + + + + +
+ +## Usage + +```javascript +var mode = require( '@stdlib/stats/base/dists/wald/mode' ); +``` + +#### mode( mu, lambda ) + +Returns the [mode][mode] for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```javascript +var y = mode( 2.0, 1.0 ); +// returns ~0.325 + +y = mode( 5.0, 2.0 ); +// returns ~0.655 + +y = mode( 1.0, 1.0 ); +// returns ~0.303 +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = mode( NaN, 1.0 ); +// returns NaN + +y = mode( 1.0, NaN ); +// returns NaN +``` + +If provided `mu <= 0` or `lambda <= 0`, the function returns `NaN`. + +```javascript +var y = mode( 0.0, 1.0 ); +// returns NaN + +y = mode( -1.0, 1.0 ); +// returns NaN + +y = mode( 1.0, 0.0 ); +// returns NaN + +y = mode( 1.0, -1.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 mode = require( '@stdlib/stats/base/dists/wald/mode' ); + +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, mode(X;µ,λ): %0.4f', mu, lambda, mode ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/wald/mode.h" +``` + +#### stdlib_base_dists_wald_mode( mu, lambda ) + +Returns the mode for a Wald distribution with mean `mu` and shape parameter `lambda`. + +```c +double out = stdlib_base_dists_wald_mode( 2.0, 1.0 ); +// returns ~0.325 +``` + +The function accepts the following arguments: + +- **mu**: `[in] double` mean. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_wald_mode( const double mu, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/wald/mode.h" +#include "stdlib/constants/float64/eps.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( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + lambda = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + y = stdlib_base_dists_wald_mode( mu, lambda ); + printf("µ: %.4f, λ: %.4f, mode(X;µ,λ): %.4f\n", mu, lambda, y); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/benchmark.js new file mode 100644 index 000000000000..1fa85a43d236 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/benchmark.js @@ -0,0 +1,57 @@ +/** +* @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 mode = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var lambda; + var len; + var mu; + var y; + var i; + + len = 100; + mu = uniform( len, EPS, 100.0 ); + lambda = uniform( len, EPS, 20.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mode( mu[ i%len ], lambda[ i%len ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/benchmark.native.js new file mode 100644 index 000000000000..5c2850a1e51d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/benchmark.native.js @@ -0,0 +1,67 @@ +/** +* @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 mode = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mode instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var lambda; + var len; + var mu; + var y; + var i; + + len = 100; + mu = uniform( len, EPS, 100.0 ); + lambda = uniform( len, EPS, 20.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mode( mu[ i%len ], lambda[ i%len ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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 := 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/mode/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/c/benchmark.c new file mode 100644 index 000000000000..4355594ee9ac --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/benchmark/c/benchmark.c @@ -0,0 +1,141 @@ +/** +* @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/mode.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "wald-mode" +#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 elapsed; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + mu[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 100.0 ); + lambda[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_wald_mode( 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/mode/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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/mode/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/docs/repl.txt new file mode 100644 index 000000000000..12c1eebc4d1d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/docs/repl.txt @@ -0,0 +1,40 @@ + +{{alias}}( μ, λ ) + Returns the mode 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. + + λ: number + Shape parameter. + + Returns + ------- + out: number + Mode. + + Examples + -------- + > var y = {{alias}}( 2.0, 1.0 ) + ~0.325 + > y = {{alias}}( 5.0, 2.0 ) + ~0.655 + > y = {{alias}}( NaN, 1.0 ) + NaN + > y = {{alias}}( 1.0, NaN ) + NaN + > y = {{alias}}( 0.0, 1.0 ) + NaN + > y = {{alias}}( 1.0, 0.0 ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/docs/types/index.d.ts new file mode 100644 index 000000000000..a01f40bc7d3b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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 mode 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 parameter +* @param lambda - shape parameter +* @returns mode +* +* @example +* var y = mode( 2.0, 1.0 ); +* // returns ~0.325 +* +* @example +* var y = mode( 5.0, 2.0 ); +* // returns ~0.655 +* +* @example +* var y = mode( NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = mode( 1.0, NaN ); +* // returns NaN +* +* @example +* var y = mode( 0.0, 1.0 ); +* // returns NaN +* +* @example +* var y = mode( 1.0, 0.0 ); +* // returns NaN +*/ +declare function mode( mu: number, lambda: number ): number; + + +// EXPORTS // + +export = mode; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/docs/types/test.ts new file mode 100644 index 000000000000..9560727f82c0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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 mode = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + mode( 2, 1 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + mode( true, 3 ); // $ExpectError + mode( false, 2 ); // $ExpectError + mode( '5', 1 ); // $ExpectError + mode( [], 1 ); // $ExpectError + mode( {}, 2 ); // $ExpectError + mode( ( x: number ): number => x, 2 ); // $ExpectError + + mode( 9, true ); // $ExpectError + mode( 9, false ); // $ExpectError + mode( 5, '5' ); // $ExpectError + mode( 8, [] ); // $ExpectError + mode( 9, {} ); // $ExpectError + mode( 8, ( x: number ): number => x ); // $ExpectError + + mode( [], true ); // $ExpectError + mode( {}, false ); // $ExpectError + mode( false, '5' ); // $ExpectError + mode( {}, [] ); // $ExpectError + mode( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + mode(); // $ExpectError + mode( 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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/mode/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/examples/c/example.c new file mode 100644 index 000000000000..167f285aaef1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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/mode.h" +#include "stdlib/constants/float64/eps.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 < 25; i++ ) { + mu = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + lambda = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + y = stdlib_base_dists_wald_mode( mu, lambda ); + printf( "µ: %lf, λ: %lf, mode(X;µ,λ): %lf\n", mu, lambda, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/examples/index.js new file mode 100644 index 000000000000..cd7cc0634ab7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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 mode = 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, mode(X;µ,λ): %0.4f', mu, lambda, mode ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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", + "wald", + "inverse gaussian", + "continuous", + "mode", + "location", + "center", + "univariate" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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/mode/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/src/addon.c new file mode 100644 index 000000000000..b4a2a63b81ec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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/mode.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_wald_mode ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/src/main.c new file mode 100644 index 000000000000..cd01c7ab9878 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/src/main.c @@ -0,0 +1,46 @@ +/** +* @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/mode.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/sqrt.h" + +/** +* Returns the mode for a Wald distribution with mean `mu` and shape parameter `lambda`. +* +* @param mu mean of the distribution +* @param lambda shape parameter of the distribution +* @return mode of the Wald distribution +* +* @example +* double y = stdlib_base_dists_wald_mode( 2.0, 1.0 ); +* // returns ~0.325 +*/ +double stdlib_base_dists_wald_mode( const double mu, const double lambda ) { + double numerator; + if ( + stdlib_base_is_nan( mu ) || + stdlib_base_is_nan( lambda ) || + lambda <= 0.0 || + mu <= 0.0 + ) { + return 0.0/0.0; // NaN + } + numerator = stdlib_base_sqrt( 4.0*lambda*lambda + 9.0*mu*mu ) - 3.0*mu; + return mu * numerator / ( 2.0*lambda ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/test/fixtures/julia/data.json new file mode 100644 index 000000000000..110d8a043148 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"expected":[0.19771648773026074,0.9929120185008405,1.182997322602162,1.1572409852016254,1.0490856061303862,0.4756026934914126,0.9985214763927229,0.9982378756856061,1.1037706323598548,0.8501420460583701,1.205787969485026,0.3047895843566855,1.0115443516350768,0.8164127892110501,0.3856373833080713,0.1020844734569049,0.18410268037738595,0.8839510327887087,1.540147869841245,0.6673092583059197,0.8584012788620154,1.0991578258671004,0.7289864387782278,0.515920548202662,0.5259169501244607,0.7961684531202058,1.1161711755161703,0.2259288227091103,0.8212289301794822,0.792887531831247,0.8373294611524162,0.5113018509454658,0.37111602056325965,0.3451482807922219,0.32543923424157123,1.1259049541024395,0.6078812510466131,0.763606628062365,0.7371190533695787,1.4301306133847855,0.14301127145406758,0.45702332890230296,1.4602854880957146,0.29599625398005164,0.1942975529315782,0.8162645299308274,0.04874243413996844,1.2689644102946482,0.7190041593732336,0.2773179203014947,0.45913471116156557,1.05339057881822,1.2593163127325349,0.515827968469626,1.2362520359444606,1.1743113022711638,0.6892438358099608,1.2581000309819026,1.193987289239968,0.2656158602416078,1.1575042762750114,1.0195879506065468,1.14751373350056,0.6824869878296524,0.4391279966549337,0.8743871588127551,1.2760794054973552,1.1788590704066162,1.2690584984584936,1.0170511439803458,1.155890086240397,1.3983415865385425,0.461110096788869,0.5637011102335544,0.44018087883911877,0.9007719647787203,0.2560430707079243,1.4963067795584306,0.03480935391345486,0.5050663974917842,0.34426657073708394,1.114748486336591,0.42224428537458064,0.9900757656743594,0.38820649237543964,0.6956313588886626,0.6449032275136337,0.19721098922486166,1.2446727550037113,0.22737950682787367,0.40073277322607537,1.0458742681970759,0.6538020564302395,0.28221657895171165,0.6814977498294789,0.06334463067432082,0.1967904402642043,0.07923789332747858,0.12892487719461992,0.7950163571601029],"lambda":[0.5947445303276804,3.5295735086252407,3.736286876771658,5.061878292196841,3.2747453962949695,1.5071073953324987,3.2079407611887754,4.207590107885586,3.5798989608564606,2.6265495371841614,3.962228252455812,0.9196878754872594,3.1988520078262828,3.041436894504949,1.1663616579471647,0.30638616930316764,0.5920952628254726,3.357135442345321,5.033339766005345,2.105260276784565,2.70305725795358,3.849828011156601,2.455364491079579,1.5648473776546967,1.607092388136907,2.5084452411267564,4.015546725222358,0.679020736252796,2.8119817522876924,2.527776795447568,2.6660765639252957,1.554871305890499,1.126388156626229,1.0900771509480367,0.981278741679255,3.848675020680325,1.8509936076770594,2.559509821630568,2.2820181198682543,4.82896241992373,0.42972680275442865,1.6639843610075773,4.991188342357092,0.9444311802132875,0.5842313485262517,3.791595439501556,0.14637095825292648,4.510265742814838,3.819393037142544,0.9900402046781314,1.388131898265248,4.245402214485755,4.133046434494139,1.64191814796852,3.972997464248218,4.955378306155783,2.2387640413220047,4.446299299428974,3.802117613368887,0.8004414212476201,3.640563386104552,3.8362874451977222,4.141100487108268,2.2560518305239885,1.3841079329015205,3.247925880679753,4.596671299402271,5.0159110447623405,4.084522228391273,3.245620314484075,4.987541088712345,4.495606159452912,1.9770129088339723,2.2386326841545308,1.3362026691223994,2.9576000420911384,0.7761582803160376,5.008204991152713,0.10445231922615753,1.5417808623268936,1.0582157557670784,3.974791251812323,1.3396934706152224,3.677129401490573,1.178966716680252,3.225170583085819,4.1868600201799735,0.5948775780194947,3.987406465896455,0.6848924169771341,1.2093921687072395,3.264462200171763,2.1723686133782554,0.8930331438035709,3.0438481839890046,0.1901150993307026,0.6336494206128134,0.2385021195768793,0.387107086105004,3.645967148032876],"mu":[3.8178479805321066,2.513391559732005,5.283733233046507,2.064713893693516,5.3169681666944895,2.060442437151996,3.880766585687032,1.859270032612,4.02969033469306,4.993731733029314,4.087112051896462,4.007747569967314,4.464474679305272,1.8501866499142006,4.284411196470825,4.904319472687602,0.7102056088536813,1.928551022250792,5.377372517013266,3.012045833074121,3.9469516060068806,2.9018286148857926,2.2048649435930185,4.937442037969451,3.8922090194369723,3.641040164086488,2.7386051467861345,5.29917669775321,2.333441369504282,3.264535898152123,3.482956233318964,4.403209572249717,3.449160181247714,1.5417343775434889,4.57698812848203,3.2185870993330057,5.0008484975567224,2.356798149418713,4.188971594771924,4.282341555033459,3.5612585820676856,1.0892878191542943,4.1759637632468865,1.2107892789877757,4.059006933180697,1.371626779747956,1.5558690408306004,3.213348370459049,1.0898415294826882,0.6939961086540093,5.222769665556005,2.0834729188132597,4.296315499900392,2.150878542700169,4.793643897780668,2.1841515119550534,2.4936625731628643,3.2361611486958104,4.961893801324051,3.9640523412515565,5.387495546244801,2.264766730034068,2.79392112368269,2.244508567124897,2.0000242167478173,1.993648943951826,3.121018890126114,2.170719498452092,4.870132156679317,4.154978903496381,2.0939024364168155,5.407871346471554,0.8414575614792242,1.1398208757474855,4.06603403552845,3.066003590176104,2.517419554356939,4.646853153564721,2.284189407862841,3.846525987629034,2.2214062641967076,2.7988249568685766,1.8093486445100506,2.2581004104797913,3.5190820412488053,1.17093182646644,0.879306092521739,2.670322021206152,4.93750153529275,3.5858217122340164,5.195864037972876,5.305889709262265,2.0980240767716616,1.2383259932636181,1.1893674243744967,3.064929981578701,0.7529990464834903,1.378144731339337,4.399326202203795,1.351882681062683]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..2c0808f39764 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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: mode, 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 ) .* 5.0 .+ 0.5; +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 ] = mode( 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 ) .* 5.0 .+ 0.5; +lambda = rand( 100 ) .* 5.0 .+ 0.1; +gen( mu, lambda, "data.json" ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/mode/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/test/test.js new file mode 100644 index 000000000000..97df4f6460ef --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/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 mode = 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 mode, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = mode( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = mode( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = mode( NaN, NaN ); + 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 = mode( 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( -1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NINF, PINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NaN, NINF ); + 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 = mode( 1.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( 1.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the mode 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 = mode( 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], 1000 ), '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/mode/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/test/test.native.js new file mode 100644 index 000000000000..65d4cd78f305 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/mode/test/test.native.js @@ -0,0 +1,133 @@ +/** +* @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 mode = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mode instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mode, '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 = mode( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = mode( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = mode( NaN, NaN ); + 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 = mode( 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( -1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NINF, PINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NaN, NINF ); + 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 = mode( 1.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( 1.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( PINF, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mode( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the mode 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 = mode( 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], 1000 ), 'within tolerance. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +});