diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/README.md new file mode 100644 index 000000000000..cf9b59159174 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/README.md @@ -0,0 +1,232 @@ + + +# Logarithm of Cumulative Distribution Function + +> Evaluate the natural logarithm of the cumulative distribution function (CDF) for a [half-normal][half-normal-distribution] distribution. + +
+ +
+ + + +
+ +## Usage + +```javascript +var logcdf = require( '@stdlib/stats/base/dists/halfnormal/logcdf' ); +``` + +#### logcdf( x, sigma ) + +Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [half-normal][half-normal-distribution] distribution with parameter `sigma` (standard deviation). + +```javascript +var y = logcdf( 2.0, 1.0 ); +// returns ~-0.0466 + +y = logcdf( 1.0, 2.0 ); +// returns ~-0.960 + +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = logcdf( NaN, 1.0 ); +// returns NaN + +y = logcdf( 0.0, NaN ); +// returns NaN +``` + +If provided `sigma < 0`, the function returns `NaN`. + +```javascript +var y = logcdf( 2.0, -1.0 ); +// returns NaN +``` + +If provided `sigma = 0`, the function returns `NaN`. + +```javascript +var y = logcdf( 2.0, 0.0 ); +// returns NaN +``` + +#### logcdf.factory( sigma ) + +Returns a `function` for evaluating the [cumulative distribution function][cdf] (CDF) of a [half-normal][half-normal-distribution] distribution with parameter `sigma` (standard deviation). + +```javascript +var mylogcdf = logcdf.factory( 2.0 ); + +var y = mylogcdf( 1.0 ); +// returns ~-0.960 + +y = mylogcdf( 4.0 ); +// returns ~-0.0466 +``` + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var logcdf = require( '@stdlib/stats/base/dists/halfnormal/logcdf' ); + +var opts = { + 'dtype': 'float64' +}; +var sigma = uniform( 10, 0.1, 20.0, opts ); +var x = uniform( 10, 0.0, 10.0, opts ); + +logEachMap( 'x: %lf, σ: %lf, ln(F(x;σ)): %lf', x, sigma, logcdf ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/halfnormal/logcdf.h" +``` + +#### stdlib_base_dists_halfnormal_logcdf( x, sigma ) + +Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [half-normal][half-normal-distribution] distribution with parameter `sigma` (standard deviation). + +```c +double out = stdlib_base_dists_halfnormal_logcdf( 2.0, 1.0 ); +// returns ~-0.046 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **sigma**: `[in] double` standard deviation. + +```c +double stdlib_base_dists_halfnormal_logcdf( const double x, const double sigma ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/halfnormal/logcdf.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 sigma; + double x; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + x = random_uniform( 0.0, 10.0 ); + sigma = random_uniform( 0.1, 20.0 ); + y = stdlib_base_dists_halfnormal_logcdf( x, sigma ); + printf( "x: %lf, σ: %lf, ln(F(x;σ)): %lf\n", x, sigma, y ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/benchmark.js new file mode 100644 index 000000000000..33b74782dd34 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/benchmark.js @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var logcdf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var sigma; + var len; + var x; + var y; + var i; + + len = 100; + x = uniform( len, -10.0, 10.0 ); + sigma = uniform( len, EPS, 20.0 + EPS ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = logcdf( x[ i % len ], sigma[ i % len ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::factory', pkg ), function benchmark( b ) { + var mylogcdf; + var sigma; + var x; + var y; + var i; + + sigma = 1.5; + mylogcdf = logcdf.factory( sigma ); + x = uniform( 100, -3.0, 6.0 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mylogcdf( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..616e83d22333 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/benchmark.native.js @@ -0,0 +1,68 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var logcdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logcdf instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var sigma; + var len; + var x; + var y; + var i; + + len = 100; + x = uniform( len, -10.0, 10.0 ); + sigma = uniform( len, EPS, 20.0 + EPS ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = logcdf( x[ i % len ], sigma[ 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/halfnormal/logcdf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/c/Makefile new file mode 100644 index 000000000000..7b114bb8537f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..c5731faab134 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/benchmark/c/benchmark.c @@ -0,0 +1,145 @@ +/** +* @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/halfnormal/logcdf.h" +#include +#include +#include +#include +#include + +#define NAME "halfnormal-logcdf" +#define ITERATIONS 1000000 +#define REPEATS 3 +#define LEN 100 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmark 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 x[ LEN ]; + double sigma[ LEN ]; + double y; + double t; + int i; + + for ( i = 0; i < LEN; i++ ) { + x[ i ] = random_uniform( -10.0, 10.0 ); // negatives allowed + sigma[ i ] = random_uniform( 0.1, 20.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_halfnormal_logcdf( + x[ i % LEN ], + sigma[ i % LEN ] + ); + 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; + + // Seed RNG: + 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/halfnormal/logcdf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/docs/repl.txt new file mode 100644 index 000000000000..07d040cf2638 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/docs/repl.txt @@ -0,0 +1,66 @@ +{{alias}}( x, σ ) + Evaluates the natural logarithm of the cumulative distribution function + (CDF) for a half-normal distribution with scale parameter `σ` at a value + `x`. + + If provided `NaN` as any argument, the function returns `NaN`. + + If provided `σ <= 0`, the function returns `NaN`. + + If provided `x < 0`, the function returns `-Infinity`. + + Parameters + ---------- + x: number + Input value. + + σ: number + Scale parameter. + + Returns + ------- + out: number + Evaluated logcdf. + + Examples + -------- + > var y = {{alias}}( 1.0, 1.0 ) + ~-0.382 + + > y = {{alias}}( -1.0, 1.0 ) + -Infinity + + > y = {{alias}}( NaN, 1.0 ) + NaN + + > y = {{alias}}( 1.0, NaN ) + NaN + + +{{alias}}.factory( σ ) + Returns a function for evaluating the natural logarithm of the cumulative + distribution function (CDF) of a half-normal distribution with scale + parameter `σ`. + + Parameters + ---------- + σ: number + Scale parameter. + + Returns + ------- + logcdf: Function + Logarithm of cumulative distribution function (CDF). + + Examples + -------- + > var mylogcdf = {{alias}}.factory( 2.0 ); + > var y = mylogcdf( 1.0 ) + ~-0.960 + + > y = mylogcdf( -1.0 ) + -Infinity + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/docs/types/index.d.ts new file mode 100644 index 000000000000..849d8f72541b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/docs/types/index.d.ts @@ -0,0 +1,105 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Evaluates the natural logarithm of the cumulative distribution function (CDF) +* for a half-normal distribution. +* +* @param x - input value +* @returns evaluated logcdf +*/ +type Unary = ( x: number ) => number; + +/** +* Interface for the natural logarithm of the cumulative distribution function +* (CDF) of a half-normal distribution. +*/ +interface LogCDF { + /** + * Evaluates the natural logarithm of the cumulative distribution function (CDF) + * for a half-normal distribution with scale parameter `sigma` at a value `x`. + * + * ## Notes + * + * - If `x < 0`, the function returns `-Infinity`. + * - If `sigma <= 0`, the function returns `NaN`. + * + * @param x - input value + * @param sigma - scale parameter + * @returns logarithm of cumulative distribution function + * + * @example + * var y = logcdf( 1.0, 1.0 ); + * // returns ~-0.382 + * + * @example + * var y = logcdf( -1.0, 1.0 ); + * // returns -Infinity + * + * @example + * var y = logcdf( NaN, 1.0 ); + * // returns NaN + * + * @example + * var y = logcdf( 1.0, NaN ); + * // returns NaN + */ + ( x: number, sigma: number ): number; + + /** + * Returns a function for evaluating the natural logarithm of the cumulative + * distribution function (CDF) for a half-normal distribution. + * + * @param sigma - scale parameter + * @returns logcdf + * + * @example + * var mylogcdf = logcdf.factory( 2.0 ); + * y = mylogcdf( 4.0 ); + * // returns ~-0.0466 + * + * y = mylogcdf( -1.0 ); + * // returns -Infinity + */ + factory( sigma: number ): Unary; +} + +/** +* Half-normal distribution natural logarithm of cumulative distribution +* function (CDF). +* +* @param x - input value +* @param sigma - scale parameter +* @returns evaluated logcdf +* +* @example +* var y = logcdf( 1.0, 1.0 ); +* // returns ~-0.382 +* +* var mylogcdf = logcdf.factory( 2.0 ); +* y = mylogcdf( 4.0 ); +* // returns ~-0.0466 +*/ +declare var logcdf: LogCDF; + + +// EXPORTS // + +export = logcdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/docs/types/test.ts new file mode 100644 index 000000000000..75d069d24cdf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/docs/types/test.ts @@ -0,0 +1,99 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import logcdf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + logcdf( 2, 4 ); // $ExpectType number + logcdf( 1, 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + logcdf( true, 3 ); // $ExpectError + logcdf( false, 2 ); // $ExpectError + logcdf( '5', 1 ); // $ExpectError + logcdf( [], 1 ); // $ExpectError + logcdf( {}, 2 ); // $ExpectError + logcdf( ( x: number ): number => x, 2 ); // $ExpectError + + logcdf( 9, true ); // $ExpectError + logcdf( 9, false ); // $ExpectError + logcdf( 5, '5' ); // $ExpectError + logcdf( 8, [] ); // $ExpectError + logcdf( 9, {} ); // $ExpectError + logcdf( 8, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + logcdf(); // $ExpectError + logcdf( 2 ); // $ExpectError + logcdf( 2, 4, 1 ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + logcdf.factory( 4 ); // $ExpectType Unary +} + +// The `factory` method returns a function which returns a number... +{ + const fcn = logcdf.factory( 4 ); + fcn( 2 ); // $ExpectType number +} + +// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... +{ + const fcn = logcdf.factory( 4 ); + fcn( true ); // $ExpectError + fcn( false ); // $ExpectError + fcn( '5' ); // $ExpectError + fcn( [] ); // $ExpectError + fcn( {} ); // $ExpectError + fcn( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... +{ + const fcn = logcdf.factory( 4 ); + fcn(); // $ExpectError + fcn( 2, 0 ); // $ExpectError + fcn( 2, 0, 1 ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided values other than one number... +{ + logcdf.factory( true ); // $ExpectError + logcdf.factory( false ); // $ExpectError + logcdf.factory( '5' ); // $ExpectError + logcdf.factory( [] ); // $ExpectError + logcdf.factory( {} ); // $ExpectError + logcdf.factory( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + logcdf.factory(); // $ExpectError + logcdf.factory( 0, 4 ); // $ExpectError +} + diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/examples/c/example.c new file mode 100644 index 000000000000..fb5a10ebde85 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/examples/c/example.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/halfnormal/logcdf.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 x; + double sigma; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + x = random_uniform( 0.0, 10.0 ); + sigma = random_uniform( 0.0, 20.0 ); + + y = stdlib_base_dists_halfnormal_logcdf( x, sigma ); + + printf( "x: %lf, σ: %lf, ln(F(x;σ)): %lf\n", x, sigma, y ); + } +} + diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/examples/index.js new file mode 100644 index 000000000000..eb664c35d8c7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/examples/index.js @@ -0,0 +1,31 @@ +/** +* @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 logcdf = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; + +var sigma = uniform( 10, 0.0, 20.0, opts ); +var x = uniform( 10, 0.0, 10.0, opts ); + +logEachMap( 'x: %lf, σ: %lf, ln(F(x;σ)): %lf', x, sigma, logcdf ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "dist", + "continuous", + "probability", + "cdf", + "logcdf", + "gaussian", + "halfnormal", + "bell-shape", + "logarithm", + "log", + "ln", + "natural", + "univariate" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/src/addon.c new file mode 100644 index 000000000000..e2c39964bff5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/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/halfnormal/logcdf.h" +#include "stdlib/math/base/napi/binary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_halfnormal_logcdf ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/src/main.c new file mode 100644 index 000000000000..3ec983073a14 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/src/main.c @@ -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. +*/ + +#include "stdlib/stats/base/dists/halfnormal/logcdf.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/erf.h" +#include "stdlib/math/base/special/ln.h" +#include "stdlib/constants/float64/ninf.h" +#include "stdlib/constants/float64/sqrt_two.h" + +static const double INV_SQRT_TWO = 1.0 / STDLIB_CONSTANT_FLOAT64_SQRT2; // 1/sqrt(2) + +/** +* Evaluates the natural logarithm of the cumulative distribution function (CDF) +* for a half-normal distribution with scale parameter `sigma` at a value `x`. +* +* @param x input value +* @param sigma scale parameter +* @return evaluated log CDF +* +* @example +* double y = stdlib_base_dists_halfnormal_logcdf( 1.0, 1.0 ); +* // returns ~-0.382 +*/ +double stdlib_base_dists_halfnormal_logcdf( const double x, const double sigma ) { + double z; + + if ( + stdlib_base_is_nan( x ) || + stdlib_base_is_nan( sigma ) || + sigma <= 0.0 + ) { + return 0.0 / 0.0; // NaN + } + if ( x < 0.0 ) { + return STDLIB_CONSTANT_FLOAT64_NINF; + } + + z = x / sigma; + + return stdlib_base_ln( stdlib_base_erf( z * INV_SQRT_TWO ) ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/fixtures/julia/REQUIRE @@ -0,0 +1,3 @@ +Distributions 0.23.8 +julia 1.5 +JSON 0.21 diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/fixtures/julia/data.json new file mode 100644 index 000000000000..baf1a26a97a6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"sigma":[2.5741033761728502,8.64831475027368,3.907871511514407,1.8699218257092354,3.6122263974607325,8.54577096385224,5.4729600547324155,4.331611477605195,8.551437465832208,7.434037109411834,3.2977629498432037,3.502449937822113,6.136815805777337,7.552234709996281,1.0772476521526697,0.17782822121354958,8.00543137605481,1.8479351728392301,9.814171904841462,9.155043010459655,7.759882653724639,4.238020139928381,5.208209169653415,8.048157306728918,9.591488171427217,1.8407383039583392,7.047913154717587,4.2379307692645,8.67613113830123,7.089278466700966,2.9352816053336674,1.3900729423774238,7.796749457985612,0.36955119456747454,7.530052369742176,9.09965820714316,2.6617547340159255,2.396958236448036,3.304114177333697,9.07940550511184,1.1883119551034038,2.6664336541884195,8.234378092002736,7.7343818975255925,6.123632481653862,9.787740178407944,7.959570469244342,0.1601106327838142,0.795261924180859,7.378212242208633,9.59013983344141,7.682001543586559,7.079650640381252,1.4454915123506162,6.751758516497571,4.889987778267685,1.0082748656102325,0.33867007826189677,8.66676828682354,4.3081659485311,6.0155373779049235,6.687170793180412,3.613853138916967,5.5842153719833965,9.214754995391463,6.262540605650679,5.346569200560385,5.84301541860266,4.13160194663274,7.709620395410387,1.4228550264523854,7.004037966521017,4.402400938314387,9.160658690529912,8.834368785528678,1.1667067908437523,1.4468191833867017,3.011134224317078,1.789246310263506,6.70470333505728,1.9172663778815624,1.0528306714097957,8.227115475208148,4.385963263557553,9.928277653128038,3.248880158299147,9.594711211239966,8.058138993758114,9.81715105261555,1.1924132541350185,6.606674418711941,2.1901030162324533,2.248610404395027,6.28332831201284,8.46357789912798,1.2403845380789258,5.560587440702774,4.292948539666346,9.83075873023781,3.636454470622615,4.513401527312027,5.896786335862492,1.5672476520158396,6.394316695430355,3.524119465097584,7.918434151265419,6.900207039226225,6.546165746784798,1.7690061653525146,6.214383187588398,1.2572851249237538,0.44782217011096526,6.100617042432267,3.9054570438577816,8.615737602749029,2.314930903443526,8.022279044961358,0.09105843386523427,0.8314274874256544,8.329554337313496,9.524795589650719,2.4758560527900944,6.6230201212594295,9.743783116196072,8.321483304173753,7.266751194519442,9.425139793827418,3.606008984802264,1.7386584185260134,2.5161518656750625,5.7981176864428665,0.5499433201232806,2.039404932463562,9.163281221572891,5.655776114102846,5.815998493820609,2.030274054274017,2.6463744772021105,3.276902953920434,2.215557115650263,5.973867873512827,9.045136677504411,9.551972390966574,8.749870472355148,1.1173507522709236,9.493667572222934,2.846954484254387,2.513538870854799,6.034479998572587,0.6421459813718811,2.4129873521138845,3.968158839594673,0.20690927695969696,4.020805859365758,9.516213117900444,4.400251292191544,0.3341181006839722,6.40547477913341,4.538451657591551,5.063132806302352,8.575542741350343,6.215419145196951,2.9202369411124285,5.7389760074246805,4.961961610652602,7.07318384699192,0.2818489313602024,4.9948295896155095,3.8204730761893835,4.406145459636895,4.850191462076539,5.738321894838201,1.5782426322473275,6.872412684031332,8.774650578739436,0.0025986361147389836,4.757802213376663,4.402037359745759,7.38723285324102,7.404644459923004,1.7429332738408665,7.938796613062264,2.335749552441102,7.436742387354517,6.76455739695427,4.13279178613549,8.359471641261699,3.4454246476834074,9.463825075801353,5.856592613870253,2.8295090151475333,5.45297928169759,7.04749145452373,3.8797649447679983,6.98518015910382,7.958940058232553,9.276514085834918,8.24850708489743,5.963284288820827,0.2612647171747773,6.360353831017898,1.512890824526325,3.4764084030384,2.7993355796356054,7.2954002024995335,8.762267724741948,3.3537431253766803,2.691978726196682,1.4217312919674319,2.854336676050664,6.775685320750343,0.7298885643388009,3.806904074501516,4.38938787443722,6.715224866243456,3.5836642062644652,9.416288583258673,6.532796903738033,8.369383951861733,4.345070900196204,3.956888321353861,4.519752809812099,2.3823603135137796,8.155242729521829,4.221462666287388,9.052295747900963,0.37951795579117986,3.4052607849714764,9.020928869717451,1.7921676758016547,2.4384008440466776,7.895293412539792,6.797958011410859,2.6815981160515356,1.5192450756169318,6.58130857899864,0.07449226344849791,2.6105139856167234,6.519491053095713,7.167243989688173,5.158964754549769,7.1476657443796014,5.3511207896269495,9.601973537587131,6.942801072577387,9.512022987954161,4.4408044402368665,5.611983592824487,8.737632666198586,2.5055330202578805,6.202010886866077,6.408082693865542,1.1477864009991001,8.922175429674658,6.901492342688398,9.201745792796057,4.515515136902534,8.541178660259085,5.864419856886741,8.810569946222376,2.0830765797746187,1.4233904231258754,4.665482087680989,4.296324936777899,6.806037118118086,1.1880712562021256,6.005162518165571,1.6140386510089522,7.186233697180063,6.71463100405679,8.326011911504391,5.994658967948601,3.0548619338514618,9.617044050189808,5.157436930663538,9.379026792299047,6.945330451430548,5.067110430978568,5.289154297586123,2.242648398129438,9.395125293092313,3.4679395756531948,0.45230927369732,7.989450193569042,2.8733624245293123,8.601385525490006,6.333332810855507,1.9481433365798195,5.204102740857717,2.5352650996713963,3.0930515141339243,3.2096995259627015,1.9690785867840854,6.093063293765965,1.1252695187658157,6.3127708925776025,9.150587825056283,3.3625252146697635,5.598273124208455,0.6309404303317556,9.939341223860747,7.444694493728157,3.9376277845719674,2.515828028411584,2.342931320801318,8.728520881350612,1.7556606084999704,1.1053415440722492,5.021589552040716,5.650475239286985,9.004883723433041,9.493049039336178,2.6513308288797965,8.28220319747389,6.699722908627038,7.595007556649599,8.086650702559542,3.4941405393013145,5.60477613549634,2.0966254104723605,4.599445487632389,8.635361937867735,9.115870814892164,2.9158048007360104,1.218387217473047,5.196594547287568,5.425572705389612,7.811041816672391,5.070048206140447,2.5555715288825276,2.39141306502101,1.1040688068055327,3.7005345676402057,9.565577016221905,2.6582198905368495,3.6894714930530768,8.089607072087631,3.2677083399747198,5.498864590011003,6.054883906187374,1.700942782131678,6.563392706437857,0.09636275709886455,6.444710680794298,3.6535891117008856,4.958147848018225,5.363548589387662,4.758346631319592,1.5361273161127709,9.305743357288058,5.822038673915842,6.293339386935863,5.643639341056232,3.937678004515969,0.8568594446827094,3.1042879246890887,0.5986772534579943,2.8111016507585616,7.964880514380612,7.156431184365165,4.593636996813456,7.619230967334981,1.1549405303551041,2.5726249330146445,9.323835174049863,4.514394818861076,8.584514162793216,8.659559356718878,1.7017744713816985,1.4591019565494356,5.009547403673068,2.670012261938166,4.970502486874201,0.21950973402793728,3.4368534350565607,0.18531121872495837,6.758889461669632,9.737120349935516,8.578594024292482,9.038385724677056,8.212302441367473,5.7909051730683645,8.66253104472796,0.16293748745384584,9.155545159209607,4.861636476919929,1.5559116800232176,5.654939863332711,9.694502278905833,5.340691441113141,1.346844889796125,2.5225843304865014,3.026696106596345,6.001870815747883,0.2095051852997265,6.0650007230313685,0.2987286939792211,2.8006246843185267,7.904802176609028,5.794523166437756,2.903133801692298,9.894476754203263,3.2392052302064602,5.555432330317906,0.07182827524621183,0.4400843988527392,0.5791851691536753,2.7635547579040622,2.945359073483129,4.931770047785045,5.015071931679858,9.196920182746657,2.4051358410554,7.48706229450598,5.362103357382537,7.766522735308512,3.9780156407292298,9.406411089632414,7.299075597276206,0.9936511089601163,2.2019075725461734,6.383326313948952,5.826468925108753,6.124910594783325,0.9877508805343194,9.769474724724859,9.914329797614169,2.469333334902978,4.005267320962145,1.4923055459376178,1.9859571218717553,0.8965711396341647,4.3306079686661105,8.027334208876844,4.076204680610385,3.6149221938020237,8.856424346499423,0.2996365373961529,8.635777424043503,1.886758909622287,0.19202379227463706,4.701733521551831,5.265691391883474,8.849638042186097,6.374086911341133,4.168542428921912,2.8868894804682643,4.870428094758036,6.4898705263164,6.355732339353084,8.517456951076007,0.09660793970128867,8.64790651530246,4.427395563177976,1.2242913995059368,0.8787616484839933,7.518410553322355,9.991091005204485,3.8290488355705907,7.074387125512329,3.8669138496592637,1.465578358703098,1.905935324453285,5.815586364711653,0.20918007114090198,7.010075032466792,4.955637373517609,0.08332454755995533,4.71163824301407,9.614957667928664,1.3178092800700258,4.0770757966315765,8.94343303698106,9.295873355548313,5.564251453601292,4.869967074856803,0.849142586189644,2.449240557613408,6.113395581225215,6.491021920768634,2.0462142817966944,7.370420788842421,0.09582437917443176,7.119878472894098,3.4498378076300495,8.36120267684424,0.2802858262371033,4.57015063430394,3.1853581577041847,1.288211983379044,6.37362969658507,7.187443655144018,5.421703905677835,9.928602880847047,4.372504295119568,7.165915497050727,8.968457775206378,5.615642732976247,9.02863832010482,1.3676018985357585,3.295609155287793,5.8974070972143515,8.651469531767095,9.919808392438622,9.932187789125734,7.063760817604473,6.2818635212293925,6.418515007612729,1.785798942603345,3.6253148086890397,4.3086955147459625,0.021192331626175287,8.742331698645073,7.286984102113593,9.642325788818024,0.4702484663482176,6.197310350461858,5.401845780287976,5.285012940515478,3.2908884911392122,4.154751622798955,2.169512314364873,1.4189959171162447,4.698866354272996,7.9262482178538685,9.436689956981573,5.312361480065439,6.585912778133154,8.186993304800096,5.890090942838709,2.035091963046356,8.666863737445935,4.020985141793323,0.9182339567387654,5.242048701123803,0.2920712006431525,5.90894356340994,7.784814893637584,6.447701467908215,4.405234598416532,0.7424136417007576,7.720245596951862,9.293542047302271,1.9310521789002844,5.78091986490262,3.3152856295570468,6.755672792516808,7.287889487167024,9.310266619092868,2.015140476312478,4.036627855572505,7.29608960179209,9.35184032222447,4.352751328648638,4.119753856957601,2.9018088216059934,0.7314975117130518,8.993340089637343,7.263557070712619,9.49227602460698,9.389801660365404,6.522792937167203,9.32765302847002,0.5944088317934471,6.96735852564541,7.346132135168917,9.532820888074793,4.063886273452004,5.336350272500678,6.8894956688207385,1.5871207547420485,5.286000472066451,9.9575867502716,0.49698734019265833,9.313283004587326,5.235446968274442,9.984533451189268,7.2096195862327095,6.791936500083819,8.322753944586323,4.853206068224995,3.138114645519524,7.382764823914265,4.863774618864095,6.137905245561656,6.018468456968179,1.3678360211549712,9.097873032451254,8.919505769386936,4.460425665771618,8.559144107728843,6.656960362019992,8.48105363741942,7.40951547101353,9.106874618770997,7.411076193848675,0.2992556723753803,7.0843769007632496,3.226982295009697,2.9108839068797687,2.511345576047966,4.515024768207171,6.68880829697568,2.6306427170667854,5.3489253178389085,7.472547279239818,5.914800392028718,2.6921967163597516,6.59133557458313,7.775133601892285,8.891354946677293,0.46055285538278756,2.087523653299047,0.03031853883310287,4.388994480123177,3.9212812446583447,4.695667142436307,8.661207888461716,4.8823983846785515,0.0036348924335949384,6.0759122708288515,5.168079148121826,3.420654244985888,9.845722913439397,5.155996087095466,9.578806598629955,2.2088084166728974,7.948898111087756,7.2485147829024745,5.666223184366485,9.56212704674295,7.625812837078207,2.840735541732935,8.002464725538122,8.8167938257477,1.4338976904164924,6.109435156276763,2.064611375493648,0.869819051185885,1.9031891668767542,5.833959448817884,9.713653575155526,3.5512393857631883,4.638107664907146,3.487866175702857,2.78979543815412,3.2456279591636408,4.379245982421589,1.338548914563903,2.8475988045924794,6.014275534227495,3.4794837745105545,3.0485003950497056,2.428470236394272,5.160803787508101,8.261127355036965,4.009169683691311,6.8096051900193855,2.7822976386467246,0.19520667769271527,6.042222115975424,8.990068490127992,1.4643123749273101,1.448244423133055,7.667626468417259,0.7846803136502012,1.82009656783361,3.537152665031744,2.471389382124942,4.916074534786424,4.41543682786507,1.6890658059721797,2.5766178559275863,9.45886881863766,0.5440832682278118,2.715721441874639,5.578020414188164,0.5501240981660227,5.859441573553822,7.900109554426628,7.405657444778666,3.5573316405091973,1.1561689017614118,2.600529511440872,8.351858556020893,7.751102175644476,6.139268387784464,8.40261044099409,9.685452958800779,3.747044188298725,8.229300294611697,6.24531117097059,8.198025806133053,2.7762088270160987,8.815900759862426,2.9682114049310107,2.1227221026131424,1.3525542082711595,6.699696901644227,7.307545189834197,0.14747781445437425,1.1231912988001258,6.927587427720161,1.1985457279502398,3.0109461407663787,0.35211643751678734,1.7198575850973885,5.9324139554263535,8.253582573175409,7.105536988957201,8.82772730361234,1.4370594124560687,7.516131122861431,3.5120458789346,3.608425741250072,2.3410355869877897,4.29248887732649,1.096817044379288,5.796983453650432,8.715919337688725,9.703844499376302,9.980397984697452,9.576470824737788,9.682883579011921,5.844203579233382,1.0429308475355226,8.794750509881236,7.4013470594016395,9.951001875917466,2.7674983214034454,8.75543525715539,0.5434677242562835,9.158515859090478,9.587329294128027,7.710913109262844,5.198425441695522,9.51556334790617,6.959938390594301,4.379804886144091,5.509674540408355,6.667850255155163,1.8158341283353774,1.2350368362589703,2.4840773154157434,8.994486158978379,7.496002625879629,1.5986835521779919,6.2206069733638305,4.734197998980896,1.4577559980435206,4.05194241444785,5.136520630057085,9.631670472080847,9.342165722983333,3.824803748354053,6.894308746437479,0.3551852670644229,1.4381827055715846,4.475754078165131,8.668302115069867,8.990025738833072,6.943717803671431,8.128724558138195,6.706216048531163,2.6064811188648687,0.6738227070677871,0.9251136001450222,3.545003171415204,5.7933373709091125,5.864638854516919,7.0750824006406905,6.281481234552553,0.5802549250348576,0.1646351315211081,6.2944565136206645,5.429941454653372,3.6012456031294793,8.921131722339895,0.3343758600678304,7.1817033394614125,3.9596301071862285,9.667898083022934,7.036864514887812,3.26811423248903,4.584587349435955,6.9437781723142,1.7540980375857063,6.46111951938402,6.593525650482247,4.443883621447159,6.563175575034592,3.7956569603639045,1.668926427668368,5.1157584704897605,8.587870620522954,2.006251850961005,3.016133391505419,1.4714840343539404,1.2913522277143918,8.922478582115168,5.5271982017910135,6.797238824059104,5.578207956434387,2.145595597156621,0.3254252669975355,1.068665885283363,9.459089967878002,1.4183046618578998,3.214141864345228,6.889698678994984,1.5987077968192842,5.487769129960941,7.172339112563724,7.860177612060193,4.293591781755444,6.0681164840672235,7.056831522542351,4.200548967696389,6.629488737984356,5.7385822670285025,5.691039121560832,2.479376677642601,3.870239179236873,6.141097543732315,3.5679881841891756,3.8513702243097425,7.011022421429123,7.3319750420282315,1.6594332156299274,8.86612131491985,0.47510676238612604,0.1268765432831498,3.5580425035273544,9.770935847370017,2.1205500664096446,5.53897464602271,2.339062948311578,6.500333803106417,6.815438245882729,3.1330706402524044,8.901774288187736,9.407122553208717,7.5381805837260005,2.2186943040973017,2.6736894992293117,1.2491050604844234,0.19136391858552093,5.511056215237133,6.545551174856889,3.8940309234542414,9.110317537728056,8.725215347601093,7.642543745454268,0.8084304165149148,9.336743357304346,8.191267326871937,9.606307973525846,5.8355600197105195,7.136391049075192,7.81489541087062,0.18740675623268643,7.608581625124593,3.600154008596965,1.097523577983185,3.0557480256552716,0.26358652359164125,9.788706583246507,7.7515362811930935,7.774007110738838,2.8231381200494288,1.8885405608307182,9.730221869288702,0.7098115526960891,1.8319146945422726,6.906977624735441,2.4818207236327163,5.869557084218155,8.41939603983294,3.7196691082820896,0.1616085862544503,1.199266892776818,2.556061556518805,3.22848963162097,9.134808610388598,3.0972182437239573,9.339768578336555,8.663806877519134,2.3220072480821505,9.964356367137377,8.018915272282651,9.545054631670455,7.309059857184699,8.060655601002582,9.36754835227753,4.210581565294697,9.103703166734284,2.183284019718348,4.405528715902336,3.164445854551241,5.493874092363498,2.319143618887823,1.8448876302844208,3.855501227211512,9.229684514394307,5.363063270942079,0.4408116007169216,8.414773812040051,1.8142808925152354,9.571209714759737,5.220357072851135,6.680571879591223,4.881932475072109,5.8517838319516935,0.3864836216931422,2.6542846719824906,8.747759844308511,5.546368312504184,0.49289486187452325,7.191394555555556,8.139574734107672,5.108916497983895,0.9000473260279862,9.41393819760184,1.6766353999979011,3.3326720464016124,0.9948309272116596,2.5671728926254547,3.367152102454397,1.615947191097693,8.617561664331953,9.900810167354493,0.8431044614656824,8.866179712695507,0.8742378879168622,9.311712817858123,6.351302024265371,7.609713992194676,9.918030453952055,7.116910414135143,0.46219530505005935,9.131326196872227,2.2734339115635205,9.365088686508392,0.5850552249599728,1.9276052303002311,6.5244907889023205,2.8056622021095667,7.6676094476244145,9.666239408861765,4.308658221556703,1.8016361439472584,2.645543531418737,4.962819133215116,7.664017071221052,1.1528090762329402,4.518037791111161,1.0567631436747216,1.7178490520604928,2.985926520931134,9.486023626440362,5.857647461448378,7.609684614244996,4.777326228637796,0.04184583302158429,3.9539190194888905,1.8350350279298,3.0087173999442474,1.0050530744720232,6.514550761724508,3.2044614560663764,6.250805113716618,1.1497796033146734,3.435044834146842,4.333684598905844,5.520438694979253,7.365407729635685,1.7932766826660018,8.680871061798593,5.321753600311326,8.116039921310051,5.326930490022789,0.8289498069863599,9.634675767317702,4.631007315333519,0.7020624241119688,2.2943330977601963,3.2538845481072265,7.645764463586233,6.405585199375769,4.072879743038874,6.048709722624834,7.312264261580324,0.7861769036041955,5.751715293355395,5.798266588421699,8.383841235505159,1.5048380360689328,7.461157167757194,7.20096175469132,1.9060343557573534],"expected":[-0.13080361614108849,-0.618440960485913,-0.5213972775268813,-0.42639812738393,-0.015890929619584826,-0.5153276508024912,-0.10375136254534056,-0.42933830864098044,-0.6620167501409863,-1.1284611520606815],"x":[3.9741860674215146,6.372472919225002,3.2451178227702293,1.7579960485788648,8.721009931493114,7.151250909792023,9.040899260853184,4.056179491840519,5.982409984179374,3.1021192598303604]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..e0d4af8f2737 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/fixtures/julia/runner.jl @@ -0,0 +1,65 @@ +#!/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: logcdf, Normal, Truncated +import JSON + +""" + gen( x, sigma, name ) + +Generate fixture data and write to file. + +# Arguments +* `x`: input values +* `sigma`: scale parameters +* `name::AbstractString`: output filename +""" +function gen( x, sigma, name ) + z = Array{Float64}( undef, length(x) ); + for i in eachindex(x) + d = Truncated( Normal( 0.0, sigma[i] ), 0.0, Inf ); + z[i] = logcdf( d, x[i] ); + end + + # Store data to be written to file as a collection: + data = Dict([ + ("x", x), + ("sigma", sigma), + ("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 a single fixture file: +x = rand( 10 ) .* 10.0; +sigma = rand( 1000 ) .* 10.0 .+ 1e-80; # Ensure sigma is positive +gen( x, sigma, "data.json" ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.factory.js new file mode 100644 index 000000000000..275e1d02765c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.factory.js @@ -0,0 +1,151 @@ +/** +* @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 abs = require( '@stdlib/math/base/special/abs' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var factory = require( './../lib/factory.js' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a function', function test( t ) { + var logcdf = factory( 1.0 ); + t.strictEqual( typeof logcdf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN` for `sigma`, the created function returns `NaN`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( NaN ); + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NaN ); + y = logcdf( NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the created function returns `0` when provided `+Infinity` for `x`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 1.0 ); + y = logcdf( PINF ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'the created function returns `-Infinity` when provided `-Infinity` for `x`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 1.0 ); + y = logcdf( NINF ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a negative `sigma`, the created function always returns `NaN`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( -1.0 ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NINF ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `sigma` equals `0`, the created function always returns `NaN`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 0.0 ); + + y = logcdf( PINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value'); + + y = logcdf( -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the created function evaluates the logcdf for `x` given `sigma`', function test( t ) { + var expected; + var logcdf; + var delta; + var sigma; + var tol; + var x; + var y; + var i; + + expected = data.expected; + x = data.x; + sigma = data.sigma; + + for ( i = 0; i < x.length; i++ ) { + logcdf = factory( sigma[ i ] ); + y = logcdf( x[ i ] ); + + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+', sigma: '+sigma[i]+', y: '+y+', expected: '+expected[i]); + } else { + delta = abs( y - expected[ i ] ); + tol = 1500.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. sigma: '+sigma[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.js new file mode 100644 index 000000000000..b45719a84984 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var logcdf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logcdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a factory method for generating `logcdf` functions', function test( t ) { + t.strictEqual( typeof logcdf.factory, 'function', 'exports a factory method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.logcdf.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.logcdf.js new file mode 100644 index 000000000000..b73ffb203fee --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.logcdf.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var abs = require( '@stdlib/math/base/special/abs' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var logcdf = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logcdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any argument, the function returns `NaN`', function test( t ) { + var y; + + y = logcdf( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( NaN, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `+Infinity` for `x`, the function returns `0`', function test( t ) { + var y = logcdf( PINF, 1.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `-Infinity` for `x`, the function returns `-Infinity`', function test( t ) { + var y = logcdf( NINF, 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `sigma <=0`, the function always returns `NaN`', function test( t ) { + var y; + + y = logcdf( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( PINF, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function evaluates the logcdf for `x` given `sigma`', function test( t ) { + var expected; + var delta; + var sigma; + var tol; + var x; + var y; + var i; + + expected = data.expected; + x = data.x; + sigma = data.sigma; + + for ( i = 0; i < x.length; i++ ) { + y = logcdf( x[ i ], sigma[ i ] ); + + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+', sigma: '+sigma[i]+', y: '+y+', expected: '+expected[i] ); + } else { + delta = abs( y - expected[ i ] ); + tol = 1500.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. sigma: '+sigma[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.native.js new file mode 100644 index 000000000000..140e40c2daa5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logcdf/test/test.native.js @@ -0,0 +1,139 @@ +/** +* @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 abs = require( '@stdlib/math/base/special/abs' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// VARIABLES // + +var logcdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logcdf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logcdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any argument, the function returns `NaN`', opts, function test( t ) { + var y; + + y = logcdf( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( NaN, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `+Infinity` for `x`, the function returns `0`', opts, function test( t ) { + var y = logcdf( PINF, 1.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `-Infinity` for `x`, the function returns `-Infinity`', opts, function test( t ) { + var y = logcdf( NINF, 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a negative `sigma`, the function always returns `NaN`', opts, function test( t ) { + var y; + + y = logcdf( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `sigma <=0`, the function always returns `NaN`', opts, function test( t ) { + var y; + + y = logcdf( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( PINF, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function evaluates the logcdf for `x` given `sigma`', opts, function test( t ) { + var expected; + var delta; + var sigma; + var tol; + var x; + var y; + var i; + + expected = data.expected; + x = data.x; + sigma = data.sigma; + + for ( i = 0; i < x.length; i++ ) { + y = logcdf( x[ i ], sigma[ i ] ); + + if ( y === expected[ i ] ) { + t.strictEqual( y, expected[ i ], 'x: '+x[i]+', sigma: '+sigma[i]+', y: '+y+', expected: '+expected[i] ); + } else { + delta = abs( y - expected[ i ] ); + tol = 1500.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. sigma: '+sigma[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +});