diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/README.md b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/README.md new file mode 100644 index 000000000000..9c20e78973fc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/README.md @@ -0,0 +1,271 @@ + + +# Quantile Function + +> [Half-normal][halfnormal-distribution] distribution [quantile function][quantile-function]. + +
+ +The [quantile function][quantile-function] for a [Half-normal][halfnormal-distribution] random variable is + + + +```math +Q(p;\sigma) = \sigma\sqrt{2}\,\mathop{\mathrm{erf}}^{-1}(p) +``` + + + + + +for `0 <= p < 1`, where `σ > 0` is the scale parameter. + +
+ + + +
+ +## Usage + +```javascript +var quantile = require( '@stdlib/stats/base/dists/halfnormal/quantile' ); +``` + +#### quantile( p, sigma ) + +Evaluates the [quantile function][quantile-function] for a [Half-normal][halfnormal-distribution] distribution with scale parameter `sigma`. + +```javascript +var y = quantile( 0.5, 1.0 ); +// returns ~0.674 + +y = quantile( 0.8, 2.0 ); +// returns ~2.563 +``` + +If provided a probability `p` outside the interval `[0,1]`, the function returns `NaN`. + +```javascript +var y = quantile( 1.9, 1.0 ); +// returns NaN + +y = quantile( -0.1, 1.0 ); +// returns NaN +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = quantile( NaN, 1.0 ); +// returns NaN + +y = quantile( 0.0, NaN ); +// returns NaN +``` + +If provided `sigma < 0`, the function returns `NaN`. + +```javascript +var y = quantile( 0.4, -1.0 ); +// returns NaN +``` + +If provided `sigma = 0`, the function evaluates the [quantile function][quantile-function] of a [degenerate distribution][degenerate-distribution] centered at `0`. + +```javascript +var y = quantile( 0.3, 0.0 ); +// returns 0.0 + +y = quantile( 0.9, 0.0 ); +// returns 0.0 +``` + +#### quantile.factory( sigma ) + +Returns a function for evaluating the [quantile function][quantile-function] of a [Half-normal][halfnormal-distribution] distribution with parameter `sigma`. + +```javascript +var myquantile = quantile.factory( 4.0 ); + +var y = myquantile( 0.2 ); +// returns ~1.013 + +y = myquantile( 0.8 ); +// returns ~5.126 +``` + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var quantile = require( '@stdlib/stats/base/dists/halfnormal/quantile' ); + +var opts = { + 'dtype': 'float64' +}; +var sigma = uniform( 10, 0.0, 20.0, opts ); +var p = uniform( 10, 0.0, 1.0, opts ); + +logEachMap( 'p: %lf, σ: %lf, Q(p;σ): %lf', p, sigma, quantile ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/halfnormal/quantile.h" +``` + +#### stdlib_base_dists_halfnormal_quantile( p, sigma ) + +Evaluates the [quantile function][quantile-function] for a [Half-normal][halfnormal-distribution] distribution with parameter `sigma` (scale). + +```c +double y = stdlib_base_dists_halfnormal_quantile( 0.8, 1.0 ); +// returns ~1.282 +``` + +The function accepts the following arguments: + +- **p**: `[in] double` probability. +- **sigma**: `[in] double` scale parameter. + +```c +double stdlib_base_dists_halfnormal_quantile( const double p, const double sigma ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/halfnormal/quantile.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 sigma; + double p; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + p = random_uniform( 0.0, 1.0 ); + sigma = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + y = stdlib_base_dists_halfnormal_quantile( p, sigma ); + printf( "p:%lf, σ: %lf, Q(p;σ): %lf\n", p, sigma, y ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/benchmark/benchmark.js new file mode 100644 index 000000000000..2815ef3fd5c8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/benchmark/benchmark.js @@ -0,0 +1,93 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var pkg = require( './../package.json' ).name; +var quantile = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var sigma; + var len; + var p; + var y; + var i; + + len = 100; + p = new Float64Array( len ); + sigma = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + p[ i ] = uniform( 0.0, 1.0 ); + sigma[ i ] = uniform( EPS, 20.0 ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = quantile( p[ 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( pkg+':factory', function benchmark( b ) { + var myquantile; + var sigma; + var len; + var p; + var y; + var i; + + sigma = 4.0; + myquantile = quantile.factory( sigma ); + len = 100; + p = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + p[ i ] = uniform( 0.0, 1.0 ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = myquantile( p[ 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/quantile/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/benchmark/benchmark.native.js new file mode 100644 index 000000000000..6e7ed876ec0a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/benchmark/benchmark.native.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var Float64Array = require( '@stdlib/array/float64' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var quantile = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( quantile instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var sigma; + var len; + var p; + var y; + var i; + + len = 100; + p = new Float64Array( len ); + sigma = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + p[ i ] = uniform( 0.0, 1.0 ); + sigma[ i ] = uniform( EPS, 20.0 ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = quantile( p[ 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/quantile/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/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/quantile/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/benchmark/c/benchmark.c new file mode 100644 index 000000000000..50195b410ece --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/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/halfnormal/quantile.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "halfnormal-quantile" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double p[ 100 ]; + double sigma[ 100 ]; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + p[ i ] = random_uniform( 0.0, 1.0 ); + sigma[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_halfnormal_quantile( p[ i % 100 ], sigma[ 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/halfnormal/quantile/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/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/quantile/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/docs/repl.txt new file mode 100644 index 000000000000..3a54c869fe9a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/docs/repl.txt @@ -0,0 +1,81 @@ +{{alias}}( p, σ ) + Evaluates the quantile function for a Half-Normal distribution with scale + parameter `σ` at a probability `p`. + + If `p < 0` or `p > 1`, the function returns `NaN`. + + If provided `NaN` as any argument, the function returns `NaN`. + + If provided `σ < 0`, the function returns `NaN`. + + If `σ = 0`, the function returns `0`. + + If `p = 1`, the function returns `+∞`. + + Parameters + ---------- + p: number + Input probability. + + σ: number + Scale parameter. + + Returns + ------- + out: number + Evaluated quantile function. + + Examples + -------- + > var y = {{alias}}( 0.8, 1.0 ) + ~1.2816 + + > y = {{alias}}( 0.5, 2.0 ) + ~1.3490 + + > y = {{alias}}( 0.5, 4.0 ) + ~2.6980 + + > y = {{alias}}( 1.1, 1.0 ) + NaN + + > y = {{alias}}( -0.2, 1.0 ) + NaN + + > y = {{alias}}( NaN, 1.0 ) + NaN + + > y = {{alias}}( 0.0, NaN ) + NaN + + // Negative scale parameter: + > y = {{alias}}( 0.5, -1.0 ) + NaN + + +{{alias}}.factory( σ ) + Returns a function for evaluating the quantile function of a Half-Normal + distribution with scale parameter `σ`. + + Parameters + ---------- + σ: number + Scale parameter. + + Returns + ------- + quantile: Function + Quantile function. + + Examples + -------- + > var myQuantile = {{alias}}.factory( 2.0 ); + + > var y = myQuantile( 0.5 ) + ~1.3490 + + > y = myQuantile( 0.8 ) + ~2.5631 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/docs/types/index.d.ts new file mode 100644 index 000000000000..e9bc4b5266d9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/docs/types/index.d.ts @@ -0,0 +1,100 @@ +/* +* @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 quantile function for a Half-normal distribution. +* +* @param p - cumulative probability +* @returns evaluated quantile +*/ +type Unary = ( p: number ) => number; + +/** +* Interface for the quantile function of a Half-normal distribution. +*/ +interface Quantile { + /** + * Evaluates the quantile function for a Half-normal distribution with scale parameter `sigma`. + * + * ## Notes + * + * - If `sigma < 0`, the function returns `NaN`. + * - If `p < 0` or `p > 1`, the function returns `NaN`. + * - If `sigma = 0`, the function returns `0`. + * - If `p = 1`, the function returns `+Infinity`. + * + * @param p - cumulative probability + * @param sigma - scale parameter + * @returns evaluated quantile + * + * @example + * var y = quantile( 0.8, 1.0 ); + * // returns ~1.2816 + * + * @example + * var y = quantile( 0.5, 2.0 ); + * // returns ~1.3490 + * + * @example + * var y = quantile( 1.1, 1.0 ); + * // returns NaN + * + * @example + * // Negative scale parameter: + * var y = quantile( 0.5, -1.0 ); + * // returns NaN + */ + ( p: number, sigma: number ): number; + + /** + * Returns a function for evaluating the quantile function for a Half-normal distribution with scale parameter `sigma`. + * + * @param sigma - scale parameter + * @returns quantile function + * + * @example + * var myquantile = quantile.factory( 2.0 ); + * var y = myquantile( 0.5 ); + * // returns ~1.3490 + */ + factory( sigma: number ): Unary; +} + +/** +* Half-normal distribution quantile function. +* +* @param p - cumulative probability +* @param sigma - scale parameter +* @returns evaluated quantile +* +* @example +* var y = quantile( 0.8, 1.0 ); +* // returns ~1.2816 +* +* var myquantile = quantile.factory( 1.0 ); +* var y = myquantile( 0.8 ); +* // returns ~1.2816 +*/ +declare var quantile: Quantile; + + +// EXPORTS // + +export = quantile; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/docs/types/test.ts new file mode 100644 index 000000000000..6eec785bf355 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/docs/types/test.ts @@ -0,0 +1,98 @@ +/* +* @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 quantile = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + quantile( 0.2, 4 ); // $ExpectType number + quantile( 0.8, 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + quantile( true, 6 ); // $ExpectError + quantile( false, 4 ); // $ExpectError + quantile( '5', 2 ); // $ExpectError + quantile( [], 2 ); // $ExpectError + quantile( {}, 4 ); // $ExpectError + quantile( ( x: number ): number => x, 4 ); // $ExpectError + + quantile( 0.2, true ); // $ExpectError + quantile( 0.8, false ); // $ExpectError + quantile( 0.5, '5' ); // $ExpectError + quantile( 0.8, [] ); // $ExpectError + quantile( 0.9, {} ); // $ExpectError + quantile( 0.8, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + quantile(); // $ExpectError + quantile( 0.2 ); // $ExpectError + quantile( 0.2, 4, 1 ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + quantile.factory( 4 ); // $ExpectType Unary +} + +// The `factory` method returns a function which returns a number... +{ + const fcn = quantile.factory( 4 ); + fcn( 0.5 ); // $ExpectType number +} + +// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... +{ + const fcn = quantile.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 = quantile.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... +{ + quantile.factory( true ); // $ExpectError + quantile.factory( false ); // $ExpectError + quantile.factory( '5' ); // $ExpectError + quantile.factory( [] ); // $ExpectError + quantile.factory( {} ); // $ExpectError + quantile.factory( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + quantile.factory(); // $ExpectError + quantile.factory( 0, 4 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/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/quantile/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/examples/c/example.c new file mode 100644 index 000000000000..5deff2a54239 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/examples/c/example.c @@ -0,0 +1,40 @@ +/** +* @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/quantile.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 p; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + p = random_uniform( 0.0, 1.0 ); + sigma = random_uniform( 0.0, 10.0 ); + y = stdlib_base_dists_halfnormal_quantile( p, sigma ); + printf( "p: %lf, σ: %lf, Q(p;σ): %lf\n", p, sigma, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/examples/index.js new file mode 100644 index 000000000000..95e4060a12a3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 randu = require( '@stdlib/random/base/randu' ); +var quantile = require( './../lib' ); + +var i; +var p; +var sigma; +var y; + +for ( i = 0; i < 25; i++ ) { + p = randu(); // p in [0,1) + sigma = randu() * 3.0; // sigma >= 0 + y = quantile( p, sigma ); + console.log( 'p: %lf, σ: %lf, Q(p;σ): %lf', p, sigma, y ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + */ + function quantile( p ) { + if ( isnan( p ) || p < 0.0 || p > 1.0 ) { + return NaN; + } + if ( p === 1.0 ) { + return PINF; + } + return sigma * SQRT2 * erfinv( p ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/lib/index.js new file mode 100644 index 000000000000..ab5461df0d39 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/lib/index.js @@ -0,0 +1,54 @@ +/** +* @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'; + +/** +* Half-normal distribution quantile function. +* +* @module @stdlib/stats/base/dists/halfnormal/quantile +* +* @example +* var quantile = require( '@stdlib/stats/base/dists/halfnormal/quantile' ); +* +* var y = quantile( 0.8, 1.0 ); +* // returns ~1.282 +* +* var myQuantile = quantile.factory( 1.0 ); +* y = myQuantile( 0.5 ); +* // returns ~0.674 +* +* y = myQuantile( 0.7 ); +* // returns ~1.036 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var factory = require( './factory.js' ); + + +// MAIN // + +setReadOnly( main, 'factory', factory ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/lib/main.js new file mode 100644 index 000000000000..5b58c79258e4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/lib/main.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var erfinv = require( '@stdlib/math/base/special/erfinv' ); +var SQRT2 = require( '@stdlib/constants/float64/sqrt-two' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); + + +// MAIN // + +/** +* Evaluates the quantile function for a Half-Normal distribution with scale parameter `sigma` at a probability `p`. +* +* @param {Probability} p - cumulative probability +* @param {NonNegativeNumber} sigma - scale parameter +* @returns {number} evaluated quantile function +* +* @example +* var y = quantile( 0.8, 1.0 ); +* // returns ~1.2816 +* +* @example +* var y = quantile( 0.5, 2.0 ); +* // returns ~1.3490 +* +* @example +* var y = quantile( 0.5, 4.0 ); +* // returns ~2.6980 +* +* @example +* var y = quantile( 1.1, 1.0 ); +* // returns NaN +* +* @example +* var y = quantile( -0.2, 1.0 ); +* // returns NaN +* +* @example +* var y = quantile( NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = quantile( 0.0, NaN ); +* // returns NaN +* +* @example +* // Negative scale parameter: +* var y = quantile( 0.5, -1.0 ); +* // returns NaN +*/ +function quantile( p, sigma ) { + if ( + isnan( sigma ) || + isnan( p ) || + sigma < 0.0 || + p < 0.0 || + p > 1.0 + ) { + return NaN; + } + if ( sigma === 0.0 ) { + return 0.0; + } + if ( p === 1.0 ) { + return PINF; + } + return sigma * SQRT2 * erfinv( p ); +} + + +// EXPORTS // + +module.exports = quantile; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/lib/native.js new file mode 100644 index 000000000000..4255bbd7b1fa --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/lib/native.js @@ -0,0 +1,75 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Evaluates the quantile function for a Half-Normal distribution with scale parameter `sigma` at a probability `p`. +* +* @param {Probability} p - cumulative probability +* @param {NonNegativeNumber} sigma - scale parameter +* @returns {number} evaluated quantile function +* +* @example +* var y = quantile( 0.8, 1.0 ); +* // returns ~1.2816 +* +* @example +* var y = quantile( 0.5, 2.0 ); +* // returns ~1.3490 +* +* @example +* var y = quantile( 0.5, 4.0 ); +* // returns ~2.6980 +* +* @example +* var y = quantile( 1.1, 1.0 ); +* // returns NaN +* +* @example +* var y = quantile( -0.2, 1.0 ); +* // returns NaN +* +* @example +* var y = quantile( NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = quantile( 0.0, NaN ); +* // returns NaN +* +* @example +* // Negative scale parameter: +* var y = quantile( 0.5, -1.0 ); +* // returns NaN +*/ +function quantile( p, sigma ) { + return addon( p, sigma ); +} + + +// EXPORTS // + +module.exports = quantile; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/manifest.json new file mode 100644 index 000000000000..833d05bf1a41 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/manifest.json @@ -0,0 +1,84 @@ +{ + "options": { + "task": "build", + "wasm": false + }, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "task": "build", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/napi/binary", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/erfinv", + "@stdlib/constants/float64/sqrt-two" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/constants/float64/eps", + "@stdlib/math/base/special/erfinv", + "@stdlib/constants/float64/sqrt-two" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/constants/float64/eps", + "@stdlib/math/base/special/erfinv", + "@stdlib/constants/float64/sqrt-two" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/package.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/package.json new file mode 100644 index 000000000000..f569963257e6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/stats/base/dists/halfnormal/quantile", + "version": "0.0.0", + "description": "Half-normal distribution quantile function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "dist", + "probability", + "cdf", + "inverse", + "half-normal", + "univariate", + "continuous" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/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/quantile/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/src/addon.c new file mode 100644 index 000000000000..3e0f61fd98ed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/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/halfnormal/quantile.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_halfnormal_quantile ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/src/main.c new file mode 100644 index 000000000000..75646bd5b8d2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/src/main.c @@ -0,0 +1,52 @@ +/** +* @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/quantile.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/erfinv.h" +#include "stdlib/constants/float64/sqrt_two.h" + +/** +* Evaluates the quantile function for a Half-normal distribution with cumulative probability p and scale `sigma`. +* +* @param p probability +* @param sigma scale parameter +* @return evaluated quantile +* +* @example +* double y = stdlib_base_dists_halfnormal_quantile( 0.8, 1.0 ); +* // returns ~1.282 +*/ +double stdlib_base_dists_halfnormal_quantile( const double p, const double sigma ) { + if ( + stdlib_base_is_nan( p ) || + stdlib_base_is_nan( sigma ) || + sigma < 0.0 || + p < 0.0 || + p > 1.0 + ) { + return 0.0 / 0.0; // NaN + } + if ( sigma == 0.0 ) { + return 0.0; + } + if ( p == 1.0 ) { + return 1.0 / 0.0; // +infinity + } + return sigma * STDLIB_CONSTANT_FLOAT64_SQRT2 * stdlib_base_erfinv( p ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/fixtures/julia/data.json new file mode 100644 index 000000000000..8eec56801a4c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"sigma":[3.752372343198736,0.5952487736546558,3.3856198354728,1.3195086901125626,0.33660791776355947,3.0698228295251733,2.8333822017156756,0.842096233317226,0.9014208323745504,0.9645360412814957],"expected":[4.115703132034415,0.4368820501703096,3.423273300043822,0.6971282572460012,0.27955804839293547,0.6442160951563007,2.626768194061231,0.24752155341315513,0.04330086356582894,1.155323910174928],"p":[0.7272829554760867,0.5370199818842734,0.6880417602571298,0.40272560115812794,0.5937525368951077,0.1662187547190921,0.6461143084421898,0.23119242465068246,0.038312635981986976,0.7690061785566936]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..8f5dfec5906d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/fixtures/julia/runner.jl @@ -0,0 +1,64 @@ +#!/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. + +using Distributions +using SpecialFunctions # for erfinv +using JSON + +""" + gen(p, sigma, name) + +Generate Half-Normal quantile fixture data. + +# Arguments +- `p`: probability values (0 ≤ p ≤ 1) +- `sigma`: scale parameters (σ ≥ 0) +- `name`: output filename +""" +function gen(p, sigma, name) + z = Array{Float64}(undef, length(p)) + for i in eachindex(p) + # Half-normal quantile: + # Q(p) = sigma * sqrt(2) * erfinv(p) + z[i] = sigma[i] * sqrt(2.0) * erfinv(p[i]) + end + + data = Dict( + "p" => p, + "sigma" => sigma, + "expected" => z + ) + + filepath = joinpath(dir, name) + open(filepath, "w") do f + write(f, JSON.json(data)) + write(f, "\n") + end +end + +# Directory of this script +file = @__FILE__ +dir = dirname(file) + +# Generate random test values +N = 10 +p = rand(N) # in (0,1) +sigma = rand(N) .* 5.0 # σ in [0,5) + +# Write a single data file +gen(p, sigma, "data.json") diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.factory.js new file mode 100644 index 000000000000..0f0961ac02a2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.factory.js @@ -0,0 +1,108 @@ +/** +* @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 EPS = require( '@stdlib/constants/float64/eps' ); +var factory = require( './../lib/factory.js' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); +var p = data.p; +var sigma = data.sigma; +var expected = data.expected; + + +// 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( 'factory returns a function', function test( t ) { + var q = factory( 1.0 ); + t.strictEqual( typeof q, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'if sigma is NaN or < 0, returned function always returns NaN', function test( t ) { + var q; + + q = factory( NaN ); + t.ok( isnan( q( 0.5 ) ), 'sigma NaN' ); + + q = factory( -1.0 ); + t.ok( isnan( q( 0.5 ) ), 'sigma < 0' ); + + t.end(); +}); + +tape( 'if sigma = 0, quantile always returns 0', function test( t ) { + var q = factory( 0.0 ); + t.strictEqual( q( 0.0 ), 0.0 ); + t.strictEqual( q( 0.5 ), 0.0 ); + t.strictEqual( q( 1.0 ), 0.0 ); + t.end(); +}); + +tape( 'if p < 0, p > 1, or p is NaN, quantile returns NaN', function test( t ) { + var q = factory( 1.0 ); + + t.ok( isnan( q( -0.1 ) ), 'p < 0' ); + t.ok( isnan( q( 1.1 ) ), 'p > 1' ); + t.ok( isnan( q( NaN ) ), 'p NaN' ); + + t.end(); +}); + +tape( 'p = 1 returns +Infinity', function test( t ) { + var q = factory( 1.0 ); + t.strictEqual( q( 1.0 ), PINF, 'returns +Infinity' ); + t.end(); +}); + +tape( 'the factory evaluates the Half-normal quantile correctly', function test( t ) { + var delta; + var tol; + var q; + var i; + + for ( i = 0; i < p.length; i++ ) { + q = factory( sigma[i] ); + if ( expected[i] !== null ) { + if ( q( p[i] ) === expected[i] ) { + t.strictEqual( q( p[i] ), expected[i], 'exact match' ); + } else { + delta = abs( q( p[i] ) - expected[i] ); + tol = 40.0 * EPS * abs( expected[i] ); + t.ok(delta <= tol, 'p: '+p[i]+', sigma: '+sigma[i]+', q: '+q(p[i])+', expected: '+expected[i]); + } + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.js new file mode 100644 index 000000000000..ea2a910239b6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/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 quantile = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof quantile, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a factory method for generating `quantile` functions', function test( t ) { + t.strictEqual( typeof quantile.factory, 'function', 'exports a factory method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.native.js new file mode 100644 index 000000000000..c2d45671affc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.native.js @@ -0,0 +1,104 @@ +/** +* @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 EPS = require( '@stdlib/constants/float64/eps' ); + + +// VARIABLES // + +var quantile = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( quantile instanceof Error ) +}; + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); +var p = data.p; +var sigma = data.sigma; +var expected = data.expected; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof quantile, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if any argument is NaN, the function returns NaN', opts, function test( t ) { + t.ok( isnan( quantile( NaN, 1.0 ) ), 'p NaN' ); + t.ok( isnan( quantile( 0.5, NaN ) ), 'sigma NaN' ); + t.end(); +}); + +tape( 'if p is outside [0,1], the function returns NaN', opts, function test( t ) { + t.ok( isnan( quantile( -0.1, 1.0 ) ), 'p < 0' ); + t.ok( isnan( quantile( 1.1, 1.0 ) ), 'p > 1' ); + t.end(); +}); + +tape( 'if sigma < 0, the function returns NaN', opts, function test( t ) { + t.ok( isnan( quantile( 0.5, -1.0 ) ), 'negative sigma' ); + t.end(); +}); + +tape( 'if sigma = 0, the quantile is 0 for all p', opts, function test( t ) { + t.strictEqual( quantile( 0.0, 0.0 ), 0.0 ); + t.strictEqual( quantile( 0.5, 0.0 ), 0.0 ); + t.strictEqual( quantile( 1.0, 0.0 ), 0.0 ); + t.end(); +}); + +tape( 'p = 1 returns +Infinity', opts, function test( t ) { + t.strictEqual( quantile( 1.0, 1.0 ), PINF ); + t.end(); +}); + +tape( 'the native function evaluates the Half-normal quantile correctly', opts, function test( t ) { + var delta; + var tol; + var y; + var i; + + for ( i = 0; i < p.length; i++ ) { + y = quantile( p[i], sigma[i] ); + if ( expected[i] !== null ) { + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'exact match' ); + } else { + delta = abs( y - expected[i] ); + tol = 40.0 * EPS * abs( expected[i] ); + t.ok(delta <= tol, 'p: '+p[i]+', sigma: '+sigma[i]+', y: '+y+', expected: '+expected[i]); + } + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.quantile.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.quantile.js new file mode 100644 index 000000000000..2245271a4122 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/quantile/test/test.quantile.js @@ -0,0 +1,95 @@ +/** +* @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 EPS = require( '@stdlib/constants/float64/eps' ); +var quantile = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); +var p = data.p; +var sigma = data.sigma; +var expected = data.expected; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof quantile, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if any argument is NaN, the function returns NaN', function test( t ) { + t.ok( isnan( quantile( NaN, 1.0 ) ), 'p NaN' ); + t.ok( isnan( quantile( 0.5, NaN ) ), 'sigma NaN' ); + t.end(); +}); + +tape( 'if p is outside [0,1], the function returns NaN', function test( t ) { + t.ok( isnan( quantile( -0.1, 1.0 ) ), 'p < 0' ); + t.ok( isnan( quantile( 1.1, 1.0 ) ), 'p > 1' ); + t.end(); +}); + +tape( 'if sigma < 0, the function returns NaN', function test( t ) { + t.ok( isnan( quantile( 0.5, -1.0 ) ), 'negative sigma' ); + t.end(); +}); + +tape( 'if sigma = 0, the quantile is 0 for all p', function test( t ) { + t.strictEqual( quantile( 0.0, 0.0 ), 0.0 ); + t.strictEqual( quantile( 0.5, 0.0 ), 0.0 ); + t.strictEqual( quantile( 1.0, 0.0 ), 0.0 ); + t.end(); +}); + +tape( 'p = 1 returns +Infinity', function test( t ) { + t.strictEqual( quantile( 1.0, 1.0 ), PINF ); + t.end(); +}); + +tape( 'the function evaluates the Half-normal quantile correctly', function test( t ) { + var delta; + var tol; + var y; + var i; + + for ( i = 0; i < p.length; i++ ) { + y = quantile( p[i], sigma[i] ); + if ( expected[i] !== null ) { + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'exact match' ); + } else { + delta = abs( y - expected[i] ); + tol = 40.0 * EPS * abs( expected[i] ); + t.ok(delta <= tol, 'p: '+p[i]+', sigma: '+sigma[i]+', y: '+y+', expected: '+expected[i]); + } + } + } + t.end(); +});