From 093b515f06fdf388b6b0151da3f74b705d77cfaa Mon Sep 17 00:00:00 2001 From: Archit Date: Sat, 27 Dec 2025 09:51:35 +0000 Subject: [PATCH 01/19] feat: implement entropy for hypergeometric distribution --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../dists/hypergeometric/entropy/README.md | 142 +++++++++++++++ .../entropy/benchmark/benchmark.js | 64 +++++++ .../entropy/benchmark/benchmark.native.js | 72 ++++++++ .../entropy/benchmark/c/Makefile | 146 +++++++++++++++ .../entropy/benchmark/c/benchmark.c | 143 +++++++++++++++ .../dists/hypergeometric/entropy/binding.gyp | 170 ++++++++++++++++++ .../docs/img/equation_hypergeometric_mean.svg | 30 ++++ .../hypergeometric/entropy/docs/repl.txt | 56 ++++++ .../entropy/docs/types/index.d.ts | 75 ++++++++ .../hypergeometric/entropy/docs/types/test.ts | 58 ++++++ .../entropy/examples/c/Makefile | 146 +++++++++++++++ .../entropy/examples/c/example.c | 43 +++++ .../hypergeometric/entropy/examples/index.js | 37 ++++ .../dists/hypergeometric/entropy/include.gypi | 53 ++++++ .../stats/base/dists/hypergeometric/mean.h | 40 +++++ .../dists/hypergeometric/entropy/lib/index.js | 43 +++++ .../dists/hypergeometric/entropy/lib/main.js | 95 ++++++++++ .../hypergeometric/entropy/lib/native.js | 60 +++++++ .../hypergeometric/entropy/manifest.json | 71 ++++++++ .../dists/hypergeometric/entropy/package.json | 66 +++++++ .../dists/hypergeometric/entropy/src/Makefile | 70 ++++++++ .../dists/hypergeometric/entropy/src/addon.c | 23 +++ .../dists/hypergeometric/entropy/src/main.c | 39 ++++ .../entropy/test/fixtures/julia/REQUIRE | 3 + .../entropy/test/fixtures/julia/data.json | 1 + .../entropy/test/fixtures/julia/runner.jl | 77 ++++++++ .../dists/hypergeometric/entropy/test/test.js | 139 ++++++++++++++ .../entropy/test/test.native.js | 113 ++++++++++++ 28 files changed, 2075 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypergeometric_mean.svg create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include/stdlib/stats/base/dists/hypergeometric/mean.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/REQUIRE create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/data.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/README.md new file mode 100644 index 000000000000..334beaea7df8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/README.md @@ -0,0 +1,142 @@ + + +# Entropy + +> [Hypergeometric][hypergeometric-distribution] distribution [entropy][entropy]. + +The [entropy][entropy] (in nats) for a [hypergeometric][hypergeometric-distribution] random variable is + +
+ Entropy for a hypergeometric distribution. +
+
+ +where `N` is the population size, `K` is the subpopulation size, and `n` is the number of draws. + +
+ +## Usage + +```javascript +var entropy = require( '@stdlib/stats/base/dists/hypergeometric/entropy' ); +``` + +#### entropy( N, K, n ) + +Returns the [entropy][entropy] of a [hypergeometric][hypergeometric-distribution] distribution with parameters `N` (population size), `K` (subpopulation size), and `n` (number of draws). + +```javascript +var v = entropy( 16, 11, 4 ); +// returns ~1.216 + +v = entropy( 2, 1, 1 ); +// returns ~0.693 +``` + +If provided `NaN` for any parameter, the function returns `NaN`. + +```javascript +var v = entropy( NaN, 10, 4 ); +// returns NaN + +v = entropy( 20, NaN, 4 ); +// returns NaN + +v = entropy( 20, 10, NaN ); +// returns NaN +``` + +If provided a parameter that is not a nonnegative integer, the function returns `NaN`. + +```javascript +var v = entropy( 10.5, 5, 2 ); +// returns NaN + +v = entropy( 10, 1.5, 2 ); +// returns NaN + +v = entropy( 10, 5, -2.0 ); +// returns NaN +``` + +If the number of draws `n` exceeds the population size `N`, the function returns `NaN`. + +```javascript +var v = entropy( 10, 5, 12 ); +// returns NaN +``` + +If the subpopulation size `K` exceeds the population size `N`, the function returns `NaN`. + +```javascript +var v = entropy( 10, 12, 5 ); +// returns NaN +``` + +
+ + + +
+ +## Examples + +```javascript +var entropy = require( '@stdlib/stats/base/dists/hypergeometric/entropy' ); + +var v = entropy( 16, 11, 4 ); +console.log( v ); +// => 1.2156868611027067 + +v = entropy( 2, 1, 1 ); +console.log( v ); +// => 0.6931471805599453 + +v = entropy( 10, 5, 12 ); +console.log( v ); +// => NaN +``` + +
+ + + +
+ +
+ + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js new file mode 100644 index 000000000000..874622842114 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js @@ -0,0 +1,64 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pkg = require( './../package.json' ).name; +var mean = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var len; + var N; + var K; + var n; + var y; + var i; + + len = 100; + N = new Float64Array( len ); + K = new Float64Array( len ); + n = new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + N[ i ] = discreteUniform( 1, 100 ); + K[ i ] = discreteUniform( 1, N[ i ] ); + n[ i ] = discreteUniform( 1, N[ i ] ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mean( N[ i % len ], K[ i % len ], n[ 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/hypergeometric/entropy/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js new file mode 100644 index 000000000000..42ca4ee74ddc --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js @@ -0,0 +1,72 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var mean = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mean instanceof Error ) +}; + + +// MAIN // + +bench( pkg+'::native', opts, function benchmark( b ) { + var len; + var N; + var K; + var n; + var y; + var i; + + len = 100; + N = new Float64Array( len ); + K = new Float64Array( len ); + n= new Float64Array( len ); + for ( i = 0; i < len; i++ ) { + N[ i ] = discreteUniform( 1, 100 ); + K[ i ] = discreteUniform( 1, N[ i ] ); + n[ i ] = discreteUniform( 1, N[ i ] ); + } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mean( N[ i % len ], K[ i % len ], n[ 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/hypergeometric/entropy/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/Makefile new file mode 100644 index 000000000000..a4bd7b38fd74 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/hypergeometric/entropy/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/benchmark.c new file mode 100644 index 000000000000..c92bf10fcdc2 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/benchmark.c @@ -0,0 +1,143 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/hypergeometric/mean.h" +#include +#include +#include +#include +#include +#include + +#define NAME "hypergeometric-mean" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random integer on the interval [min,max]. +* +* @param min minimum value (inclusive) +* @param max maximum value (inclusive) +* @return random integer +*/ +static int32_t random_int( const int32_t min, const int32_t max ) { + int32_t v = rand() % ( max - min + 1 ); + return min + v; +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double elapsed; + int32_t N[ 100 ]; + int32_t K[ 100 ]; + int32_t n[ 100 ]; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + N[i] = random_int( 1, 100 ); + K[i] = random_int( 0, N[i] ); + n[i] = random_int( 0, N[i] ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_hypergeometric_mean( N[ i % 100 ], K[ i % 100 ], n[ 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/hypergeometric/entropy/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/hypergeometric/entropy/docs/img/equation_hypergeometric_mean.svg b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypergeometric_mean.svg new file mode 100644 index 000000000000..6cfaec4ed66e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypergeometric_mean.svg @@ -0,0 +1,30 @@ + +double-struck upper E left-bracket upper X right-bracket equals n StartFraction upper K Over upper N EndFraction + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/repl.txt new file mode 100644 index 000000000000..dc69409e8e7f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/repl.txt @@ -0,0 +1,56 @@ +{{alias}}( N, K, n ) + Evaluates the entropy for a hypergeometric distribution with population + size `N`, subpopulation size `K`, and number of draws `n`. + + If provided `NaN` as any argument, the function returns `NaN`. + + If provided a population size `N`, subpopulation size `K` or draws `n` which + is not a nonnegative integer, the function returns `NaN`. + + If the number of draws `n` or subpopulation size `K` exceeds population size + `N`, the function returns `NaN`. + + Parameters + ---------- + N: integer + Population size. + + K: integer + Subpopulation size. + + n: integer + Number of draws. + + Returns + ------- + out: number + Entropy. + + Examples + -------- + > var v = {{alias}}( 16, 11, 4 ) + ~1.216 + > v = {{alias}}( 2, 1, 1 ) + ~0.693 + + > v = {{alias}}( NaN, 10, 5, 2 ) + NaN + > v = {{alias}}( 20, NaN, 5, 2 ) + NaN + > v = {{alias}}( 20, 10, NaN, 2 ) + NaN + + > v = {{alias}}( 10.5, 5, 2 ) + NaN + > v = {{alias}}( 10, 1.5, 2 ) + NaN + > v = {{alias}}( 10, 5, -2.0 ) + NaN + > v = {{alias}}( 10, 5, 12 ) + NaN + > v = {{alias}}( 10, 12, 5 ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/index.d.ts new file mode 100644 index 000000000000..77a30496748f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/index.d.ts @@ -0,0 +1,75 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Returns the entropy of a hypergeometric distribution. +* +* ## Notes +* +* - If provided a population size `N`, subpopulation size `K` or draws `n` which is not a nonnegative integer, the function returns `NaN`. +* - If the number of draws `n` or subpopulation size `K` exceeds population size `N`, the function returns `NaN`. +* +* @param N - population size +* @param K - subpopulation size +* @param n - number of draws +* @returns entropy +* +* @example +* var v = entropy( 16, 11, 4 ); +* // returns 1.2156868611027067 +* +* @example +* var v = entropy( 2, 1, 1 ); +* // returns 0.6931471805599453 +* +* @example +* var v = entropy( 10, 5, 12 ); +* // returns NaN +* +* @example +* var v = entropy( 10.3, 10, 4 ); +* // returns NaN +* +* @example +* var v = entropy( 10, 5.5, 4 ); +* // returns NaN +* +* @example +* var v = entropy( 10, 5, 4.5 ); +* // returns NaN +* +* @example +* var v = entropy( NaN, 10, 4 ); +* // returns NaN +* +* @example +* var v = entropy( 20, NaN, 4 ); +* // returns NaN +* +* @example +* var v = entropy( 20, 10, NaN ); +* // returns NaN +*/ +declare function entropy( N: number, K: number, n: number ): number; + + +// EXPORTS // + +export = entropy; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts new file mode 100644 index 000000000000..98827a2d40bb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts @@ -0,0 +1,58 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2019 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import mean = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + mean( 16, 12, 5 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than three numbers... +{ + mean( true, 3, 2 ); // $ExpectError + mean( false, 4, 2 ); // $ExpectError + mean( '5', 3, 2 ); // $ExpectError + mean( [], 1, 1 ); // $ExpectError + mean( {}, 2, 1 ); // $ExpectError + mean( ( x: number ): number => x, 2, 1 ); // $ExpectError + + mean( 90, true, 12 ); // $ExpectError + mean( 90, false, 12 ); // $ExpectError + mean( 50, '5', 8 ); // $ExpectError + mean( 80, [], 10 ); // $ExpectError + mean( 90, {}, 12 ); // $ExpectError + mean( 80, ( x: number ): number => x, 12 ); // $ExpectError + + mean( 90, 18, true ); // $ExpectError + mean( 90, 18, false ); // $ExpectError + mean( 50, 10, '5' ); // $ExpectError + mean( 80, 16, [] ); // $ExpectError + mean( 90, 18, {} ); // $ExpectError + mean( 80, 16, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + mean(); // $ExpectError + mean( 30 ); // $ExpectError + mean( 30, 6 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/Makefile new file mode 100644 index 000000000000..25ced822f96a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/hypergeometric/entropy/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/example.c new file mode 100644 index 000000000000..c4af680314c4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/example.c @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/hypergeometric/mean.h" +#include +#include +#include + +static int32_t random_int( const int32_t min, const int32_t max ) { + int32_t v = rand() % ( max - min + 1 ); + return min + v; +} + +int main( void ) { + int32_t N; + int32_t K; + int32_t n; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + N = random_int( 1, 20 ); + K = random_int( 0, N ); + n = random_int( 0, K ); + y = stdlib_base_dists_hypergeometric_mean( N, K, n ); + printf( "N: %d, K: %d, n: %d, E(X;N,K,n): %.4f\n", N, K, n, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js new file mode 100644 index 000000000000..8198166bca4b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js @@ -0,0 +1,37 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 round = require( '@stdlib/math/base/special/round' ); +var mean = require( './../lib' ); + +var v; +var i; +var N; +var K; +var n; + +for ( i = 0; i < 10; i++ ) { + N = round( randu() * 20 ); + K = round( randu() * N ); + n = round( randu() * K ); + v = mean( N, K, n ); + console.log( 'N: %d, K: %d, n: %d, E(X;N,K,n): %d', N, K, n, v.toFixed( 4 ) ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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': [ + ' + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Returns the expected value of a hypergeometric distribution. +*/ +double stdlib_base_dists_hypergeometric_mean( const int32_t N, const int32_t K, const int32_t n ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_MEAN_H diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js new file mode 100644 index 000000000000..e7ed3551ffa7 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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'; + +/** +* Hypergeometric distribution expected value. +* +* @module @stdlib/stats/base/dists/hypergeometric/entropy +* +* @example +* var entropy = require( '@stdlib/stats/base/dists/hypergeometric/entropy' ); +* +* var v = entropy( 16, 11, 4 ); +* // returns ~1.216 +* +* v = entropy( 2, 1, 1 ); +* // returns ~0.693 +*/ + +// MODULES // + +var entropy = require( './main.js' ); + + +// EXPORTS // + +module.exports = entropy; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js new file mode 100644 index 000000000000..c2549f2dc2cf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js @@ -0,0 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 PINF = require( '@stdlib/constants/float64/pinf' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' ); +var ln = require( '@stdlib/math/base/special/ln' ); +var pmf = require( '@stdlib/stats/base/dists/hypergeometric/pmf' ); + + +// MAIN // + +/** +* Returns the Shannon entropy of a hypergeometric distribution. +* +* @param {NonNegativeInteger} N - population size +* @param {NonNegativeInteger} K - subpopulation size +* @param {NonNegativeInteger} n - number of draws +* @returns {number} entropy +* +* @example +* var h = entropy( 16, 11, 4 ); +* // returns ~1.216 +* +* @example +* var h = entropy( 2, 1, 1 ); +* // returns ~0.693 +* +* @example +* var h = entropy( 10, 5, 12 ); +* // returns NaN +*/ +function entropy(N, K, n) { + var min; + var max; + var H; + var k; + var p; + + if ( + isnan(N) || + isnan(K) || + isnan(n) + ) { + return NaN; + } + if ( + !isNonNegativeInteger(N) || + !isNonNegativeInteger(K) || + !isNonNegativeInteger(n) || + N === PINF || + K === PINF || + K > N || + n > N + ) { + return NaN; + } + + // Support range: + min = ((n + K - N) > 0) ? (n + K - N) : 0; + max = (n < K) ? n : K; + + H = 0.0; + for (k = min; k <= max; k++) { + p = pmf(k, N, K, n); + if (p > 0.0) { + H -= p * ln(p); + } + } + return H; +} + + +// EXPORTS // + +module.exports = entropy; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/native.js new file mode 100644 index 000000000000..13ee8e82426a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/native.js @@ -0,0 +1,60 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 // + +/** +* Returns the expected value of a hypergeometric distribution. +* +* @private +* @param {NonNegativeInteger} N - population size +* @param {NonNegativeInteger} K - subpopulation size +* @param {NonNegativeInteger} n - number of draws +* @returns {NonNegativeNumber} expected value +* +* @example +* var v = mean( 16, 11, 4 ); +* // returns 2.75 +* +* @example +* var v = mean( 2, 1, 1 ); +* // returns 0.5 +* +* @example +* var v = mean( 10, 5, 12 ); +* // returns NaN +* +* @example +* var v = mean( 10, -2, 4 ); +* // returns NaN +*/ +function mean( N, K, n ) { + return addon( N, K, n ); +} + + +// EXPORTS // + +module.exports = mean; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json new file mode 100644 index 000000000000..382e476a4eed --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json @@ -0,0 +1,71 @@ +{ + "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/ternary" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json new file mode 100644 index 000000000000..cc767c51da3b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/stats/base/dists/hypergeometric/mean", + "version": "0.0.0", + "description": "Hypergeometric distribution expected value.", + "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", + "parameter", + "discrete", + "hypergeometric", + "univariate" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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/hypergeometric/entropy/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/addon.c new file mode 100644 index 000000000000..6c087587f6d5 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/addon.c @@ -0,0 +1,23 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/hypergeometric/mean.h" +#include "stdlib/math/base/napi/ternary.h" + +// cppcheck-suppress shadowFunction +STDLIB_MATH_BASE_NAPI_MODULE_III_D( stdlib_base_dists_hypergeometric_mean ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c new file mode 100644 index 000000000000..509428ce6853 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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/hypergeometric/mean.h" +#include + +/** +* Returns the expected value of a hypergeometric distribution. +* +* @param N population size +* @param K subpopulation size +* @param n number of draws +* @return expected value +* +* @example +* double v = stdlib_base_dists_hypergeometric_mean( 16, 11, 4 ); +* // returns 2.75 +*/ +double stdlib_base_dists_hypergeometric_mean( const int32_t N, const int32_t K, const int32_t n ) { + if ( N < 0 || K < 0 || n < 0 || K > N || n > N ) { + return 0.0/0.0; // NaN + } + return ( (double)n * (double)K ) / (double)N; +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/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/hypergeometric/entropy/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/data.json new file mode 100644 index 000000000000..b1c6db48482f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"expected":[1.0756302521008403,26.704545454545453,28.983050847457626,2.4324324324324325,61.25714285714286,26.86315789473684,14.795454545454545,34.5,2.9293478260869565,17.68421052631579,13.538461538461538,7.5,0.011764705882352941,0.0,143.373786407767,19.804878048780488,0.8210526315789474,25.23076923076923,57.6,5.6875,74.16666666666667,18.182926829268293,34.92537313432836,0.18181818181818182,2.234375,6.222222222222222,37.92045454545455,66.45161290322581,13.732394366197184,6.6976744186046515,0.0,19.369127516778523,0.4976958525345622,31.423076923076923,5.714285714285714,15.19047619047619,44.56818181818182,8.32258064516129,3.392857142857143,13.023255813953488,5.47945205479452,106.69626168224299,11.878787878787879,0.16,2.508771929824561,10.458100558659218,0.35294117647058826,0.11428571428571428,53.81725888324873,5.76,16.944444444444443,99.0,4.0,5.078431372549019,31.989637305699482,12.235294117647058,10.54054054054054,1.3928571428571428,55.660377358490564,0.9608938547486033,40.994594594594595,60.07692307692308,147.05825242718447,13.16,3.0,32.28310502283105,0.5357142857142857,5.67816091954023,31.042857142857144,15.422680412371134,0.2898550724637681,7.4,18.76,40.14746543778802,11.088372093023256,17.445454545454545,10.427586206896551,56.77777777777778,126.98019801980197,25.905797101449274,0.0,59.47959183673469,4.583333333333333,0.4444444444444444,0.28,9.526717557251908,109.32057416267942,26.367816091954023,0.13333333333333333,3.5675675675675675,30.23404255319149,25.333333333333332,12.566137566137566,0.18274111675126903,0.1917808219178082,2.857142857142857,8.846153846153847,1.9130434782608696,19.03,4.170731707317073],"N":[119.0,176.0,59.0,37.0,70.0,95.0,88.0,210.0,184.0,209.0,39.0,62.0,85.0,49.0,206.0,205.0,190.0,65.0,150.0,32.0,120.0,164.0,67.0,66.0,64.0,27.0,88.0,124.0,142.0,43.0,25.0,149.0,217.0,130.0,35.0,84.0,176.0,93.0,196.0,129.0,219.0,214.0,165.0,25.0,114.0,179.0,187.0,35.0,197.0,200.0,162.0,121.0,28.0,102.0,193.0,102.0,37.0,112.0,159.0,179.0,185.0,78.0,206.0,200.0,28.0,219.0,28.0,87.0,140.0,97.0,69.0,55.0,150.0,217.0,215.0,110.0,145.0,189.0,202.0,138.0,187.0,196.0,72.0,27.0,50.0,131.0,209.0,87.0,150.0,111.0,188.0,81.0,189.0,197.0,73.0,49.0,78.0,138.0,200.0,164.0],"K":[16.0,100.0,45.0,15.0,67.0,58.0,42.0,161.0,77.0,66.0,24.0,31.0,1.0,1.0,179.0,145.0,52.0,41.0,120.0,26.0,100.0,71.0,60.0,4.0,13.0,14.0,71.0,103.0,65.0,24.0,3.0,74.0,18.0,95.0,20.0,44.0,148.0,86.0,35.0,112.0,48.0,177.0,70.0,2.0,26.0,52.0,11.0,4.0,171.0,128.0,61.0,121.0,16.0,37.0,98.0,39.0,30.0,26.0,150.0,86.0,96.0,71.0,187.0,56.0,12.0,101.0,5.0,26.0,82.0,44.0,10.0,37.0,67.0,132.0,149.0,101.0,63.0,147.0,171.0,65.0,69.0,174.0,66.0,4.0,7.0,39.0,204.0,74.0,5.0,36.0,98.0,76.0,95.0,6.0,7.0,35.0,30.0,24.0,173.0,57.0],"n":[8.0,47.0,38.0,6.0,64.0,44.0,31.0,45.0,7.0,56.0,22.0,15.0,1.0,0.0,165.0,28.0,3.0,40.0,72.0,7.0,89.0,42.0,39.0,3.0,11.0,12.0,47.0,80.0,30.0,12.0,0.0,39.0,6.0,43.0,10.0,29.0,53.0,9.0,19.0,15.0,25.0,129.0,28.0,2.0,11.0,36.0,6.0,1.0,62.0,9.0,45.0,99.0,7.0,14.0,63.0,32.0,13.0,6.0,59.0,2.0,79.0,66.0,162.0,47.0,7.0,70.0,3.0,19.0,53.0,34.0,2.0,11.0,42.0,66.0,16.0,19.0,24.0,73.0,150.0,55.0,0.0,67.0,5.0,3.0,2.0,32.0,112.0,31.0,4.0,11.0,58.0,27.0,25.0,6.0,2.0,4.0,23.0,11.0,22.0,12.0]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..08ada4ef2bb8 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl @@ -0,0 +1,77 @@ +#!/usr/bin/env julia +# +# @license Apache-2.0 +# +# Copyright (c) 2018 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import Distributions: mean, Hypergeometric +import JSON + +""" + gen( N, K, n, name ) + +Generate fixture data and write to file. + +# Arguments + +* `N`: population size +* `K`: subpopulation size +* `n`: number of draws +* `name::AbstractString`: output filename + +# Examples + +``` julia +julia> N = round.( ( rand( 1000 ) .* 200 ) .+ 20 ); +julia> K = round.( rand( 1000 ) .* N ); +julia> n = round.( rand( 1000 ) .* K ); +julia> gen( N, K, n, "data.json" ); +``` +""" +function gen( N, K, n, name ) + z = Array{Float64}( undef, length(N) ); + for i in eachindex(N) + z[ i ] = mean( Hypergeometric( K[i], N[i] - K[i], n[i] ) ); + end + + # Store data to be written to file as a collection: + data = Dict([ + ("N", N), + ("K", K), + ("n", n), + ("expected", z) + ]); + + # Based on the script directory, create an output filepath: + filepath = joinpath( dir, name ); + + # Write the data to the output filepath as JSON: + outfile = open( filepath, "w" ); + write( outfile, JSON.json(data) ); + write( outfile, "\n" ); + close( outfile ); +end + +# Get the filename: +file = @__FILE__; + +# Extract the directory in which this file resides: +dir = dirname( file ); + +# Generate fixtures: +N = round.( ( rand( 100 ) .* 200 ) .+ 20 ); +K = round.( rand( 100 ) .* N ); +n = round.( rand( 100 ) .* K ); +gen( N, K, n, "data.json" ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js new file mode 100644 index 000000000000..3950e7a91a5b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js @@ -0,0 +1,139 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 entropy = require( './../lib' ).default; + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof entropy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var v = entropy( NaN, 10, 5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = entropy( 20, NaN, 5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = entropy( 20, 10, NaN ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided a population size `N` which is not a nonnegative integer, the function returns `NaN`', function test( t ) { + var v; + + v = entropy( 10.5, 5, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = entropy( -2, 5, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided a subpopulation size `K` which is not a nonnegative integer, the function returns `NaN`', function test( t ) { + var v; + + v = entropy( 10, 5.5, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = entropy( 10, -2, 2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if provided a number of draws `n` which is not a nonnegative integer, the function returns `NaN`', function test( t ) { + var v; + + v = entropy( 10, 5, 2.5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = entropy( 10, 5, -2 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + +tape( 'if the number of draws `n` exceeds the population size `N`, the function returns `NaN`', function test( t ) { + var v = entropy( 10, 5, 11 ); + t.equal( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'if the subpopulation size `K` exceeds the population size `N`, the function returns `NaN`', function test( t ) { + var v = entropy( 10, 11, 5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + t.end(); +}); + +tape( 'the function computes the entropy of a hypergeometric distribution', function test( t ) { + var expected; + var delta; + var tol; + var v; + + // Case 1: N=2, K=1, n=1 (Like flipping a coin: 50/50 chance of getting the special item) + v = entropy( 2, 1, 1 ); + expected = 0.69314718056; + delta = abs( v - expected ); + tol = 1.0e-9; + t.ok( delta < tol, 'within tolerance. v: ' + v + '. expected: ' + expected ); + + // Case 2: N=10, K=5, n=1 (Draw 1 from 50/50 mix) -> Same entropy + v = entropy( 10, 5, 1 ); + expected = 0.69314718056; + delta = abs( v - expected ); + t.ok( delta < tol, 'within tolerance. v: ' + v + '. expected: ' + expected ); + + // Case 3: N=16, K=11, n=4 (From your documentation example) + v = entropy( 16, 11, 4 ); + expected = 1.216395; + delta = abs( v - expected ); + tol = 1.0e-5; + t.ok( delta < tol, 'within tolerance. v: ' + v + '. expected: ' + expected ); + + t.end(); +}); + +tape( 'if the outcome is certain (only one possible value for k), the entropy is 0', function test( t ) { + var v; + + // If K=N, every item is special. If we draw n, we ALWAYS get n special items. k=n is 100%. + v = entropy( 10, 10, 5 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + // If K=0, no item is special. We ALWAYS get 0 special items. k=0 is 100%. + v = entropy( 10, 0, 5 ); + t.strictEqual( v, 0.0, 'returns 0' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js new file mode 100644 index 000000000000..7c5c23db5e65 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js @@ -0,0 +1,113 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 EPS = require( '@stdlib/constants/float64/eps' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// VARIABLES // + +var mean = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( mean instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof mean, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided an `N` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { + var v; + + v = mean( -2, 4, 2 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + v = mean( -1, 4, 2 ); + t.strictEqual( isnan( v ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `K` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { + var y; + + y = mean( 20, -2, 10 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( 20, -1, 10 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided an `n` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { + var y; + + y = mean( 40, 20, -2 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = mean( 40, 20, -1 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the mean of a hypergeometric distribution', opts, function test( t ) { + var expected; + var delta; + var tol; + var N; + var K; + var n; + var y; + var i; + + expected = data.expected; + N = data.N; + K = data.K; + n = data.n; + for ( i = 0; i < n.length; i++ ) { + y = mean( N[i], K[i], n[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'N: '+N[i]+', K: '+K[i]+', n: '+n[i]+', y: '+y+', expected: '+expected[i] ); + } else { + delta = abs( y - expected[ i ] ); + tol = 1.0 * EPS * abs( expected[ i ] ); + t.ok( delta <= tol, 'within tolerance. N: '+N[i]+'. K: '+K[i]+'. n: '+n[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); + } + } + t.end(); +}); From f3b122003230fdff2c4e31436e2086632344006d Mon Sep 17 00:00:00 2001 From: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> Date: Sat, 27 Dec 2025 11:41:30 +0000 Subject: [PATCH 02/19] chore: update copyright years --- .../@stdlib/stats/base/dists/hypergeometric/entropy/README.md | 2 +- .../base/dists/hypergeometric/entropy/benchmark/benchmark.js | 2 +- .../base/dists/hypergeometric/entropy/docs/types/index.d.ts | 2 +- .../stats/base/dists/hypergeometric/entropy/docs/types/test.ts | 2 +- .../stats/base/dists/hypergeometric/entropy/examples/index.js | 2 +- .../stats/base/dists/hypergeometric/entropy/lib/index.js | 2 +- .../@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js | 2 +- .../dists/hypergeometric/entropy/test/fixtures/julia/runner.jl | 2 +- .../stats/base/dists/hypergeometric/entropy/test/test.js | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/README.md b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/README.md index 334beaea7df8..5d5076091fd1 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2018 The Stdlib Authors. +Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js index 874622842114..4322395bc562 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/index.d.ts index 77a30496748f..412311cbb7e5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts index 98827a2d40bb..ec4d6137c583 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2019 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js index 8198166bca4b..709b11b05778 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js index e7ed3551ffa7..cc5938fc001d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js index c2549f2dc2cf..4640fd421f26 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl index 08ada4ef2bb8..0a7a92ab211b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl @@ -2,7 +2,7 @@ # # @license Apache-2.0 # -# Copyright (c) 2018 The Stdlib Authors. +# Copyright (c) 2025 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. diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js index 3950e7a91a5b..e8c419bff53f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2025 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. From ce6f412f403326846cc777eedd20bc125870f349 Mon Sep 17 00:00:00 2001 From: Archit Date: Sat, 27 Dec 2025 14:58:43 +0000 Subject: [PATCH 03/19] feat: implement native C entropy calculation and fix tests --- .../dists/hypergeometric/entropy/binding.gyp | 82 ++----------- .../dists/hypergeometric/entropy/include.gypi | 20 +--- .../hypergeometric/{mean.h => entropy.h} | 15 +-- .../dists/hypergeometric/entropy/lib/main.js | 37 +++--- .../hypergeometric/entropy/lib/native.js | 26 ++--- .../hypergeometric/entropy/manifest.json | 26 ----- .../dists/hypergeometric/entropy/package.json | 4 +- .../dists/hypergeometric/entropy/src/addon.c | 6 +- .../dists/hypergeometric/entropy/src/main.c | 37 ++++-- .../entropy/test/test.native.js | 108 ++++-------------- 10 files changed, 98 insertions(+), 263 deletions(-) rename lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include/stdlib/stats/base/dists/hypergeometric/{mean.h => entropy.h} (56%) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/binding.gyp index 68a1ca11d160..5ed67b6a6277 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/binding.gyp +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/binding.gyp @@ -14,157 +14,95 @@ # 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/hypergeometric/entropy/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include.gypi index ecfaf82a3279..15aa04ad4f3b 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include.gypi +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include.gypi @@ -14,40 +14,22 @@ # 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': [ ' -/* -* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. -*/ #ifdef __cplusplus extern "C" { #endif /** -* Returns the expected value of a hypergeometric distribution. +* Returns the entropy of a hypergeometric distribution. */ -double stdlib_base_dists_hypergeometric_mean( const int32_t N, const int32_t K, const int32_t n ); +double stdlib_base_dists_hypergeometric_entropy( const int32_t N, const int32_t K, const int32_t n ); #ifdef __cplusplus } #endif -#endif // !STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_MEAN_H +#endif // !STDLIB_STATS_BASE_DISTS_HYPERGEOMETRIC_ENTROPY_H diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js index 4640fd421f26..9d6c520a6253 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/main.js @@ -25,12 +25,13 @@ var isnan = require( '@stdlib/math/base/assert/is-nan' ); var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' ); var ln = require( '@stdlib/math/base/special/ln' ); var pmf = require( '@stdlib/stats/base/dists/hypergeometric/pmf' ); +var accumulator = require( '@stdlib/stats/incr/sum' ); // Import accumulator // MAIN // /** -* Returns the Shannon entropy of a hypergeometric distribution. +* Returns the entropy of a hypergeometric distribution. * * @param {NonNegativeInteger} N - population size * @param {NonNegativeInteger} K - subpopulation size @@ -49,24 +50,24 @@ var pmf = require( '@stdlib/stats/base/dists/hypergeometric/pmf' ); * var h = entropy( 10, 5, 12 ); * // returns NaN */ -function entropy(N, K, n) { +function entropy( N, K, n ) { + var acc; var min; var max; - var H; var k; var p; if ( - isnan(N) || - isnan(K) || - isnan(n) + isnan( N ) || + isnan( K ) || + isnan( n ) ) { return NaN; } if ( - !isNonNegativeInteger(N) || - !isNonNegativeInteger(K) || - !isNonNegativeInteger(n) || + !isNonNegativeInteger( N ) || + !isNonNegativeInteger( K ) || + !isNonNegativeInteger( n ) || N === PINF || K === PINF || K > N || @@ -75,18 +76,18 @@ function entropy(N, K, n) { return NaN; } - // Support range: - min = ((n + K - N) > 0) ? (n + K - N) : 0; - max = (n < K) ? n : K; + min = ( (n + K - N ) > 0 ) ? ( n + K - N ) : 0; + max = ( n < K ) ? n : K; - H = 0.0; - for (k = min; k <= max; k++) { - p = pmf(k, N, K, n); - if (p > 0.0) { - H -= p * ln(p); + acc = accumulator(); + + for ( k = min; k <= max; k++ ) { + p = pmf( k, N, K, n ); + if ( p > 0.0 ) { + acc( -p * ln( p ) ); } } - return H; + return acc(); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/native.js index 13ee8e82426a..5b9f762f73ff 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/native.js @@ -7,7 +7,7 @@ * 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 +* 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, @@ -26,35 +26,27 @@ var addon = require( './../src/addon.node' ); // MAIN // /** -* Returns the expected value of a hypergeometric distribution. +* Returns the entropy of a hypergeometric distribution. * * @private * @param {NonNegativeInteger} N - population size * @param {NonNegativeInteger} K - subpopulation size * @param {NonNegativeInteger} n - number of draws -* @returns {NonNegativeNumber} expected value +* @returns {number} entropy * * @example -* var v = mean( 16, 11, 4 ); -* // returns 2.75 +* var v = entropy( 16, 11, 4 ); +* // returns ~1.216 * * @example -* var v = mean( 2, 1, 1 ); -* // returns 0.5 -* -* @example -* var v = mean( 10, 5, 12 ); -* // returns NaN -* -* @example -* var v = mean( 10, -2, 4 ); -* // returns NaN +* var v = entropy( 2, 1, 1 ); +* // returns ~0.693 */ -function mean( N, K, n ) { +function entropy( N, K, n ) { return addon( N, K, n ); } // EXPORTS // -module.exports = mean; +module.exports = entropy; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json index 382e476a4eed..f439924789a0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json @@ -40,32 +40,6 @@ "dependencies": [ "@stdlib/math/base/napi/ternary" ] - }, - { - "task": "benchmark", - "wasm": false, - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] - }, - { - "task": "examples", - "wasm": false, - "src": [ - "./src/main.c" - ], - "include": [ - "./include" - ], - "libraries": [], - "libpath": [], - "dependencies": [] } ] } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json index cc767c51da3b..f0c23ecd9d52 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/stats/base/dists/hypergeometric/mean", + "name": "@stdlib/stats/base/dists/hypergeometric/entropy", "version": "0.0.0", - "description": "Hypergeometric distribution expected value.", + "description": "Hypergeometric distribution entropy.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/addon.c index 6c087587f6d5..a5337c29f41a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/addon.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/addon.c @@ -7,7 +7,7 @@ * 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 +* 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, @@ -16,8 +16,8 @@ * limitations under the License. */ -#include "stdlib/stats/base/dists/hypergeometric/mean.h" +#include "stdlib/stats/base/dists/hypergeometric/entropy.h" #include "stdlib/math/base/napi/ternary.h" // cppcheck-suppress shadowFunction -STDLIB_MATH_BASE_NAPI_MODULE_III_D( stdlib_base_dists_hypergeometric_mean ) +STDLIB_MATH_BASE_NAPI_MODULE_III_D( stdlib_base_dists_hypergeometric_entropy ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c index 509428ce6853..b3dded5accb3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c @@ -7,7 +7,7 @@ * 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 +* 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, @@ -16,24 +16,41 @@ * limitations under the License. */ -#include "stdlib/stats/base/dists/hypergeometric/mean.h" +#include "stdlib/stats/base/dists/hypergeometric/entropy.h" +#include +#include #include +static double log_binomial( int32_t n, int32_t k ) { + return lgamma( n + 1.0 ) - lgamma( k + 1.0 ) - lgamma( n - k + 1.0 ); +} + +static double hypergeometric_pmf( int32_t k, int32_t N, int32_t K, int32_t n ) { + return exp( log_binomial( K, k ) + log_binomial( N - K, n - k ) - log_binomial( N, n ) ); +} + /** -* Returns the expected value of a hypergeometric distribution. +* Returns the entropy of a hypergeometric distribution. * * @param N population size * @param K subpopulation size * @param n number of draws -* @return expected value -* -* @example -* double v = stdlib_base_dists_hypergeometric_mean( 16, 11, 4 ); -* // returns 2.75 +* @return entropy */ -double stdlib_base_dists_hypergeometric_mean( const int32_t N, const int32_t K, const int32_t n ) { +double stdlib_base_dists_hypergeometric_entropy( const int32_t N, const int32_t K, const int32_t n ) { if ( N < 0 || K < 0 || n < 0 || K > N || n > N ) { return 0.0/0.0; // NaN } - return ( (double)n * (double)K ) / (double)N; + + int32_t min = ( n + K - N > 0 ) ? ( n + K - N ) : 0; + int32_t max = ( n < K ) ? n : K; + + double H = 0.0; + for ( int32_t k = min; k <= max; k++ ) { + double p = hypergeometric_pmf( k, N, K, n ); + if ( p > 0.0 ) { + H -= p * log( p ); + } + } + return H; } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js index 7c5c23db5e65..5bbdf171ea12 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js @@ -1,113 +1,47 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2025 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 EPS = require( '@stdlib/constants/float64/eps' ); - - -// FIXTURES // - -var data = require( './fixtures/julia/data.json' ); - - -// VARIABLES // -var mean = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var entropy = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { - 'skip': ( mean instanceof Error ) + 'skip': ( entropy instanceof Error ) }; - -// TESTS // - tape( 'main export is a function', opts, function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof mean, 'function', 'main export is a function' ); + t.strictEqual( typeof entropy, 'function', 'main export is a function' ); t.end(); }); tape( 'if provided an `N` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { - var v; - - v = mean( -2, 4, 2 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - v = mean( -1, 4, 2 ); - t.strictEqual( isnan( v ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `K` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { - var y; - - y = mean( 20, -2, 10 ); - t.strictEqual( isnan( y ), true, 'returns expected value' ); - - y = mean( 20, -1, 10 ); - t.strictEqual( isnan( y ), true, 'returns expected value' ); - - t.end(); -}); - -tape( 'if provided an `n` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { - var y; - - y = mean( 40, 20, -2 ); - t.strictEqual( isnan( y ), true, 'returns expected value' ); - - y = mean( 40, 20, -1 ); - t.strictEqual( isnan( y ), true, 'returns expected value' ); - + var v = entropy( -2, 4, 2 ); + t.strictEqual( isnan( v ), true, 'returns NaN' ); t.end(); }); -tape( 'the function returns the mean of a hypergeometric distribution', opts, function test( t ) { +tape( 'the function returns the entropy', opts, function test( t ) { var expected; var delta; var tol; - var N; - var K; - var n; - var y; - var i; + var v; + + // Case 1: N=2, K=1, n=1 (50/50 chance) + v = entropy( 2, 1, 1 ); + expected = 0.69314718056; + delta = abs( v - expected ); + tol = 1.0e-9; + t.ok( delta < tol, 'within tolerance. v: ' + v + '. expected: ' + expected ); + + // Case 2: N=16, K=11, n=4 + v = entropy( 16, 11, 4 ); + expected = 1.2156868611027067; // Corrected Value + delta = abs( v - expected ); + tol = 1.0e-9; + t.ok( delta < tol, 'within tolerance. v: ' + v + '. expected: ' + expected ); - expected = data.expected; - N = data.N; - K = data.K; - n = data.n; - for ( i = 0; i < n.length; i++ ) { - y = mean( N[i], K[i], n[i] ); - if ( y === expected[i] ) { - t.strictEqual( y, expected[i], 'N: '+N[i]+', K: '+K[i]+', n: '+n[i]+', y: '+y+', expected: '+expected[i] ); - } else { - delta = abs( y - expected[ i ] ); - tol = 1.0 * EPS * abs( expected[ i ] ); - t.ok( delta <= tol, 'within tolerance. N: '+N[i]+'. K: '+K[i]+'. n: '+n[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' ); - } - } t.end(); }); From e60b64d866d08417968bfb95c1fad293e19dd4ae Mon Sep 17 00:00:00 2001 From: Archit Mishra <145186590+24archit@users.noreply.github.com> Date: Sat, 27 Dec 2025 21:58:37 +0530 Subject: [PATCH 04/19] Update documentation for hypergeometric entropy Signed-off-by: Archit Mishra <145186590+24archit@users.noreply.github.com> --- .../stats/base/dists/hypergeometric/entropy/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js index cc5938fc001d..379f61e6bf7a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Hypergeometric distribution expected value. +* Hypergeometric distribution entropy. * * @module @stdlib/stats/base/dists/hypergeometric/entropy * From e71f895d957bf6d76628b6d86bfb40bfd1ec3df5 Mon Sep 17 00:00:00 2001 From: Archit Mishra <145186590+24archit@users.noreply.github.com> Date: Sat, 27 Dec 2025 22:02:23 +0530 Subject: [PATCH 05/19] Add dependencies and update keywords in package.json Signed-off-by: Archit Mishra <145186590+24archit@users.noreply.github.com> --- .../base/dists/hypergeometric/entropy/package.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json index f0c23ecd9d52..2d874a114ff5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json @@ -34,7 +34,14 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": {}, + "dependencies": { + "@stdlib/constants/float64/pinf": "^0.0.x", + "@stdlib/math/base/assert/is-nan": "^0.0.x", + "@stdlib/math/base/assert/is-nonnegative-integer": "^0.0.x", + "@stdlib/math/base/special/ln": "^0.0.x", + "@stdlib/stats/base/dists/hypergeometric/pmf": "^0.0.x", + "@stdlib/stats/incr/sum": "^0.0.x" + }, "devDependencies": {}, "engines": { "node": ">=0.10.0", @@ -61,6 +68,7 @@ "parameter", "discrete", "hypergeometric", - "univariate" + "univariate", + "entropy" ] } From 8c5fbbf943e27fe74e3345beab949ba04775db81 Mon Sep 17 00:00:00 2001 From: Archit Mishra <145186590+24archit@users.noreply.github.com> Date: Sat, 27 Dec 2025 22:12:20 +0530 Subject: [PATCH 06/19] Replace mean function with entropy in benchmark Signed-off-by: Archit Mishra <145186590+24archit@users.noreply.github.com> --- .../base/dists/hypergeometric/entropy/benchmark/benchmark.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js index 4322395bc562..0f3e426d9996 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.js @@ -25,7 +25,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var pkg = require( './../package.json' ).name; -var mean = require( './../lib' ); +var entropy = require( './../lib' ); // MAIN // @@ -50,7 +50,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = mean( N[ i % len ], K[ i % len ], n[ i % len ] ); + y = entropy( N[ i % len ], K[ i % len ], n[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } From 9f014018e79254f4bd7d5ccb87025a2a92af0315 Mon Sep 17 00:00:00 2001 From: Archit Date: Sat, 27 Dec 2025 17:23:30 +0000 Subject: [PATCH 07/19] feat: implementation and docs (wip) --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../entropy/benchmark/benchmark.native.js | 8 ++--- .../entropy/benchmark/c/benchmark.c | 6 ++-- .../docs/img/equation_hypergeometric_mean.svg | 30 ------------------- 3 files changed, 7 insertions(+), 37 deletions(-) delete mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypergeometric_mean.svg diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js index 42ca4ee74ddc..9267aaf69c6d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js @@ -31,9 +31,9 @@ var pkg = require( './../package.json' ).name; // VARIABLES // -var mean = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var entropy = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { - 'skip': ( mean instanceof Error ) + 'skip': ( entropy instanceof Error ) }; @@ -50,7 +50,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { len = 100; N = new Float64Array( len ); K = new Float64Array( len ); - n= new Float64Array( len ); + n = new Float64Array( len ); for ( i = 0; i < len; i++ ) { N[ i ] = discreteUniform( 1, 100 ); K[ i ] = discreteUniform( 1, N[ i ] ); @@ -58,7 +58,7 @@ bench( pkg+'::native', opts, function benchmark( b ) { } b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = mean( N[ i % len ], K[ i % len ], n[ i % len ] ); + y = entropy( N[ i % len ], K[ i % len ], n[ i % len ] ); if ( isnan( y ) ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/benchmark.c index c92bf10fcdc2..ae9b73441779 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/benchmark.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/c/benchmark.c @@ -16,7 +16,7 @@ * limitations under the License. */ -#include "stdlib/stats/base/dists/hypergeometric/mean.h" +#include "stdlib/stats/base/dists/hypergeometric/entropy.h" #include #include #include @@ -24,7 +24,7 @@ #include #include -#define NAME "hypergeometric-mean" +#define NAME "hypergeometric-entropy" #define ITERATIONS 1000000 #define REPEATS 3 @@ -109,7 +109,7 @@ static double benchmark( void ) { t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { - y = stdlib_base_dists_hypergeometric_mean( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); + y = stdlib_base_dists_hypergeometric_entropy( N[ i % 100 ], K[ i % 100 ], n[ i % 100 ] ); if ( y != y ) { printf( "should not return NaN\n" ); break; diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypergeometric_mean.svg b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypergeometric_mean.svg deleted file mode 100644 index 6cfaec4ed66e..000000000000 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypergeometric_mean.svg +++ /dev/null @@ -1,30 +0,0 @@ - -double-struck upper E left-bracket upper X right-bracket equals n StartFraction upper K Over upper N EndFraction - - - \ No newline at end of file From 7fef0d03b197a6db0c5de7df0a3159e4b9c02865 Mon Sep 17 00:00:00 2001 From: Archit Date: Sat, 27 Dec 2025 17:31:31 +0000 Subject: [PATCH 08/19] fix(stats-base-dists-hypergeometric-entropy): resolve benchmark lint warning --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../dists/hypergeometric/entropy/benchmark/benchmark.native.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js index 9267aaf69c6d..24ce5169b513 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/benchmark/benchmark.native.js @@ -26,6 +26,7 @@ var Float64Array = require( '@stdlib/array/float64' ); var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var tryRequire = require( '@stdlib/utils/try-require' ); +var format = require( '@stdlib/string/format' ); var pkg = require( './../package.json' ).name; @@ -39,7 +40,7 @@ var opts = { // MAIN // -bench( pkg+'::native', opts, function benchmark( b ) { +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { var len; var N; var K; From 4eea424096632181331b6e90bcde4325e02dcce6 Mon Sep 17 00:00:00 2001 From: Archit Date: Sat, 27 Dec 2025 17:40:27 +0000 Subject: [PATCH 09/19] fix: add benchmark and example tasks to manifest.json --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../hypergeometric/entropy/manifest.json | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json index f439924789a0..382e476a4eed 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/manifest.json @@ -40,6 +40,32 @@ "dependencies": [ "@stdlib/math/base/napi/ternary" ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] } ] } From c92849823c97502d1a63841dd26f9bd02f7b92d1 Mon Sep 17 00:00:00 2001 From: Archit Date: Sat, 27 Dec 2025 18:15:17 +0000 Subject: [PATCH 10/19] fix(stats/base/dists/hypergeometric/entropy): update examples, types, and docs - Update TypeScript test file to use correct ES module import syntax. - Correct labels in C and JS examples (replaced E(X) with H(X)) and improve input generation logic. - Update Julia fixture runner. --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../entropy/docs/img/equation_entropy.svg | 0 .../hypergeometric/entropy/docs/types/test.ts | 50 +++++++++---------- .../entropy/examples/c/example.c | 10 ++-- .../hypergeometric/entropy/examples/index.js | 10 ++-- .../entropy/test/fixtures/julia/runner.jl | 4 +- 5 files changed, 37 insertions(+), 37 deletions(-) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_entropy.svg diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_entropy.svg b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_entropy.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts index ec4d6137c583..0e2035e085b3 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/types/test.ts @@ -16,43 +16,43 @@ * limitations under the License. */ -import mean = require( './index' ); +import entropy = require( './index' ); // TESTS // // The function returns a number... { - mean( 16, 12, 5 ); // $ExpectType number + entropy( 16, 12, 5 ); // $ExpectType number } // The compiler throws an error if the function is provided values other than three numbers... { - mean( true, 3, 2 ); // $ExpectError - mean( false, 4, 2 ); // $ExpectError - mean( '5', 3, 2 ); // $ExpectError - mean( [], 1, 1 ); // $ExpectError - mean( {}, 2, 1 ); // $ExpectError - mean( ( x: number ): number => x, 2, 1 ); // $ExpectError - - mean( 90, true, 12 ); // $ExpectError - mean( 90, false, 12 ); // $ExpectError - mean( 50, '5', 8 ); // $ExpectError - mean( 80, [], 10 ); // $ExpectError - mean( 90, {}, 12 ); // $ExpectError - mean( 80, ( x: number ): number => x, 12 ); // $ExpectError - - mean( 90, 18, true ); // $ExpectError - mean( 90, 18, false ); // $ExpectError - mean( 50, 10, '5' ); // $ExpectError - mean( 80, 16, [] ); // $ExpectError - mean( 90, 18, {} ); // $ExpectError - mean( 80, 16, ( x: number ): number => x ); // $ExpectError + entropy( true, 3, 2 ); // $ExpectError + entropy( false, 4, 2 ); // $ExpectError + entropy( '5', 3, 2 ); // $ExpectError + entropy( [], 1, 1 ); // $ExpectError + entropy( {}, 2, 1 ); // $ExpectError + entropy( ( x: number ): number => x, 2, 1 ); // $ExpectError + + entropy( 90, true, 12 ); // $ExpectError + entropy( 90, false, 12 ); // $ExpectError + entropy( 50, '5', 8 ); // $ExpectError + entropy( 80, [], 10 ); // $ExpectError + entropy( 90, {}, 12 ); // $ExpectError + entropy( 80, ( x: number ): number => x, 12 ); // $ExpectError + + entropy( 90, 18, true ); // $ExpectError + entropy( 90, 18, false ); // $ExpectError + entropy( 50, 10, '5' ); // $ExpectError + entropy( 80, 16, [] ); // $ExpectError + entropy( 90, 18, {} ); // $ExpectError + entropy( 80, 16, ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided insufficient arguments... { - mean(); // $ExpectError - mean( 30 ); // $ExpectError - mean( 30, 6 ); // $ExpectError + entropy(); // $ExpectError + entropy( 30 ); // $ExpectError + entropy( 30, 6 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/example.c index c4af680314c4..b5e894243424 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/example.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/c/example.c @@ -16,7 +16,7 @@ * limitations under the License. */ -#include "stdlib/stats/base/dists/hypergeometric/mean.h" +#include "stdlib/stats/base/dists/hypergeometric/entropy.h" #include #include #include @@ -34,10 +34,10 @@ int main( void ) { int i; for ( i = 0; i < 10; i++ ) { - N = random_int( 1, 20 ); + N = random_int( 1, 100 ); K = random_int( 0, N ); - n = random_int( 0, K ); - y = stdlib_base_dists_hypergeometric_mean( N, K, n ); - printf( "N: %d, K: %d, n: %d, E(X;N,K,n): %.4f\n", N, K, n, y ); + n = random_int( 0, N ); + y = stdlib_base_dists_hypergeometric_entropy( N, K, n ); + printf( "N: %d, K: %d, n: %d, H(X;N,K,n): %.4f\n", N, K, n, y ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js index 709b11b05778..c5a090c93c96 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/examples/index.js @@ -20,7 +20,7 @@ var randu = require( '@stdlib/random/base/randu' ); var round = require( '@stdlib/math/base/special/round' ); -var mean = require( './../lib' ); +var entropy = require( './../lib' ); var v; var i; @@ -29,9 +29,9 @@ var K; var n; for ( i = 0; i < 10; i++ ) { - N = round( randu() * 20 ); + N = round( randu() * 100 ); K = round( randu() * N ); - n = round( randu() * K ); - v = mean( N, K, n ); - console.log( 'N: %d, K: %d, n: %d, E(X;N,K,n): %d', N, K, n, v.toFixed( 4 ) ); + n = round( randu() * N ); + v = entropy( N, K, n ); + console.log( 'N: %d, K: %d, n: %d, H(X;N,K,n): %d', N, K, n, v.toFixed( 4 ) ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl index 0a7a92ab211b..1890950e1ea6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import Distributions: mean, Hypergeometric +import Distributions: entropy, Hypergeometric import JSON """ @@ -43,7 +43,7 @@ julia> gen( N, K, n, "data.json" ); function gen( N, K, n, name ) z = Array{Float64}( undef, length(N) ); for i in eachindex(N) - z[ i ] = mean( Hypergeometric( K[i], N[i] - K[i], n[i] ) ); + z[ i ] = entropy( Hypergeometric( K[i], N[i] - K[i], n[i] ) ); end # Store data to be written to file as a collection: From ec6929e50bdb451899d179ae487325c19f835e7b Mon Sep 17 00:00:00 2001 From: Archit Date: Sat, 27 Dec 2025 18:43:38 +0000 Subject: [PATCH 11/19] docs(hypergeometric/entropy): add equation SVG --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../entropy/docs/img/equation_entropy.svg | 0 .../img/equation_hypogeometric_entropy.svg | 80 +++++++++++++++++++ 2 files changed, 80 insertions(+) delete mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_entropy.svg create mode 100644 lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypogeometric_entropy.svg diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_entropy.svg b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_entropy.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypogeometric_entropy.svg b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypogeometric_entropy.svg new file mode 100644 index 000000000000..6cfdcb349ad1 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/img/equation_hypogeometric_entropy.svg @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 90972d9550244036c7a55ea7ff183475dbd2b7a7 Mon Sep 17 00:00:00 2001 From: Archit Mishra <145186590+24archit@users.noreply.github.com> Date: Sun, 28 Dec 2025 00:33:18 +0530 Subject: [PATCH 12/19] Update REPL examples for hypergeometric entropy Signed-off-by: Archit Mishra <145186590+24archit@users.noreply.github.com> --- .../stats/base/dists/hypergeometric/entropy/docs/repl.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/repl.txt index dc69409e8e7f..15449e093730 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/repl.txt +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/docs/repl.txt @@ -33,11 +33,11 @@ > v = {{alias}}( 2, 1, 1 ) ~0.693 - > v = {{alias}}( NaN, 10, 5, 2 ) + > v = {{alias}}( NaN, 10, 5 ) NaN - > v = {{alias}}( 20, NaN, 5, 2 ) + > v = {{alias}}( 20, NaN, 5 ) NaN - > v = {{alias}}( 20, 10, NaN, 2 ) + > v = {{alias}}( 20, 10, NaN ) NaN > v = {{alias}}( 10.5, 5, 2 ) From 258bd86e815dcbb61be36d2fc9c968b2097c061d Mon Sep 17 00:00:00 2001 From: Archit Mishra <145186590+24archit@users.noreply.github.com> Date: Sun, 28 Dec 2025 00:50:08 +0530 Subject: [PATCH 13/19] Change parameters of hypergeometric_entropy to double Signed-off-by: Archit Mishra <145186590+24archit@users.noreply.github.com> --- .../dists/hypergeometric/entropy/src/main.c | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c index b3dded5accb3..d8330cbcdab0 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/src/main.c @@ -37,9 +37,25 @@ static double hypergeometric_pmf( int32_t k, int32_t N, int32_t K, int32_t n ) { * @param n number of draws * @return entropy */ -double stdlib_base_dists_hypergeometric_entropy( const int32_t N, const int32_t K, const int32_t n ) { - if ( N < 0 || K < 0 || n < 0 || K > N || n > N ) { - return 0.0/0.0; // NaN +double stdlib_base_dists_hypergeometric_entropy( const double N, const double K, const double n ) { + int32_t N_int; + int32_t K_int; + int32_t n_int; + + if ( isnan( N ) || isnan( K ) || isnan( n ) ) { + return 0.0 / 0.0; // NaN + } + + if ( floor( N ) != N || floor( K ) != K || floor( n ) != n ) { + return 0.0 / 0.0; // NaN + } + + N_int = (int32_t) N; + K_int = (int32_t) K; + n_int = (int32_t) n; + + if ( N_int < 0 || K_int < 0 || n_int < 0 || K_int > N_int || n_int > N_int ) { + return 0.0 / 0.0; // NaN } int32_t min = ( n + K - N > 0 ) ? ( n + K - N ) : 0; From 74479a6230b2c19d03f7a2a3a8eb3528168adbc9 Mon Sep 17 00:00:00 2001 From: Archit Mishra <145186590+24archit@users.noreply.github.com> Date: Sun, 28 Dec 2025 00:56:32 +0530 Subject: [PATCH 14/19] Change hypergeometric_entropy parameters to double Updated the parameter types of the hypergeometric entropy function from int32_t to double. Signed-off-by: Archit Mishra <145186590+24archit@users.noreply.github.com> --- .../include/stdlib/stats/base/dists/hypergeometric/entropy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include/stdlib/stats/base/dists/hypergeometric/entropy.h b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include/stdlib/stats/base/dists/hypergeometric/entropy.h index 1ca033d9412b..46568bd2ba0f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include/stdlib/stats/base/dists/hypergeometric/entropy.h +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/include/stdlib/stats/base/dists/hypergeometric/entropy.h @@ -28,7 +28,7 @@ extern "C" { /** * Returns the entropy of a hypergeometric distribution. */ -double stdlib_base_dists_hypergeometric_entropy( const int32_t N, const int32_t K, const int32_t n ); +double stdlib_base_dists_hypergeometric_entropy( const double N, const double K, const double n ); #ifdef __cplusplus } From 3583b1e05d0396215d35276b86ba6cc772519385 Mon Sep 17 00:00:00 2001 From: Archit Mishra <145186590+24archit@users.noreply.github.com> Date: Sun, 28 Dec 2025 01:07:59 +0530 Subject: [PATCH 15/19] Fix variable 'N' assignment in runner.jl Signed-off-by: Archit Mishra <145186590+24archit@users.noreply.github.com> --- .../dists/hypergeometric/entropy/test/fixtures/julia/runner.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl index 1890950e1ea6..af39153ae635 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/runner.jl @@ -73,5 +73,5 @@ dir = dirname( file ); # Generate fixtures: N = round.( ( rand( 100 ) .* 200 ) .+ 20 ); K = round.( rand( 100 ) .* N ); -n = round.( rand( 100 ) .* K ); +n = round.( rand( 100 ) .* N ); gen( N, K, n, "data.json" ); From 8e55c7fb38f7d9d148394ed515068cf142f6cac5 Mon Sep 17 00:00:00 2001 From: Archit Date: Sat, 27 Dec 2025 19:48:28 +0000 Subject: [PATCH 16/19] fix: updated test fixtures with correct runner and expected values --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../dists/hypergeometric/entropy/test/fixtures/julia/data.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/data.json index b1c6db48482f..b676b26dbe49 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/data.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/fixtures/julia/data.json @@ -1 +1 @@ -{"expected":[1.0756302521008403,26.704545454545453,28.983050847457626,2.4324324324324325,61.25714285714286,26.86315789473684,14.795454545454545,34.5,2.9293478260869565,17.68421052631579,13.538461538461538,7.5,0.011764705882352941,0.0,143.373786407767,19.804878048780488,0.8210526315789474,25.23076923076923,57.6,5.6875,74.16666666666667,18.182926829268293,34.92537313432836,0.18181818181818182,2.234375,6.222222222222222,37.92045454545455,66.45161290322581,13.732394366197184,6.6976744186046515,0.0,19.369127516778523,0.4976958525345622,31.423076923076923,5.714285714285714,15.19047619047619,44.56818181818182,8.32258064516129,3.392857142857143,13.023255813953488,5.47945205479452,106.69626168224299,11.878787878787879,0.16,2.508771929824561,10.458100558659218,0.35294117647058826,0.11428571428571428,53.81725888324873,5.76,16.944444444444443,99.0,4.0,5.078431372549019,31.989637305699482,12.235294117647058,10.54054054054054,1.3928571428571428,55.660377358490564,0.9608938547486033,40.994594594594595,60.07692307692308,147.05825242718447,13.16,3.0,32.28310502283105,0.5357142857142857,5.67816091954023,31.042857142857144,15.422680412371134,0.2898550724637681,7.4,18.76,40.14746543778802,11.088372093023256,17.445454545454545,10.427586206896551,56.77777777777778,126.98019801980197,25.905797101449274,0.0,59.47959183673469,4.583333333333333,0.4444444444444444,0.28,9.526717557251908,109.32057416267942,26.367816091954023,0.13333333333333333,3.5675675675675675,30.23404255319149,25.333333333333332,12.566137566137566,0.18274111675126903,0.1917808219178082,2.857142857142857,8.846153846153847,1.9130434782608696,19.03,4.170731707317073],"N":[119.0,176.0,59.0,37.0,70.0,95.0,88.0,210.0,184.0,209.0,39.0,62.0,85.0,49.0,206.0,205.0,190.0,65.0,150.0,32.0,120.0,164.0,67.0,66.0,64.0,27.0,88.0,124.0,142.0,43.0,25.0,149.0,217.0,130.0,35.0,84.0,176.0,93.0,196.0,129.0,219.0,214.0,165.0,25.0,114.0,179.0,187.0,35.0,197.0,200.0,162.0,121.0,28.0,102.0,193.0,102.0,37.0,112.0,159.0,179.0,185.0,78.0,206.0,200.0,28.0,219.0,28.0,87.0,140.0,97.0,69.0,55.0,150.0,217.0,215.0,110.0,145.0,189.0,202.0,138.0,187.0,196.0,72.0,27.0,50.0,131.0,209.0,87.0,150.0,111.0,188.0,81.0,189.0,197.0,73.0,49.0,78.0,138.0,200.0,164.0],"K":[16.0,100.0,45.0,15.0,67.0,58.0,42.0,161.0,77.0,66.0,24.0,31.0,1.0,1.0,179.0,145.0,52.0,41.0,120.0,26.0,100.0,71.0,60.0,4.0,13.0,14.0,71.0,103.0,65.0,24.0,3.0,74.0,18.0,95.0,20.0,44.0,148.0,86.0,35.0,112.0,48.0,177.0,70.0,2.0,26.0,52.0,11.0,4.0,171.0,128.0,61.0,121.0,16.0,37.0,98.0,39.0,30.0,26.0,150.0,86.0,96.0,71.0,187.0,56.0,12.0,101.0,5.0,26.0,82.0,44.0,10.0,37.0,67.0,132.0,149.0,101.0,63.0,147.0,171.0,65.0,69.0,174.0,66.0,4.0,7.0,39.0,204.0,74.0,5.0,36.0,98.0,76.0,95.0,6.0,7.0,35.0,30.0,24.0,173.0,57.0],"n":[8.0,47.0,38.0,6.0,64.0,44.0,31.0,45.0,7.0,56.0,22.0,15.0,1.0,0.0,165.0,28.0,3.0,40.0,72.0,7.0,89.0,42.0,39.0,3.0,11.0,12.0,47.0,80.0,30.0,12.0,0.0,39.0,6.0,43.0,10.0,29.0,53.0,9.0,19.0,15.0,25.0,129.0,28.0,2.0,11.0,36.0,6.0,1.0,62.0,9.0,45.0,99.0,7.0,14.0,63.0,32.0,13.0,6.0,59.0,2.0,79.0,66.0,162.0,47.0,7.0,70.0,3.0,19.0,53.0,34.0,2.0,11.0,42.0,66.0,16.0,19.0,24.0,73.0,150.0,55.0,0.0,67.0,5.0,3.0,2.0,32.0,112.0,31.0,4.0,11.0,58.0,27.0,25.0,6.0,2.0,4.0,23.0,11.0,22.0,12.0]} +{"expected":[0.9605691359496381,2.36022301542335,2.3109206816828194,2.4475318680028515,2.6715398603555514,1.0558304681057127,2.169949020906224,2.1044232178821045,2.343031681075205,2.0774570789871687,2.6210407891017278,1.5937553893178027,1.5734560450295227,2.4385796506160746,1.9940966299257414,1.5532319642804908,1.5902519548351852,2.406928836025579,1.6548923265006898,2.4705696190862434,1.403449215345543,2.608658529914859,2.024375790087892,0.47413931305783763,2.2802727310640862,1.9208073707839328,1.3438421885395349,-0.0,1.5372057905553902,1.3241503191598174,2.2090976552200146,0.686961576597323,2.1593429557620163,1.4354700698325267,1.6410816884282264,2.6005518275965547,1.4719087465540202,1.7357252896272457,2.3981556931342056,2.3335486982916285,1.9237933952987074,1.9440193472399103,1.6410816884282264,0.5163615681440755,2.3568158257847225,2.155448612252608,1.0155879303656914,2.172551987049449,2.121161362239099,1.8937699212001955,2.048104440725605,2.451969341392494,2.0316242521123753,1.4881393032186538,2.2294844886033247,1.6637392276894984,2.3223583749714787,0.9755195263052014,2.574906644243393,2.1731708164537955,1.3692384347131124,2.4892377688029295,1.470960204844828,1.9226398519238475,2.146432996322684,2.697806403143644,2.533711626595903,1.1423430784435036,1.1672296255371846,1.45958958467898,2.241770941138564,1.8961940398404766,1.5991104043055324,1.3666293292913687,1.6910228477156346,0.9242212350762793,1.8087297960360136,-0.0,2.5864303579974557,2.369551238597645,0.6700089798274271,2.2651406935861207,1.1655067789346878,2.283063240817543,1.0210572481905098,1.7212973816077262,0.6931471805599454,2.141678553423554,1.4620612979243952,2.0416491482535806,2.1631937498973013,2.0186997913780296,1.801108552652871,1.6781553412455192,1.6806338005588422,1.5351944584549344,2.5547559587139057,1.7379832235966675,0.47427179388730223,1.1873052356728573],"N":[199.0,200.0,140.0,158.0,212.0,159.0,92.0,118.0,161.0,113.0,211.0,189.0,111.0,137.0,174.0,42.0,59.0,141.0,46.0,133.0,22.0,187.0,69.0,121.0,109.0,76.0,181.0,104.0,55.0,143.0,83.0,27.0,165.0,38.0,25.0,200.0,73.0,203.0,187.0,207.0,204.0,78.0,25.0,203.0,192.0,107.0,100.0,82.0,184.0,74.0,79.0,162.0,66.0,93.0,215.0,27.0,170.0,198.0,179.0,134.0,37.0,153.0,90.0,44.0,144.0,219.0,163.0,24.0,38.0,30.0,160.0,47.0,44.0,68.0,124.0,66.0,203.0,34.0,199.0,109.0,28.0,123.0,66.0,189.0,55.0,203.0,132.0,116.0,66.0,75.0,106.0,102.0,40.0,183.0,108.0,110.0,156.0,35.0,178.0,121.0],"K":[189.0,169.0,40.0,106.0,135.0,18.0,58.0,41.0,41.0,88.0,148.0,8.0,6.0,50.0,160.0,7.0,10.0,40.0,10.0,64.0,9.0,112.0,37.0,1.0,38.0,38.0,166.0,0.0,21.0,4.0,37.0,12.0,65.0,11.0,13.0,95.0,15.0,186.0,131.0,174.0,182.0,17.0,10.0,202.0,128.0,59.0,9.0,29.0,112.0,23.0,32.0,66.0,47.0,17.0,162.0,17.0,42.0,3.0,118.0,111.0,28.0,86.0,55.0,25.0,51.0,100.0,58.0,21.0,7.0,6.0,68.0,22.0,14.0,4.0,8.0,54.0,193.0,10.0,124.0,46.0,11.0,28.0,3.0,26.0,49.0,36.0,1.0,75.0,19.0,55.0,81.0,59.0,12.0,87.0,12.0,6.0,75.0,22.0,172.0,6.0],"n":[11.0,96.0,99.0,53.0,114.0,153.0,65.0,21.0,114.0,84.0,111.0,49.0,45.0,82.0,100.0,28.0,13.0,71.0,33.0,76.0,5.0,113.0,18.0,99.0,37.0,63.0,167.0,68.0,6.0,48.0,52.0,26.0,144.0,32.0,15.0,139.0,65.0,30.0,44.0,137.0,35.0,24.0,13.0,160.0,156.0,22.0,7.0,32.0,165.0,59.0,60.0,45.0,36.0,84.0,32.0,13.0,126.0,158.0,86.0,51.0,31.0,52.0,5.0,20.0,22.0,84.0,90.0,8.0,33.0,10.0,135.0,15.0,36.0,28.0,45.0,3.0,73.0,0.0,134.0,52.0,1.0,65.0,22.0,92.0,49.0,14.0,66.0,93.0,60.0,28.0,68.0,16.0,21.0,176.0,86.0,72.0,86.0,23.0,5.0,18.0]} From e3a5a3fe7c09373661cfbb3a8bc747f0a40398f4 Mon Sep 17 00:00:00 2001 From: Archit Mishra <145186590+24archit@users.noreply.github.com> Date: Sun, 28 Dec 2025 01:26:57 +0530 Subject: [PATCH 17/19] Enhance tests for hypergeometric entropy function Added tests to validate entropy function against expected results from Julia implementation. Signed-off-by: Archit Mishra <145186590+24archit@users.noreply.github.com> --- .../dists/hypergeometric/entropy/test/test.js | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js index e8c419bff53f..d0dc76563d7d 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.js @@ -23,7 +23,13 @@ var tape = require( 'tape' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var abs = require( '@stdlib/math/base/special/abs' ); -var entropy = require( './../lib' ).default; +var EPS = require( '@stdlib/constants/float64/eps' ); +var entropy = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); // TESTS // @@ -124,6 +130,32 @@ tape( 'the function computes the entropy of a hypergeometric distribution', func t.end(); }); +tape( 'the function matches expected results generated by Julia', function test( t ) { + var expected; + var delta; + var tol; + var v; + var N; + var K; + var n; + var i; + + for ( i = 0; i < data.expected.length; i++ ) { + N = data.N[ i ]; + K = data.K[ i ]; + n = data.n[ i ]; + expected = data.expected[ i ]; + + v = entropy( N, K, n ); + + delta = abs( v - expected ); + tol = 50.0 * EPS; + + t.ok( delta <= tol, 'within tolerance. N: ' + N + '. K: ' + K + '. n: ' + n + '. v: ' + v + '. expected: ' + expected ); + } + t.end(); +}); + tape( 'if the outcome is certain (only one possible value for k), the entropy is 0', function test( t ) { var v; From dbaf11dd460b499a43975467ef5ba24c5878e4f7 Mon Sep 17 00:00:00 2001 From: Archit Mishra <145186590+24archit@users.noreply.github.com> Date: Sun, 28 Dec 2025 01:34:27 +0530 Subject: [PATCH 18/19] Update native tests for hypergeometric entropy function Signed-off-by: Archit Mishra <145186590+24archit@users.noreply.github.com> --- .../entropy/test/test.native.js | 74 +++++++++++++++---- 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js index 5bbdf171ea12..34608042f282 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/test/test.native.js @@ -1,47 +1,95 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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 EPS = require( '@stdlib/constants/float64/eps' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// VARIABLES // var entropy = tryRequire( resolve( __dirname, './../lib/native.js' ) ); var opts = { 'skip': ( entropy instanceof Error ) }; + +// TESTS // + tape( 'main export is a function', opts, function test( t ) { t.ok( true, __filename ); t.strictEqual( typeof entropy, 'function', 'main export is a function' ); t.end(); }); +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { + var v = entropy( NaN, 10, 5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = entropy( 20, NaN, 5 ); + t.equal( isnan( v ), true, 'returns NaN' ); + + v = entropy( 20, 10, NaN ); + t.equal( isnan( v ), true, 'returns NaN' ); + + t.end(); +}); + tape( 'if provided an `N` which is not a nonnegative integer, the function returns `NaN`', opts, function test( t ) { var v = entropy( -2, 4, 2 ); t.strictEqual( isnan( v ), true, 'returns NaN' ); t.end(); }); -tape( 'the function returns the entropy', opts, function test( t ) { +tape( 'the function matches expected results generated by Julia', opts, function test( t ) { var expected; var delta; var tol; var v; + var N; + var K; + var n; + var i; - // Case 1: N=2, K=1, n=1 (50/50 chance) - v = entropy( 2, 1, 1 ); - expected = 0.69314718056; - delta = abs( v - expected ); - tol = 1.0e-9; - t.ok( delta < tol, 'within tolerance. v: ' + v + '. expected: ' + expected ); + for ( i = 0; i < data.expected.length; i++ ) { + N = data.N[ i ]; + K = data.K[ i ]; + n = data.n[ i ]; + expected = data.expected[ i ]; - // Case 2: N=16, K=11, n=4 - v = entropy( 16, 11, 4 ); - expected = 1.2156868611027067; // Corrected Value - delta = abs( v - expected ); - tol = 1.0e-9; - t.ok( delta < tol, 'within tolerance. v: ' + v + '. expected: ' + expected ); + v = entropy( N, K, n ); + + delta = abs( v - expected ); + tol = 50.0 * EPS; + t.ok( delta <= tol, 'within tolerance. N: ' + N + '. K: ' + K + '. n: ' + n + '. v: ' + v + '. expected: ' + expected ); + } t.end(); }); From 6f26850220c819c8f3e4653f7b981f5cff5eefbe Mon Sep 17 00:00:00 2001 From: Archit Date: Sat, 27 Dec 2025 21:45:03 +0000 Subject: [PATCH 19/19] fix: resolved dependencies in entropy --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../stats/base/dists/hypergeometric/entropy/package.json | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json index 2d874a114ff5..e3e959ae16d9 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json +++ b/lib/node_modules/@stdlib/stats/base/dists/hypergeometric/entropy/package.json @@ -34,14 +34,7 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/constants/float64/pinf": "^0.0.x", - "@stdlib/math/base/assert/is-nan": "^0.0.x", - "@stdlib/math/base/assert/is-nonnegative-integer": "^0.0.x", - "@stdlib/math/base/special/ln": "^0.0.x", - "@stdlib/stats/base/dists/hypergeometric/pmf": "^0.0.x", - "@stdlib/stats/incr/sum": "^0.0.x" - }, + "dependencies": {}, "devDependencies": {}, "engines": { "node": ">=0.10.0",