diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/README.md new file mode 100644 index 000000000000..e77c980c5305 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/README.md @@ -0,0 +1,247 @@ + + +# Logarithm of Probability Density Function + +> [Half-Normal][half-normal-distribution] distribution logarithm of [probability density function (PDF)][pdf]. + +
+ +The [probability density function][pdf] (PDF) for a [half-normal][half-normal-distribution] random variable is + + + +```math +f(x;\sigma) = \frac{\sqrt{2}}{\sigma\sqrt{\pi}} e^{-\frac{x^2}{2\sigma^2}} +``` + + + + + +for `x >= 0`, where `sigma > 0` is the scale parameter. For `x < 0`, the PDF is `0`. + +
+ + + +
+ +## Usage + +```javascript +var logpdf = require( '@stdlib/stats/base/dists/halfnormal/logpdf' ); +``` + +#### logpdf( x, sigma ) + +Evaluates the logarithm of the [probability density function][pdf] (PDF) for a [half-normal][half-normal-distribution] distribution with parameter `sigma` (scale parameter). + +```javascript +var y = logpdf( 0.8, 1.0 ); +// returns ~-0.546 + +y = logpdf( 0.5, 1.0 ); +// returns ~-0.351 + +y = logpdf( 1.2, 2.0 ); +// returns ~-1.099 +``` + +If `x < 0`, the function returns `-Infinity`. + +```javascript +var y = logpdf( -0.2, 1.0 ); +// returns -Infinity +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = logpdf( NaN, 1.0 ); +// returns NaN + +y = logpdf( 0.0, NaN ); +// returns NaN +``` + +If provided `sigma <= 0`, the function returns `NaN`. + +```javascript +var y = logpdf( 2.0, -1.0 ); +// returns NaN + +y = logpdf( 2.0, 0.0 ); +// returns NaN +``` + +#### logpdf.factory( sigma ) + +Returns a `function` for evaluating the logarithm of the [PDF][pdf] for a [half-normal][half-normal-distribution] distribution with parameter `sigma` (scale parameter). + +```javascript +var mylogpdf = logpdf.factory( 1.0 ); + +var y = mylogpdf( 0.8 ); +// returns ~-0.546 + +y = mylogpdf( 1.2 ); +// returns ~-0.946 +``` + +
+ + + +
+ +## Notes + +- In virtually all cases, using the `logpdf` or `logcdf` functions is preferable to manually computing the logarithm of the `pdf` or `cdf`, respectively, since the latter is prone to overflow and underflow. + +
+ + + +
+ +## Examples + + + +```javascript +var randu = require( '@stdlib/random/base/randu' ); +var logpdf = require( '@stdlib/stats/base/dists/halfnormal/logpdf' ); +var i; +var x; +var y; +var sigma; + +for ( i = 0; i < 25; i++ ) { + x = randu() * 3.0; + sigma = randu() * 3.0; + y = logpdf( x, sigma ); + console.log( 'x: %d, σ: %d, ln(f(x;σ)): %d', x.toFixed( 4 ), sigma.toFixed( 4 ), y.toFixed( 4 ) ); +} +``` + +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/halfnormal/logpdf.h" +``` + +#### stdlib_base_dists_halfnormal_logpdf( x, sigma ) + +Evaluates the logarithm of the [probability density function][pdf] (PDF) for a [Half-Normal][half-normal-distribution] distribution with parameter `sigma` (scale parameter). + +```c +double out = stdlib_base_dists_halfnormal_logpdf( 0.8, 1.0 ); +// returns ~-0.546 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **sigma**: `[in] double` scale parameter. + +```c +double stdlib_base_dists_halfnormal_logpdf( const double x, const double sigma ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/halfnormal/logpdf.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 < 25; i++ ) { + x = random_uniform( 0.0, 10.0 ); + sigma = random_uniform( 0.1, 10.0 ); // sigma must be > 0 + y = stdlib_base_dists_halfnormal_logpdf( 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/logpdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/benchmark/benchmark.js new file mode 100644 index 000000000000..f1566e5b70b1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/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 logpdf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var sigma; + var len; + var x; + var y; + var i; + + len = 100; + x = new Float64Array( len ); + sigma = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = uniform( 0.0, 10.0 ); + sigma[ i ] = uniform( EPS, 10.0 ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = logpdf( 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( pkg+':factory', function benchmark( b ) { + var mylogpdf; + var sigma; + var len; + var x; + var y; + var i; + + sigma = 4.0; + mylogpdf = logpdf.factory( sigma ); + len = 100; + x = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = uniform( 0.0, 20.0 ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mylogpdf( x[ 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/logpdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..0fe2269163a1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/benchmark/benchmark.native.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var Float64Array = require( '@stdlib/array/float64' ); +var randu = require( '@stdlib/random/base/randu' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var logpdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logpdf instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var sigma; + var len; + var x; + var y; + var i; + + len = 100; + sigma = new Float64Array( len ); + x = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + x[ i ] = randu() * 10.0; + sigma[ i ] = ( randu() * 10.0 ) + EPS; + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = logpdf( 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/logpdf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/benchmark/c/Makefile new file mode 100644 index 000000000000..34fcc0fcd245 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/benchmark/c/Makefile @@ -0,0 +1,148 @@ +#/ +# @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/logpdf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..d9e0a57fb469 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/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/logpdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "halfnormal-logpdf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + double sigma[ 100 ]; + double x[ 100 ]; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( 0.0, 10.0 ); + sigma[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_halfnormal_logpdf( x[ 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/logpdf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/docs/repl.txt new file mode 100644 index 000000000000..c3e158932916 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/docs/repl.txt @@ -0,0 +1,66 @@ + +{{alias}}( x, σ ) + Evaluates the logarithm of the probability density function (PDF) 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 `x < 0`, the function returns `-Infinity`. + + Parameters + ---------- + x: number + Input value. + + σ: number + Scale parameter. + + Returns + ------- + out: number + Evaluated logPDF. + + Examples + -------- + > var y = {{alias}}( 0.8, 1.0 ) + ~-0.546 + > y = {{alias}}( 0.5, 1.0 ) + ~-0.351 + > y = {{alias}}( 1.2, 2.0 ) + ~-1.099 + > y = {{alias}}( NaN, 1.0 ) + NaN + > y = {{alias}}( 0.0, NaN ) + NaN + // Negative scale parameter: + > y = {{alias}}( 2.0, -1.0 ) + NaN + + +{{alias}}.factory( σ ) + Returns a function for evaluating the logarithm of the probability density + function (PDF) of a half-normal distribution with scale parameter `σ`. + + Parameters + ---------- + σ: number + Scale parameter. + + Returns + ------- + logpdf: Function + Logarithm of probability density function (PDF). + + Examples + -------- + > var mylogpdf = {{alias}}.factory( 1.0 ); + > var y = mylogpdf( 0.8 ) + ~-0.546 + > y = mylogpdf( 1.2 ) + ~-0.946 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/docs/types/index.d.ts new file mode 100644 index 000000000000..e72e44b43007 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/docs/types/index.d.ts @@ -0,0 +1,106 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Evaluates the natural logarithm of the probability density function (logPDF) for a half-normal distribution. +* +* @param x - input value +* @returns evaluated logPDF +*/ +type Unary = ( x: number ) => number; + +/** +* Interface for the natural logarithm of the probability density function (logPDF) of a half-normal distribution. +*/ +interface LogPDF { + /** + * Evaluates the logarithm of the probability density function (PDF) for a half-normal distribution with scale parameter `sigma`. + * + * ## Notes + * + * - If provided `sigma <= 0`, the function returns `NaN`. + * - If `x < 0`, the function returns `-Infinity`. + * + * @param x - input value + * @param sigma - scale parameter + * @returns evaluated logarithm of PDF + * + * @example + * var y = logpdf( 0.8, 1.0 ); + * // returns ~-0.546 + * + * @example + * var y = logpdf( 0.5, 1.0 ); + * // returns ~-0.351 + * + * @example + * var y = logpdf( 1.2, 2.0 ); + * // returns ~-1.099 + * + * @example + * var y = logpdf( NaN, 1.0 ); + * // returns NaN + * + * @example + * var y = logpdf( 0.0, NaN ); + * // returns NaN + * + * @example + * // Negative scale parameter: + * var y = logpdf( 2.0, -1.0 ); + * // returns NaN + */ + ( x: number, sigma: number ): number; + + /** + * Returns a function for evaluating the logarithm of the probability density function (PDF) for a half-normal distribution with scale parameter `sigma`. + * + * @param sigma - scale parameter + * @returns logPDF + * + * @example + * var mylogpdf = logpdf.factory( 1.0 ); + * var y = mylogpdf( 0.8 ); + * // returns ~-0.546 + */ + factory( sigma: number ): Unary; +} + +/** +* Half-normal distribution natural logarithm of probability density function (logPDF). +* +* @param x - input value +* @param sigma - scale parameter +* @returns evaluated logPDF +* +* @example +* var y = logpdf( 0.8, 1.0 ); +* // returns ~-0.546 +* +* var mylogpdf = logpdf.factory( 1.0 ); +* var y = mylogpdf( 0.8 ); +* // returns ~-0.546 +*/ +declare var logpdf: LogPDF; + + +// EXPORTS // + +export = logpdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/docs/types/test.ts new file mode 100644 index 000000000000..79c141e250a9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/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 logpdf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + logpdf( 2, 4 ); // $ExpectType number + logpdf( 1, 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + logpdf( true, 6 ); // $ExpectError + logpdf( false, 4 ); // $ExpectError + logpdf( '5', 2 ); // $ExpectError + logpdf( [], 2 ); // $ExpectError + logpdf( {}, 4 ); // $ExpectError + logpdf( ( x: number ): number => x, 4 ); // $ExpectError + + logpdf( 9, true ); // $ExpectError + logpdf( 9, false ); // $ExpectError + logpdf( 5, '5' ); // $ExpectError + logpdf( 8, [] ); // $ExpectError + logpdf( 9, {} ); // $ExpectError + logpdf( 8, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + logpdf(); // $ExpectError + logpdf( 2 ); // $ExpectError + logpdf( 2, 0, 4 ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + logpdf.factory( 4 ); // $ExpectType Unary +} + +// The `factory` method returns a function which returns a number... +{ + const fcn = logpdf.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 = logpdf.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 = logpdf.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... +{ + logpdf.factory( true ); // $ExpectError + logpdf.factory( false ); // $ExpectError + logpdf.factory( '5' ); // $ExpectError + logpdf.factory( [] ); // $ExpectError + logpdf.factory( {} ); // $ExpectError + logpdf.factory( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + logpdf.factory(); // $ExpectError + logpdf.factory( 0, 4 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/examples/c/example.c new file mode 100644 index 000000000000..9fed4e03468d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/examples/c/example.c @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/halfnormal/logpdf.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 < 25; i++ ) { + x = random_uniform( 0.0, 10.0 ); + sigma = random_uniform( 0.0, 10.0 ); + y = stdlib_base_dists_halfnormal_logpdf( 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/logpdf/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/examples/index.js new file mode 100644 index 000000000000..5e02f3f01760 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/examples/index.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var randu = require( '@stdlib/random/base/randu' ); +var logpdf = require( './../lib' ); +var i; +var x; +var y; +var sigma; + +for ( i = 0; i < 25; i++ ) { + x = randu() * 3.0; + sigma = randu() * 3.0; + y = logpdf( x, sigma ); + console.log( 'x: %lf, σ: %lf, ln(f(x;σ)): %lf', x, sigma, y ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + */ + function logpdf( x ) { + if ( isnan( x ) ) { + return NaN; + } + if ( x < 0.0 ) { + return NINF; + } + return C - lsigma - ( (x*x) / ( 2.0 * sigma2 ) ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/lib/index.js new file mode 100644 index 000000000000..bbed01cdffc7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/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 logarithm of probability density function (PDF). +* +* @module @stdlib/stats/base/dists/halfnormal/logpdf +* +* @example +* var logpdf = require( '@stdlib/stats/base/dists/halfnormal/logpdf' ); +* +* var y = logpdf( 0.8, 1.0 ); +* // returns ~-0.546 +* +* var mylogpdf = logpdf.factory( 1.0 ); +* y = mylogpdf( 0.8 ); +* // returns ~-0.546 +* +* y = mylogpdf( 1.2 ); +* // returns ~-0.946 +*/ + +// 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/logpdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/lib/main.js new file mode 100644 index 000000000000..9b6372097af9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/lib/main.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 isnan = require( '@stdlib/math/base/assert/is-nan' ); +var ln = require( '@stdlib/math/base/special/ln' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var LN2 = require( '@stdlib/constants/float64/ln-two' ); +var LNPI = require( '@stdlib/constants/float64/ln-pi' ); + + +// VARIABLES // + +// Constant: log(sqrt(2/pi)) = 0.5 * log(2/pi) = 0.5 * (ln(2) - ln(pi)) +var C = 0.5 * ( LN2 - LNPI ); + + +// MAIN // + +/** +* Evaluates the logarithm of the probability density function (PDF) for a half-normal distribution with scale parameter `sigma`. +* +* @param {number} x - input value +* @param {PositiveNumber} sigma - scale parameter +* @returns {number} evaluated logarithm of PDF +* +* @example +* var y = logpdf( 0.8, 1.0 ); +* // returns ~-0.546 +* +* @example +* var y = logpdf( 0.5, 1.0 ); +* // returns ~-0.351 +* +* @example +* var y = logpdf( 1.2, 2.0 ); +* // returns ~-1.099 +* +* @example +* var y = logpdf( -0.2, 1.0 ); +* // returns -Infinity +* +* @example +* var y = logpdf( NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = logpdf( 0.0, NaN ); +* // returns NaN +* +* @example +* // Negative scale parameter: +* var y = logpdf( 2.0, -1.0 ); +* // returns NaN +* +* @example +* var y = logpdf( 2.0, 0.0 ); +* // returns NaN +*/ +function logpdf( x, sigma ) { + if ( + isnan( x ) || + isnan( sigma ) || + sigma <= 0.0 + ) { + return NaN; + } + if ( x < 0.0 ) { + return NINF; + } + return C - ln( sigma ) - ( (x*x) / ( 2.0 * (sigma*sigma) ) ); +} + + +// EXPORTS // + +module.exports = logpdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/lib/native.js new file mode 100644 index 000000000000..d3b462a51429 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/lib/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 addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Evaluates the logarithm of the probability density function (PDF) for a half-normal distribution with scale parameter `sigma`. +* +* @private +* @param {number} x - input value +* @param {PositiveNumber} sigma - scale parameter +* @returns {number} evaluated logarithm of PDF +* +* @example +* var y = logpdf( 0.8, 1.0 ); +* // returns ~-0.546 +* +* @example +* var y = logpdf( 0.5, 1.0 ); +* // returns ~-0.351 +* +* @example +* var y = logpdf( 1.2, 2.0 ); +* // returns ~-1.099 +* +* @example +* var y = logpdf( NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = logpdf( 0.0, NaN ); +* // returns NaN +* +* @example +* // Negative scale parameter: +* var y = logpdf( 2.0, -1.0 ); +* // returns NaN +*/ +function logpdf( x, sigma ) { + return addon( x, sigma ); +} + + +// EXPORTS // + +module.exports = logpdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/manifest.json new file mode 100644 index 000000000000..371b66f44298 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/manifest.json @@ -0,0 +1,89 @@ +{ + "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/ln", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/ln-two", + "@stdlib/constants/float64/ln-pi" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/constants/float64/eps", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/ln-two", + "@stdlib/constants/float64/ln-pi" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/ln-two", + "@stdlib/constants/float64/ln-pi" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/package.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/package.json new file mode 100644 index 000000000000..2f272468cae7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/stats/base/dists/halfnormal/logpdf", + "version": "0.0.0", + "description": "Half-normal distribution logarithm of probability density function (PDF).", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "dist", + "probability", + "pdf", + "log", + "logarithm", + "halfnormal", + "half-normal", + "univariate", + "continuous" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/src/addon.c new file mode 100644 index 000000000000..36032875f1e1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/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/logpdf.h" +#include "stdlib/math/base/napi/binary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_halfnormal_logpdf ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/src/main.c new file mode 100644 index 000000000000..c059080d2ad0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/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/logpdf.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/ln.h" +#include "stdlib/constants/float64/ninf.h" +#include "stdlib/constants/float64/ln_two.h" +#include "stdlib/constants/float64/ln_pi.h" + +// log(sqrt(2/pi)) = 0.5 * log(2/pi) = 0.5 * (ln(2) - ln(pi)) +static const double C = 0.5 * ( STDLIB_CONSTANT_FLOAT64_LN2 - STDLIB_CONSTANT_FLOAT64_LN_PI ); + +/** +* Evaluates the logarithm of the probability density function (PDF) for a half-normal distribution with scale parameter `sigma`. +* +* @param x input value +* @param sigma scale parameter +* @return evaluated logarithm of PDF +* +* @example +* double y = stdlib_base_dists_halfnormal_logpdf( 0.8, 1.0 ); +* // returns ~-0.546 +*/ +double stdlib_base_dists_halfnormal_logpdf( const double x, const double sigma ) { + 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; + } + return C - stdlib_base_ln( sigma ) - ( (x*x) / ( 2.0 * (sigma*sigma) ) ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/fixtures/julia/REQUIRE @@ -0,0 +1,3 @@ +Distributions 0.23.8 +julia 1.5 +JSON 0.21 diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/fixtures/julia/data.json new file mode 100644 index 000000000000..19b1962876b9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"sigma":[2.604571695435689,7.499267153061186,3.348443855723051,1.954656979562216,3.4049481714068417,6.694631267188975,1.897307581920854,7.221912944090477,4.428811597768087,2.4767418429270482,6.941608679942151,5.864079750113497,9.744395766910703,9.272117265419165,9.988829036928026,6.779122786581012,0.7344609031856131,6.848342644396962,8.018330605129464,5.211868729540758,2.3049364727134636,3.8315010098974422,3.46800097207554,1.5599123588514552,6.606717962977018,7.410696875212648,6.874823897663963,3.221496034765312,6.235041810997416,1.3279597463672854,9.44146426673753,8.177461380129431,8.927627725609304,4.406701773566557,2.852317172153832,7.194955481350123,4.992607310115855,2.1282797618395977,3.483472273063902,6.627323443545885,6.6103097072837835,0.061096215826882405,7.412790779606869,0.9466556204581333,4.571859970254888,1.931551192703298,3.0050261601448183,3.3949380738891675,3.977296226018817,2.700967519855426,5.126833560160161,5.616177103419712,1.8756315123769007,3.3196801406426726,6.725542374817428,4.329955792526475,0.4250911560354642,9.461735987270043,0.6586927594496961,7.608269203215405,4.714445084719174,7.717980819408167,6.611644656967205,2.141484432321785,7.452733887330439,9.079982729334489,4.947811285888593,7.674682718699137,1.5793640726621627,5.885322199835191,9.199118278524676,5.734807081684206,7.366268858939776,0.03081687237524222,7.30137974782418,6.2731988226528905,1.9399025338398501,8.533172406966006,7.281618821026958,8.450155804925846,9.442668127724156,8.905360482641246,7.19802113263418,1.9995797415912842,3.1276311973458837,2.9685041501187936,9.983864537874025,1.5435189154177198,9.648277243231119,2.126066458700252,4.5466723024373765,5.914609833065201,0.7522464699638964,0.1699111408636922,0.2974724608114432,6.83637731242278,7.466071533354251,3.9337878013432395,7.197819493259593,5.882080876108651,2.3433828403210475,4.208632602100355,2.402290614235584,3.631925025637713,1.1876197549565193,5.911275813358032,1.8573952682854777,6.800769875989423,7.8763574742869755,8.34301823558079,3.779134698451866,0.9113517969178353,5.827640899773055,9.978794133832844,9.316042705766776,6.41172758094572,2.1136190041417646,6.80329543771399,0.5228328044946118,9.342465842369826,0.6899510144698184,2.401357651425038,6.569897634892486,6.5597841778007755,3.5123842971085315,5.454422499207389,2.8469424556343714,3.1511666712568056,7.042468052019869,7.701449272841541,1.9848872374526205,7.249009151223746,3.744987731234244,4.447337284058534,6.079028552843232,5.478180230282485,3.497906073915995,2.5695518987215027,5.15774288347941,8.614642914974516,6.604485498547804,4.962010431240841,4.384220585238067,1.6073973936985708,0.30677632383480535,7.599702224033368,1.3507874746320037,0.033302282516709525,7.862568181804671,2.009560882443947,4.059844753881587,0.5645662015751185,3.0274440109350076,9.638700752083727,4.031019765960614,6.141440401938864,1.761194274613146,2.5594009882793567,6.11194348649394,1.43195553324583,8.493334961321331,3.759331078600634,9.808853017764541,1.3213352034772674,6.503743567682694,1.8972571702963592,2.3857959629167222,7.921794655507118,1.9954696019464824,2.218004346754544,8.469211637539878,3.9062266063723614,5.248394114315007,9.184245836353762,9.203937128502,5.599345253623577,6.779095435692776,1.826583095795291,7.015873953614421,1.7864311963901647,5.011358382009109,0.6470971885279242,9.195234367419598,0.7874694428933426,5.416660805405165,5.198403368016576,9.253241653474346,3.24843709611917,5.349511246036897,2.1790328463953346,8.890143031721442,5.307417725023211,1.5329275582299007,6.234025407360917,1.6612981135523863,6.121416986356117,2.5731878015843943,0.9888453932854835,2.6704393130399664,3.5801849350579227,6.207369589686255,5.714817552781277,2.2915938865522243,6.707507757581007,1.1259067150458457,3.697549584157075,7.936520690034032,5.196305439455045,8.321035149306683,0.590242173399913,1.2907685122160717,4.600849303622966,2.673649881074213,5.960561090224231,1.2512496898840009,6.864428249326485,8.468752755121008,5.61103837397558,7.918832904075375,9.634412884912592,1.406626383340882,7.784472413479309,5.336413218604309,0.9408615136975984,9.122866631139354,1.767105963946849,8.096074889235728,5.407638630445767,0.3247329632531992,5.481060696205128,0.5014312420424416,7.940886248580753,3.435478003911807,5.485914820603188,3.2142821346641623,1.5333586509842834,7.222083783969284,6.0174548350685795,6.63198992825163,4.781160821102412,8.256571226901285,7.457094782134071,2.772301678503072,3.7078513559704174,5.6346962699407355,6.128341196103938,9.010114712113722,2.2598714449919752,0.1889602747176944,7.096189092815654,6.868846777979782,0.4209953025342872,9.866126063715146,8.14316253981656,2.9845627968962707,5.097748958896519,6.261496804523221,7.137653829376132,9.886873576164643,5.965277669151455,0.07011972662105403,4.063791807813283,6.1611190224566235,1.0959707873213287,4.576953479256925,5.90606945853529,9.654672962156841,9.688671254962339,9.710506569297284,3.1853088830387764,4.2904458012890725,9.971288891349083,6.6550883836239265,4.134009161395459,3.733200425218912,0.9402801494236745,7.074825299316756,8.633202732837145,8.738110999013507,6.5354424752550875,3.108524269120597,2.675505104228282,1.7053921120046678,1.1296415858517372,7.81206039613769,3.844803705533064,5.763541004779444,8.970388675400644,7.421022213172072,1.856270223683406,4.544226873948821,5.21772441153633,2.9353377496583355,0.9136519577161406,7.935750950947831,8.823679875304322,7.898904450799843,7.368757436462031,3.110359682485535,4.67855832511082,9.876165523893258,2.607190706678224,4.603452448548583,5.866128265093025,1.506703935312399,4.789841805675126,6.756790717198845,5.191517732568384,1.085071222251357,2.335621298392309,8.231267130795656,6.525703336557638,7.666447376623191,0.7460628443442108,3.2368502117823272,5.623746323167706,7.8538784146223275,1.119618356003086,2.3806957699600586,3.7863800897019972,8.505175747698681,8.472977304268355,9.452950029995323,1.436611747542068,1.0145680000880708,5.88117292883947,5.032871011759337,0.3912151919797313,6.997739556538859,9.604647276653346,4.49258930986219,4.637957961366989,1.0511026365561282,6.648331565353239,7.836415964137164,2.967327547555203,2.6739787771776435,7.935135225600374,0.021785297485525934,8.27283626419145,4.764888995592508,2.4594547040212356,0.5873307024081076,8.46820676389094,9.52608832647495,1.4713574187505074,3.491811085265354,4.1600261180478,9.99998375151233,8.443794927694302,1.1824066341122408,8.135689654912765,7.8905865453278405,3.420630629718521,4.389293236112181,3.7682463402637723,0.6281385489799363,9.886207659184986,0.2679810622718404,0.4339759733201143,5.0967072256540344,2.3695806585221835,2.616196067887061,2.409112830131664,0.647152059224404,1.9474018865621623,9.747060064292953,3.168028574685471,3.6266176175668408,5.983245850500021,7.15507773615342,2.716895973791379,7.247671064765257,3.338529502999955,2.062678402062602,2.995497298185492,4.497164747965099,0.3111744629945712,2.8889048047965393,9.282707545023722,5.901203795407776,5.150438610211291,5.931484980966143,3.5973463513784343,8.711550943349414,6.135939467187839,4.868402476117745,3.133183903066378,1.22211494576822,4.491103553438204,1.8251961731247957,6.62485084026637,5.09261500917918,3.8914681219502265,8.380516869533967,3.2131144846472037,7.26883637096241,7.2729173958215165,2.308187428949222,7.312827107505858,0.8588915435736988,4.482123252111473,0.4437898312470101,3.5170154332592807,4.540697119781223,7.008858188029887,8.137549822887339,0.7124239731967097,2.1404755329022027,4.443158855081336,6.668755006836599,9.95597313901661,7.228798176519304,2.1847686842532275,7.814835934962018,6.492341977245627,1.3991969374241997,2.2214769403278134,4.130649999124247,3.0204491892387786,2.1571636069082025,0.16403079175459467,3.54409853348836,3.504748409080254,2.8676230220062324,2.52415858227549,6.469287236307098,3.2294146045581384,4.3934176813649914,4.956310635554368,2.34593693145699,3.625075760959835,4.544638795940569,2.2380149631161794,8.882120549003114,2.297130371060444,4.4890716831995885,7.543920706955356,7.256769193877522,7.602308535144731,2.628986802482806,1.3709998870636242,5.337868429586066,7.871364415545975,5.533913002022285,2.212193908224478,7.432986589065473,2.657703563240422,0.47697815806395094,6.303117634942984,5.906384068132606,5.7739069084758645,8.342250832120197,0.09840198275396173,0.4353149757814234,3.8092146793471016,9.809896266270252,5.124887798503939,0.15532067895370427,3.4738152960007063,2.7373600708528323,7.119856971719382,9.62152783797164,1.4934997845813736,5.341732587909952,0.6547687085576881,2.1988362759268743,2.399266736088955,7.9131915312059835,7.06613125643433,7.061527150529297,9.297540531936985,5.66502346356839,6.237407133612046,4.315140481549119,9.94506262752262,4.65926217914938,1.3984458543502587,8.17430573710466,0.9731274854651195,0.07600018426108468,6.61031152130124,4.907007175141695,9.720563002862,8.205108395456241,8.903801383118955,7.867979768608463,3.433315023849095,1.4515591514940673,7.2829432889827626,4.419858121294563,4.3549222762833315,9.395676499189705,3.404534220439037,2.8143246044239687,1.625111802473671,5.146106547756595,1.5846847435313072,2.2470195239985147,6.658298303841505,8.772277351258401,9.304438661544722,7.385241354281018,0.07581660422492642,7.373129744597355,7.388273926373426,5.54592314338544,0.37783986311208717,8.54160172470536,5.486426507571912,7.441090895104125,1.5937233066106127,0.5508206372405899,1.7377708783132695,9.44158218493359,8.156399637317863,0.09433709417394853,2.658405776406312,0.2169747311546133,8.643782989689203,2.5745269040560723,5.019951746616041,3.276125777435986,7.572594888920598,5.439052716532555,1.5073439970407676,2.1814312695798987,0.6703770781247942,2.414711265943522,6.494590436375423,0.020496803540405173,4.771260830674317,0.013935912456467525,8.798976396819214,1.3068740911075438,4.103636753611188,1.4877753153767082,1.1613934165325723,9.421161990844677,7.711159450358592,8.699447923071306,9.434359211467719,3.135994094470682,3.056348723683268,0.92271054691906,3.212397458728975,0.7443669775045991,3.9038797476798157,4.150447633235158,2.0896610247556167,5.872526281939203,7.9496036152999725,2.5367351103931957,4.060649853767196,4.532982127636259,9.680604175354206,9.065608785389612,3.4426296387002764,2.601407497956305,2.95311453430008,2.673776352570542,9.409276156661434,7.767765523162277,8.011548422750229,7.894428901180989,8.497782049014017,8.030348267598832,1.5282246741472028,9.308572975826594,7.221868157437807,5.564855375341423,9.727733073040667,6.247057953707777,6.790063607977123,0.09198303371642846,3.7735069619102823,8.979925305245397,1.0397406770994344,1.3382296780488678,7.287521052958281,4.682767842684683,2.7286389557261326,6.645854844299056,5.681610721360917,4.943184483064753,2.8284119053473145,7.129253704319188,7.029427857982472,6.742302781762367,6.3300499803396235,7.2141657132806625,4.901733137728105,2.2293208846984935,7.440239922920689,0.25990606846057585,4.673501572300123,5.629381673498272,4.341981276793191,4.290111855711846,9.541382771607815,7.594875899725166,2.072690869679893,8.119526605598999,4.876369980731931,9.546104239796385,4.2787486000044215,4.128697772108778,0.787560422447372,8.790804485623042,9.451570300883827,5.880493539844942,5.663215418426346,1.803168635125959,9.605661146429211,9.900492448771898,1.5649072769336536,7.3692488309748505,4.1364535888110145,0.8448262507327253,2.448511847690953,1.7331098663265465,8.379801014220902,9.751003571792227,8.878335392157945,7.305795634477818,7.847936634252784,4.830874827690582,4.461436812911481,4.869332401468416,5.72215018500252,5.382870329068442,9.04902923204311,5.9715351932318566,6.841859251561849,5.657094184724585,6.593226577961784,1.0138589780470608,1.969276524742527,2.45852570422477,0.12364110630712188,0.645657738864448,8.871333595453535,5.5934069682526335,3.8215197991223637,4.044268218555116,7.419438451446281,8.410319017805476,2.442707704129324,9.98105124680183,9.862816124205137,4.128212574168401,9.674796962669024,3.238547221642846,7.823368225894825,3.5135099280853166,0.43659791917808555,4.62587380771411,9.097265030447728,4.963551301843707,6.710280038043841,7.777533328832331,1.5826210094068116,9.436885230093207,4.404639460245182,1.3234941920221976,2.1032073182217603,2.506717951397497,0.7058236003082341,1.3125741819553893,9.787560190166626,7.258153787069118,2.258024979777348,5.081493778054571,6.6429171405425835,4.369243606679776,8.125998273028802,4.644916573955483,9.196271426490348,7.279704721342871,4.16693641782172,1.0200698341959957,2.1828159606731923,0.9364763875648707,9.787220638019317,7.131468888752442,9.815666921908475,6.355367033540617,1.3173380779548771,9.482597127864242,3.1690814204114437,8.595331099578713,9.5254166174108,8.230411555439433,5.725832534042006,1.2322060288810266,9.957648582000292,9.858870469189906,3.8150702747870016,0.04871241044034802,2.420504843546211,6.470712564436538,1.2999654846770992,9.323724546544147,3.610568649725762,0.4783187385237153,8.104421729639974,7.064972520269309,8.860659572768098,7.141627159777791,2.967689424407708,6.771258527690741,4.343118967024061,2.416782477108803,0.8542843047132131,6.100406235068831,7.545700460955793,7.063892730036567,6.0446914280366615,5.285830586844894,5.307515293743254,2.9786789824782978,7.099641130940154,0.6819519354782733,8.567025786961329,5.204495467963116,3.3585160748557694,9.699216192105576,3.256506214231486,8.143589876353284,9.483939897022353,0.892251005303637,9.549915558563365,2.6712902358127644,6.596829750102574,7.455155101496727,4.978471417209422,8.593792612761126,2.866740474576054,7.141567231209653,3.0957817277295065,0.12480995248720594,1.5009485382618426,5.218758445380022,9.995043148823246,9.242820373023836,0.24455295861907977,9.116388068664943,2.2406161577832027,4.7245504836264995,8.282010468148037,4.060794678622991,8.277581912075586,8.209459921684937,6.179289799001108,5.646292460445603,7.084819606313349,2.1367656632966767,3.6493653564736905,2.6153300772850963,8.15054509089038,2.110159682058561,1.047738134041163,3.5323642453107063,5.240634558697081,0.13968990875498744,2.2279424933667302,1.934244913994957,2.373502290328852,8.386197967086126,2.045556604887815,4.601561114191883,3.8718769693383037,5.832631586448915,3.805299364156456,1.8110335125431487,0.7365648373063682,0.7213863107024732,3.068484922818744,4.329534291053867,4.222344105544882,7.589260028508294,6.324870706588142,0.8148890487064342,0.09281038864587643,4.361269639761494,1.766865209465135,5.748507947867715,4.1528650632574635,7.117250502996301,1.5012536875071791,8.72511353920917,0.36566504427537394,7.730756397553243,1.2125179565575162,2.479106634849394,9.92298128445434,2.1650597343472198,1.1764170709893307,1.5983461160828583,9.839326831507766,7.4739946593624005,3.4877612991840854,7.720292676632438,1.8501788327379964,4.8499677155627,3.9586665485789077,6.354703776739568,0.3548005180935354,4.997567742901117,2.0683252440752065,4.4790286317608965,0.5224661271247777,6.801782537389563,0.451423276864249,9.941215053085973,4.055416091127646,2.676859105247903,7.984667357214375,9.251274933997815,0.0978641060831309,2.0094574870521353,6.360467077545625,0.8901808006905798,3.3850166052563404,2.991086466851315,4.382840687706109,8.805453718405778,7.821906667699727,3.9216979186062186,5.182697506697601,4.3459574328100326,9.33706693751088,5.7423529370876425,7.6568006947908245,6.10766008587249,8.483844944947393,5.862082358397797,9.974699600986822,1.0401922694990196,0.3620365438706119,2.2531988852087768,1.1598127555237336,1.839443729634317,1.9514715256665105,6.005132802584809,0.09944319243355149,9.026963268354885,9.667228109534701,9.934570989701424,8.084511977635753,4.111363505217998,6.239496246785525,7.905413351096273,1.4556150906431986,0.310904082164547,0.9524524550257452,0.6223477438910652,4.33146165292316,6.994152257226843,4.540979353779652,4.67886131658441,5.32307309947549,9.905636018938708,3.1331422310979393,4.524018492740202,5.641627537157393,9.983221139766748,4.046693357352419,7.639775393780127,1.9451787926571495,1.040553721074643,9.97737620231218,6.620088154570877,4.847088407140681,7.308432652508161,2.5019987060068374,2.565724602528282,9.744999462768687,1.7379922200396625,5.1467241500511935,3.9664151603657882,5.465135080404684,2.4340649515490673,3.999647660435599,2.7920164787311585,1.6309260275887594,2.461510788727833,6.8649272684381035,7.8976821059705244,4.570164207878981,1.0710220306016471,1.537974995546112,9.432236143032554,8.279150766065953,8.78965030102937,0.2150344078624178,7.912716613410175,5.559492510658327,0.8344712667473331,3.546637023503736,0.44896884211464094,3.728657724054808,1.4379462968463164,2.7026700985303878,9.063496645204484,2.0355472602355738,2.762892559399045,6.954009941525049,2.1900445752999387,8.823303217540868,1.8317695470988637,6.040532563414503,1.7363536945327018,8.999202921911788,9.856095768182714,5.721467034045671,5.107117728541301,2.0452907403664113,1.728952010633692,9.430109211835125,0.3157387273472123,2.6499797952896733,1.7949998380449905,7.430336971359786,2.5471772652761535,6.975089846641394,8.185129571115748,8.561084798683435,8.273200461120231,1.4030121778235727,9.7375855473022,2.232080418938176,2.969754906257177,3.5324757871573444,0.909670759319714,2.6827428873507486,9.955927585181342,1.1835575046496405,6.845159837249769,9.24689284305757,7.5138399354055805,7.109965539401545,2.834376183277384,5.752980720602519,6.1031062087655545,3.625875816279102,7.041142289127549,2.442755849758469,3.4938513553482933,9.022654299746275,7.60586322271806,1.499191838368883,5.008784455385532,2.444010680518641,4.10306458388365,9.855249035455541,4.881604981514976,1.224028033082527,6.280697914662276,8.71366769755815,6.6509627184895965,5.059851815082793,7.99792115828399,1.0216262074894622,8.559876119224297,8.903663296998431,5.081271565606032,4.373669110854981,5.487724379480184,7.129197092051931,8.145310927434771,5.8221373296316,1.8175367726618241,4.039287647295477,0.20336558520043235,9.874559744174034,8.685094933646818,9.911205921103186,7.5079513997829945,4.187620273848688,0.27857551150699655,8.286068277614559,9.579107926558144,2.913832938391474,9.787058448943176,1.2420370609357023,1.2010150264729402,5.755395636584165,6.936000436847162,0.10721702801294031,4.65149964726212,3.8180475388364377,0.956250057705984,1.9359936252272614,1.8487648344717833,9.9136486402036,5.631877685337111,2.1111591127723885,9.770491403534772,3.297749584845082],"expected":[-1.6035506181354289,-2.5198459041901935,-5.134170223335689,-7.774202373972747,-3.4984076076596153,-2.556625759759258,-5.748161673683571,-2.466552512972811,-1.7140888788413728,-4.306243260707643],"x":[2.388524373062959,5.604409100902559,9.108608241755356,7.24974674354468,6.8900984126125,6.204940977377941,5.928553103210621,5.244136196020196,0.08075521911662387,6.239726252255959]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..c6ef116ff9ca --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/fixtures/julia/runner.jl @@ -0,0 +1,74 @@ +#!/usr/bin/env julia +# +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import Distributions: logpdf, Normal, Truncated +import JSON + +""" + gen( x, sigma, name ) + +Generate fixture data and write to file. + +# Arguments + +* `x`: input value +* `sigma`: scale parameter +* `name::AbstractString`: output filename + +# Examples + +``` julia +julia> x = rand( 1000 ) .* 10.0; +julia> sigma = rand( 1000 ) .* 10.0; +julia> gen( x, sigma, "data.json" ); +``` +""" +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 ] = logpdf( 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/logpdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.factory.js new file mode 100644 index 000000000000..65a64175e49c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.factory.js @@ -0,0 +1,118 @@ +/** +* @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 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 logpdf = factory( 1.0 ); + t.strictEqual( typeof logpdf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN` for `sigma`, the created function returns `NaN`', function test( t ) { + var logpdf; + var y; + + logpdf = factory( NaN ); + y = logpdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `sigma <= 0`, the created function always returns `NaN`', function test( t ) { + var logpdf; + var y; + + logpdf = factory( -1.0 ); + + y = logpdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logpdf = factory( 0.0 ); + + y = logpdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the created function returns `-Infinity` if provided `x < 0`', function test( t ) { + var logpdf; + var y; + + logpdf = factory( 1.0 ); + y = logpdf( -1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the created function evaluates the logpdf', function test( t ) { + var logpdf; + var delta; + var tol; + var x; + var y; + var i; + + x = data.x; + for ( i = 0; i < x.length; i++ ) { + logpdf = factory( data.sigma[i] ); + y = logpdf( x[i] ); + if ( data.expected[i] !== null ) { + if ( y === data.expected[i] ) { + t.strictEqual( y, data.expected[i], 'x: '+x[i]+', sigma: '+data.sigma[i]+', y: '+y+', expected: '+data.expected[i] ); + } else { + delta = abs( y - data.expected[ i ] ); + tol = 40.0 * EPS * abs( data.expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. sigma: '+data.sigma[i]+'. y: '+y+'. E: '+data.expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.js new file mode 100644 index 000000000000..c8fb79a7c82a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var logpdf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logpdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a factory method for generating `logpdf` functions', function test( t ) { + t.strictEqual( typeof logpdf.factory, 'function', 'exports a factory method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.logpdf.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.logpdf.js new file mode 100644 index 000000000000..901ad59dfd60 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.logpdf.js @@ -0,0 +1,102 @@ +/** +* @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 NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var logpdf = require( './../lib/main.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 logpdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = logpdf( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logpdf( 0.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `sigma <= 0`, the function returns `NaN`', function test( t ) { + var y; + + y = logpdf( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 0.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `x < 0`, the function returns `-Infinity`', function test( t ) { + var y = logpdf( -1.0, 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function evaluates the logpdf', function test( t ) { + var expected; + var delta; + var sigma; + var tol; + var x; + var y; + var i; + + x = data.x; + sigma = data.sigma; + expected = data.expected; + + for ( i = 0; i < x.length; i++ ) { + y = logpdf( x[i], sigma[i] ); + if ( expected[i] !== null ) { + 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 = 40.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/logpdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.native.js new file mode 100644 index 000000000000..0e12b55d53e5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/halfnormal/logpdf/test/test.native.js @@ -0,0 +1,111 @@ +/** +* @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 NINF = require( '@stdlib/constants/float64/ninf' ); +var EPS = require( '@stdlib/constants/float64/eps' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// VARIABLES // + +var logpdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logpdf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logpdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { + var y = logpdf( NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logpdf( 0.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `sigma <= 0`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = logpdf( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logpdf( 0.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `x < 0`, the function returns `-Infinity`', opts, function test( t ) { + var y = logpdf( -1.0, 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + t.end(); +}); + +tape( 'the function evaluates the logpdf', opts, function test( t ) { + var expected; + var delta; + var sigma; + var tol; + var x; + var y; + var i; + + x = data.x; + sigma = data.sigma; + expected = data.expected; + + for ( i = 0; i < x.length; i++ ) { + y = logpdf( x[i], sigma[i] ); + if ( expected[i] !== null ) { + 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 = 40.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(); +});