diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/README.md b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/README.md new file mode 100644 index 000000000000..d5b984635352 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/README.md @@ -0,0 +1,257 @@ + + +# Entropy + +> [Log-logistic][log-logistic-distribution] distribution [differential entropy][entropy]. + +
+ +The [differential entropy][entropy] (in [nats][nats]) for a [log-logistic][log-logistic-distribution] random variable with scale `α > 0` and shape `β > 0` is + + + +```math +h\left( X \right) = \ln\left( \frac{\alpha}{\beta} \right) + 2 +``` + + + +
+ + + + + +
+ +## Usage + +```javascript +var entropy = require( '@stdlib/stats/base/dists/log-logistic/entropy' ); +``` + +#### entropy( alpha, beta ) + +Returns the [differential entropy][entropy] of a [log-logistic][log-logistic-distribution] distribution with scale parameter `alpha` and shape parameter `beta`. + +```javascript +var y = entropy( 1.0, 3.0 ); +// returns ~0.901 + +y = entropy( 4.0, 3.0 ); +// returns ~2.288 + +y = entropy( 2.0, 5.0 ); +// returns ~1.084 +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = entropy( NaN, 3.0 ); +// returns NaN + +y = entropy( 1.0, NaN ); +// returns NaN +``` + +If provided `alpha <= 0`, the function returns `NaN`. + +```javascript +var y = entropy( 0.0, 3.0 ); +// returns NaN + +y = entropy( -1.0, 3.0 ); +// returns NaN +``` + +If provided `beta <= 0`, the function returns `NaN`. + +```javascript +var y = entropy( 2.0, 0.0 ); +// returns NaN + +y = entropy( 2.0, -1.0 ); +// returns NaN +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var entropy = require( '@stdlib/stats/base/dists/log-logistic/entropy' ); + +var opts = { + 'dtype': 'float64' +}; +var alpha = uniform( 10, 0.1, 10.0, opts ); +var beta = uniform( 10, 0.1, 10.0, opts ); + +logEachMap( 'α: %0.4f, β: %0.4f, h(X;α,β): %0.4f', alpha, beta, entropy ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/log-logistic/entropy.h" +``` + +#### stdlib_base_dists_log_logistic_entropy( alpha, beta ) + +Returns the differential entropy of a log-logistic distribution with scale parameter `alpha` and shape parameter `beta`. + +```c +double out = stdlib_base_dists_log_logistic_entropy( 1.0, 3.0 ); +// returns ~0.901 +``` + +The function accepts the following arguments: + +- **alpha**: `[in] double` scale parameter. +- **beta**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_log_logistic_entropy( const double alpha, const double beta ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/log-logistic/entropy.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double alpha; + double beta; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + alpha = random_uniform( 0.1, 10.0 ); + beta = random_uniform( 0.1, 10.0 ); + y = stdlib_base_dists_log_logistic_entropy( alpha, beta ); + printf( "α: %lf, β: %lf, h(X;α,β): %lf\n", alpha, beta, y ); + } +} +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/benchmark.js new file mode 100644 index 000000000000..dc46375bd918 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/benchmark.js @@ -0,0 +1,59 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var pkg = require( './../package.json' ).name; +var entropy = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var alpha; + var beta; + var opts; + var y; + var i; + + opts = { + 'dtype': 'float64' + }; + alpha = uniform( 100, EPS, 10.0, opts ); + beta = uniform( 100, EPS, 10.0, opts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = entropy( alpha[ i % alpha.length ], beta[ i % beta.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/benchmark.native.js new file mode 100644 index 000000000000..bbc9cf718cda --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/benchmark.native.js @@ -0,0 +1,69 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var entropy = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( entropy instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var arrayOpts; + var alpha; + var beta; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + alpha = uniform( 100, EPS, 10.0, arrayOpts ); + beta = uniform( 100, EPS, 10.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = entropy( alpha[ i % alpha.length ], beta[ i % beta.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/c/benchmark.c new file mode 100644 index 000000000000..e7a07ceceb4f --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/benchmark/c/benchmark.c @@ -0,0 +1,140 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/log-logistic/entropy.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "log-logistic-entropy" +#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 ); + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double alpha[ 100 ]; + double beta[ 100 ]; + double elapsed; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + alpha[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + beta[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_log_logistic_entropy( alpha[ i % 100 ], beta[ 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; + + 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/log-logistic/entropy/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/docs/repl.txt new file mode 100644 index 000000000000..1b378bff0aea --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/docs/repl.txt @@ -0,0 +1,42 @@ + +{{alias}}( α, β ) + Returns the differential entropy of a log-logistic distribution with scale + parameter `α` and shape parameter `β` (in nats). + + If provided `NaN` as any argument, the function returns `NaN`. + + If provided `α <= 0`, the function returns `NaN`. + + If provided `β <= 0`, the function returns `NaN`. + + Parameters + ---------- + α: number + Scale parameter. + + β: number + Shape parameter. + + Returns + ------- + out: number + Differential entropy. + + Examples + -------- + > var y = {{alias}}( 1.0, 3.0 ) + ~0.901 + > y = {{alias}}( 4.0, 3.0 ) + ~2.288 + > y = {{alias}}( NaN, 3.0 ) + NaN + > y = {{alias}}( 2.0, NaN ) + NaN + > y = {{alias}}( -1.0, 3.0 ) + NaN + > y = {{alias}}( 2.0, -1.0 ) + NaN + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/docs/types/index.d.ts new file mode 100644 index 000000000000..dc57a3888530 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/docs/types/index.d.ts @@ -0,0 +1,62 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Returns the differential entropy of a log-logistic distribution with scale parameter `alpha` and shape parameter `beta`. +* +* ## Notes +* +* - If provided `alpha <= 0`, the function returns `NaN`. +* - If provided `beta <= 0`, the function returns `NaN`. +* +* @param alpha - scale parameter +* @param beta - shape parameter +* @returns entropy +* +* @example +* var y = entropy( 1.0, 3.0 ); +* // returns ~0.901 +* +* @example +* var y = entropy( 4.0, 3.0 ); +* // returns ~2.288 +* +* @example +* var y = entropy( NaN, 3.0 ); +* // returns NaN +* +* @example +* var y = entropy( 2.0, NaN ); +* // returns NaN +* +* @example +* var y = entropy( -1.0, 3.0 ); +* // returns NaN +* +* @example +* var y = entropy( 2.0, -1.0 ); +* // returns NaN +*/ +declare function entropy( alpha: number, beta: number ): number; + + +// EXPORTS // + +export = entropy; diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/docs/types/test.ts new file mode 100644 index 000000000000..920bf6db9ded --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/docs/types/test.ts @@ -0,0 +1,56 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import entropy = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + entropy( 1.0, 3.0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than two numbers... +{ + entropy( true, 3 ); // $ExpectError + entropy( false, 2 ); // $ExpectError + entropy( '5', 1 ); // $ExpectError + entropy( [], 1 ); // $ExpectError + entropy( {}, 2 ); // $ExpectError + entropy( ( x: number ): number => x, 2 ); // $ExpectError + + entropy( 9, true ); // $ExpectError + entropy( 9, false ); // $ExpectError + entropy( 5, '5' ); // $ExpectError + entropy( 8, [] ); // $ExpectError + entropy( 9, {} ); // $ExpectError + entropy( 8, ( x: number ): number => x ); // $ExpectError + + entropy( [], true ); // $ExpectError + entropy( {}, false ); // $ExpectError + entropy( false, '5' ); // $ExpectError + entropy( {}, [] ); // $ExpectError + entropy( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + entropy(); // $ExpectError + entropy( 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/examples/c/example.c new file mode 100644 index 000000000000..373c1d563bcb --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/examples/c/example.c @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/log-logistic/entropy.h" +#include +#include + +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +int main( void ) { + double alpha; + double beta; + double y; + int i; + + for ( i = 0; i < 25; i++ ) { + alpha = random_uniform( 0.1, 10.0 ); + beta = random_uniform( 0.1, 10.0 ); + y = stdlib_base_dists_log_logistic_entropy( alpha, beta ); + printf( "α: %lf, β: %lf, h(X;α,β): %lf\n", alpha, beta, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/examples/index.js new file mode 100644 index 000000000000..8b861ce0e3da --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/examples/index.js @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var entropy = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var alpha = uniform( 10, 0.1, 10.0, opts ); +var beta = uniform( 10, 0.1, 10.0, opts ); + +logEachMap( 'α: %0.4f, β: %0.4f, h(X;α,β): %0.4f', alpha, beta, entropy ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + '=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "dist", + "entropy", + "shannon", + "information", + "continuous", + "log-logistic", + "univariate" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/src/Makefile new file mode 100644 index 000000000000..262dc98fcfa0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/src/Makefile @@ -0,0 +1,68 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# 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/log-logistic/entropy/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/src/addon.c new file mode 100644 index 000000000000..b38bf62d094b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/src/addon.c @@ -0,0 +1,22 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/log-logistic/entropy.h" +#include "stdlib/math/base/napi/binary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_log_logistic_entropy ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/src/main.c new file mode 100644 index 000000000000..ea423526abfe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/src/main.c @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include "stdlib/stats/base/dists/log-logistic/entropy.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/ln.h" + +/** +* Returns the differential entropy of a log-logistic distribution with scale parameter `alpha` and shape parameter `beta`. +* +* @param alpha scale parameter +* @param beta shape parameter +* @return entropy +* +* @example +* double y = stdlib_base_dists_log_logistic_entropy( 1.0, 3.0 ); +* // returns ~0.901 +*/ +double stdlib_base_dists_log_logistic_entropy( const double alpha, const double beta ) { + if ( + stdlib_base_is_nan( alpha ) || + stdlib_base_is_nan( beta ) || + alpha <= 0.0 || + beta <= 0.0 + ) { + return 0.0 / 0.0; // NaN + } + return stdlib_base_ln( alpha / beta ) + 2.0; +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/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/log-logistic/entropy/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/fixtures/julia/data.json new file mode 100644 index 000000000000..a99519a44159 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"alpha":[0.397,1.09,1.7830000000000001,2.4760000000000004,3.169,3.862,4.555,5.248,5.941,6.634,7.327,8.02,8.713,9.406,0.199,0.892,1.5850000000000002,2.278,2.971,3.664,4.357,5.05,5.743,6.436,7.129,7.822,8.515,9.208,9.901,0.6940000000000001,1.3870000000000002,2.08,2.773,3.466,4.159,4.852,5.545,6.2379999999999995,6.931,7.624,8.317,9.01,9.703,0.496,1.189,1.8820000000000001,2.575,3.2680000000000002,3.9610000000000003,4.654,5.3469999999999995,6.04,6.733,7.426,8.119,8.812,9.505,0.29800000000000004,0.991,1.6840000000000002,2.3770000000000002,3.0700000000000003,3.7630000000000003,4.4559999999999995,5.149,5.842,6.535,7.228,7.921,8.614,9.307,0.1,0.793,1.4860000000000002,2.1790000000000003,2.8720000000000003,3.5650000000000004,4.258,4.951,5.644,6.337,7.03,7.723,8.416,9.109,9.802,0.595,1.2880000000000003,1.981,2.6740000000000004,3.3670000000000004,4.06,4.753,5.446,6.139,6.832,7.525,8.218,8.911,9.604000000000001],"beta":[0.595,1.8820000000000001,3.169,4.4559999999999995,5.743,7.03,8.317,9.604000000000001,0.991,2.278,3.5650000000000004,4.852,6.139,7.426,8.713,0.1,1.3870000000000002,2.6740000000000004,3.9610000000000003,5.248,6.535,7.822,9.109,0.496,1.7830000000000001,3.0700000000000003,4.357,5.644,6.931,8.218,9.505,0.892,2.1790000000000003,3.466,4.753,6.04,7.327,8.614,9.901,1.2880000000000003,2.575,3.862,5.149,6.436,7.723,9.01,0.397,1.6840000000000002,2.971,4.258,5.545,6.832,8.119,9.406,0.793,2.08,3.3670000000000004,4.654,5.941,7.228,8.515,9.802,1.189,2.4760000000000004,3.7630000000000003,5.05,6.337,7.624,8.911,0.29800000000000004,1.5850000000000002,2.8720000000000003,4.159,5.446,6.733,8.02,9.307,0.6940000000000001,1.981,3.2680000000000002,4.555,5.842,7.129,8.416,9.703,1.09,2.3770000000000002,3.664,4.951,6.2379999999999995,7.525,8.812,0.199,1.4860000000000002,2.773,4.06,5.3469999999999995,6.634,7.921,9.208],"expected":[1.5953748751415606,1.4538426550778643,1.4248812581722197,1.412392852197367,1.405434358826624,1.4009984781837492,1.397923917825371,1.3956673732827811,3.7909182140257536,3.06891007549987,2.7204021013115676,2.5025474307966196,2.35015430080379,2.236360427767968,-1.7792666175067944,4.188295946591918,2.133441265996549,1.8397223863452388,1.712402077840691,1.6407083951700958,1.5946114000591198,1.562447966953946,1.5387187861194866,4.5630865813873465,3.385873633254488,2.9352627147342165,2.6700455669793466,2.489479637429014,2.35663165920453,-0.4716101889365505,0.07532516539230216,2.846657040115354,2.241063710671158,2,1.8664986631289022,1.78098697913508,1.7213304656245036,1.6772708315536926,1.64336834079547,3.7782105386697387,3.172452078770851,2.8471498876139236,2.633632594979158,-0.5630865813873465,0.1289097281215179,0.4339999695429415,3.869668532410646,2.6630062611776215,2.287597922159309,2.0889274984088124,1.963639035164264,1.8767865554604548,1.8128138156828344,1.7636395722320322,4.326139051227599,3.44374653522687,3.0377958357614547,-0.7483888573568325,0.20908178597424665,0.5432095430901531,0.7240098742634054,0.8390911151117502,3.1521038939026553,2.587607147802633,2.313586009452704,2.1456849606782806,2.0307668767348055,1.946661206378081,1.8822309918515598,5.3640505791086515,3.770182397874329,-1.3575937441800234,0.34279328189193636,0.7012065520439998,0.8718452463993391,0.9730702293075548,1.0403972486626858,3.81408288494662,2.915987808662872,2.546414856992811,2.330179939629458,2.1851135018570242,2.0800319174516355,2,1.9368278197195103,4.196408750246303,0.6149669381854357,0.9545351808702782,1.084012191337128,1.15291586049414,1.1957913295439981,1.2250685446735448,5.1732264518895175,3.298793447956,2.7947320958117183,2.5204344828726275,2.341695154668345,2.2141189299363573,2.11776900814844,2.0421070069394256]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..79c4c7e50403 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/fixtures/julia/runner.jl @@ -0,0 +1,72 @@ +#!/usr/bin/env julia +# +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import Distributions: entropy, LogLogistic +import JSON + +""" + gen( alpha, beta, name ) + +Generate fixture data and write to file. + +# Arguments + +* `alpha`: scale parameter +* `beta`: shape parameter +* `name::AbstractString`: output filename + +# Examples +``` julia +julia> alpha = rand( 1000 ) .* 10.0 .+ 0.1; +julia> beta = rand( 1000 ) .* 10.0 .+ 0.1; +julia> gen( alpha, beta, "data.json" ); +``` +""" +function gen( alpha, beta, name ) + z = Array{Float64}( undef, length(alpha) ); + for i in eachindex(alpha) + z[ i ] = entropy( LogLogistic( alpha[i], beta[i] ) ); + end + + # Store data to be written to file as a collection: + data = Dict([ + ("alpha", alpha), + ("beta", beta), + ("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: +alpha = ( rand( 1000 ) .* 10.0 ) .+ 0.1; +beta = ( rand( 1000 ) .* 10.0 ) .+ 0.1; +gen( alpha, beta, "data.json" ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/test.js new file mode 100644 index 000000000000..f1885834aad6 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/test.js @@ -0,0 +1,106 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); +var entropy = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof entropy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = entropy( NaN, 3.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = entropy( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `alpha`, the function returns `NaN`', function test( t ) { + var y; + + y = entropy( 0.0, 3.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( -1.0, 3.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( NINF, 3.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a nonpositive `beta`, the function returns `NaN`', function test( t ) { + var y; + + y = entropy( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the differential entropy of a log-logistic distribution', function test( t ) { + var expected; + var alpha; + var beta; + var y; + var i; + + expected = data.expected; + alpha = data.alpha; + beta = data.beta; + for ( i = 0; i < alpha.length; i++ ) { + y = entropy( alpha[ i ], beta[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/test.native.js new file mode 100644 index 000000000000..4d115d97ae46 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/log-logistic/entropy/test/test.native.js @@ -0,0 +1,115 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); + + +// VARIABLES // + +var entropy = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( entropy instanceof Error ) +}; + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// 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 y = entropy( NaN, 3.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = entropy( 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `alpha`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = entropy( 0.0, 3.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( -1.0, 3.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( NINF, 3.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a nonpositive `beta`, the function returns `NaN`', opts, function test( t ) { + var y; + + y = entropy( 2.0, 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( 2.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( 1.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = entropy( NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the differential entropy of a log-logistic distribution', opts, function test( t ) { + var expected; + var alpha; + var beta; + var y; + var i; + + expected = data.expected; + alpha = data.alpha; + beta = data.beta; + for ( i = 0; i < alpha.length; i++ ) { + y = entropy( alpha[ i ], beta[ i ] ); + t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' ); + } + t.end(); +});