From 1f326e79ba8d2b50b8b4e13a8c45129b126358fc Mon Sep 17 00:00:00 2001 From: Neeraj Date: Mon, 3 Aug 2026 13:15:23 +0530 Subject: [PATCH 1/4] feat: add stats/base/dists/wald/logcdf --- 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_pkg_readmes status: na - task: lint_markdown_docs status: na - 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 --- --- .../wald/logcdf/test/fixtures/julia/REQUIRE | 3 + .../wald/logcdf/test/fixtures/julia/data.json | 1 + .../wald/logcdf/test/fixtures/julia/runner.jl | 78 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/REQUIRE create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/REQUIRE b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/REQUIRE new file mode 100644 index 000000000000..98be20b58ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/REQUIRE @@ -0,0 +1,3 @@ +Distributions 0.23.8 +julia 1.5 +JSON 0.21 diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json new file mode 100644 index 000000000000..e39ea0fbdc54 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json @@ -0,0 +1 @@ +{"expected":[-0.7677471309208188,-0.2787086340220627,0.0,-0.29186588079971265,-0.1914971235172907,-0.12731826437327878,-0.0610086784073224,-0.19028425707461988,-0.42681525205624893,-0.27244540801438005,-0.21251158404533438,-7.845946115029059e-13,-0.03849048984358715,-0.39578618408422156,-0.1898310436301173,-0.1318845431741165,-0.40646684018544416,-0.3032891917840776,-0.055637733176745294,-8.455943621096414e-7,-0.343219796523212,-0.30141601654141464,-0.10333296295995086,-0.05455642821892258,-0.04690587719185412,-1.2720808052052244,-0.0796962282143258,-0.47193573066608335,-0.4134530021156068,-0.11314697005967272,-0.03216471247353266,-0.020954752134945673,-0.015599520523660508,-0.022494116512983355,-0.4180621901857225,-0.18835293326522334,-0.16834635837723289,-0.3472847724996076,-0.24962076409812362,-0.08246932615110435,-0.128564918241411,-0.5020499338920977,-0.29038754396175376,-0.31169717833873184,-0.06904784684357243,-0.41970306762870274,-0.13612005685448972,-0.007271828416049349,-0.00015796160625364324,-0.3311220546908127,-0.11981911864755566,-0.13022790414103966,-0.0653217646127126,-4.003896732022639e-5,-0.4620331299491943,-0.0003188154680565489,-0.38204564060956536,-0.8363929373195002,-0.9756308487481092,-4.9411845947719495e-8,-0.07582593148795107,-0.11930444004258285,-0.0668266210026477,-0.30539528705537283,-0.08481174372338386,-0.4053973718067023,-0.0006811817874303994,-0.15181102110853595,-1.1102230246251571e-15,-0.23894111947821683,-0.4055153021544522,-0.5295901072426727,-0.7862467843532569,-0.23625035118551335,-0.7486181436475855,-0.2265031845816536,-0.23736214416237184,-2.734723628742852e-5,-7.799821085523022e-7,-1.9762834684280597,-0.17720845862335044,-1.6047335064319812,-0.06880222614093277,-1.4355755358673525,-0.6239490729338388,-0.44181840911139736,-0.004426075765944797,-0.7023753511957961,-9.821689340075041e-7,-0.16860071469676394,-3.60587923479994e-6,-0.3160273270864338,-0.3911833228365226,-0.006534973023468772,-0.2151583507497586,-0.21306433776438144,-0.4856215167778689,-1.0184441802713948,-0.01465861472109714,-0.44445041735898383],"lambda":[3.4182949858077,0.9845087298645656,5.465527946273955,2.5987593899852373,1.9216955103800584,4.579307057884379,1.1343018721139326,2.849717984377608,3.2133430829381417,0.9625108956354124,3.371665659695282,2.805442223488767,4.44468565429758,4.433179917864226,2.576160379504697,2.8223135910564094,1.2429981405376247,4.0473949070773045,1.1047542930351129,5.051094499713389,1.3111616354411055,2.4791400567783675,1.9453897196172838,2.127033864180355,0.7435161144635856,5.089596050430019,0.7752557258865956,4.691790733935846,4.281872205292993,0.5634391957954256,5.132801344678098,3.29014221448661,4.448297918820132,2.195027101153086,2.688822324137505,2.765846447298146,4.354168793562432,1.0658269785567476,2.178053638839283,2.4465233576499212,1.0990075318128263,3.228971380463501,4.1765257232579,2.0902869722580726,5.045447362285321,4.047817024997428,2.2199700297012663,3.2203653321442385,2.763466252624867,2.1367585182007534,2.4745642757442203,4.858879927127423,0.9078811141958649,3.6810595480822585,0.8716694632316103,4.085871270710637,4.709679246255085,1.1092181441653954,4.733287410506161,1.1788727460919293,3.540469013320017,3.8588567647538903,1.0619959125897238,0.8854344423505351,1.8389559714572234,4.6743120740445345,2.3544039623848314,1.1756405668437453,3.9509919918045346,0.7575567061807799,1.1668854923906204,0.8918320819250132,4.696797384360636,5.2324232762413505,5.2506265556158125,5.389614103339855,1.3940498868748703,1.2958007081806506,3.0941573004056924,3.9362339077236843,0.708912296787423,2.4916859851471442,3.7517927984576716,3.7068430245034776,3.583063243333941,3.7601678800755503,5.1289404412236514,2.4361888788779726,4.833015774842675,1.4828963428654718,3.7508439675908103,2.278758223315224,3.457467368389411,5.234726366211575,5.231852707886034,3.696323350359666,2.5707934765856386,2.576901884357016,4.49598988830824,0.7690569644559482],"mu":[3.8160297895874224,5.415908329124594,0.5098294457677306,8.665746474677183,10.490841684140882,7.1991516914171445,4.032161592390338,9.070624432050852,8.95913754370084,10.146402603476993,10.3407887338936,0.6393188110327748,3.145518185330049,9.616540905114231,8.967259935062401,5.443979290251943,8.29334647693589,8.09163507594657,3.9833185116217127,1.7374280764998846,10.452407505971397,3.8370171293839834,4.809014301721888,1.4821914990086722,3.3320938535172333,1.639139987037665,2.076902173790744,7.2304256442179655,2.412671924751886,4.255038874649795,4.277911019408543,0.812347895555013,3.5602582965202876,3.067131107032048,5.704614939345904,6.508542890761502,6.385499153243318,5.455690900264028,8.28023740277153,0.5799358125122351,7.512617541092614,8.748534915987456,7.756998715695716,10.23885645518659,3.995320845136445,6.490540061067665,6.785084839722879,2.8691921705940233,1.752709849172211,7.161709560199388,5.790151123415305,4.565825012287347,3.3744926752138635,1.3665683138289182,3.816929208869981,1.369492173041193,5.378418315644382,7.906194742649857,9.504535724332658,0.7024185800711331,2.9638803445504376,6.645498718228065,4.1742419240277355,3.4434500311712366,2.2486516607363467,9.609355017691701,1.6218297864010573,7.8910398111913835,0.9104660748344702,9.6503359649901,2.4004774221277865,6.356006929162634,7.4573009069662035,5.36451840194582,9.623368354860267,8.098812331662867,10.192812496623592,0.5020784910025795,1.351259073741264,7.433207181952219,6.113145747998349,6.602175262408755,5.426094194351745,8.691377983453759,8.123292392337401,5.377197644699508,3.031751898527508,5.176441314240477,1.2760245361187845,10.008952169986545,1.6231979378457735,7.677283728015991,5.00564795025744,2.255467934246715,4.465342050489921,9.362791987802348,5.264922150484514,3.403574128136217,3.373899777469633,7.00522245725154],"x":[2.2886880843138413,4.661388669370461,15.164537825110578,8.580338485008458,13.73915494763048,14.78806163179938,14.565318272075649,13.568291100825938,6.465840749368759,6.392777340057905,14.114190165765205,7.952657002508393,9.114945824077552,8.161810069690503,13.23329832865447,11.083797993173047,4.072572698806404,8.847293054194239,15.332814992757871,15.091450707842013,5.733962582801725,4.414253408195529,11.692845103537817,3.8068812632230715,14.916144031773209,1.0340519826411827,6.049544567572894,5.834829491402029,2.541050075694834,8.926839111319834,13.913346183645592,1.8991106264926323,14.162118502537885,13.7975473492501,4.63823867808127,10.206891349779566,11.007962728402008,3.7602702308618947,9.201457611508358,1.007840623581448,14.103987083350495,5.415650665670313,8.913242428108818,8.161362544753588,9.752927151712433,5.710525221039752,13.502196663522962,14.673184141520277,14.337243800801662,6.233993636353876,12.681184607155295,8.758226788742023,11.701801914149112,9.061904964813463,2.041727696636957,6.809354705327678,5.464970651498978,1.4324613631118366,3.44743466072849,11.453329627931085,7.069475744432183,14.31014936889021,14.333518753828798,3.085512672342392,5.547598155269018,8.114922860121514,11.372559054774827,12.47228776059942,14.081165874504084,6.484826227477347,2.0262069868905974,2.1184974441980264,3.783768749367585,7.5108876362044645,4.783809857133653,11.478873751152472,9.330246900115748,3.557435343536315,14.1381728603775,1.3212892380120955,7.414683128332771,1.1483921882614285,15.3653829284134,1.8773257335438212,4.372427980998328,4.673844934708131,13.958932918188475,2.5509970305581966,9.055487743895595,14.077839259589743,14.935055984159352,6.994637543926216,4.775892906574661,8.219044669142614,6.58180954850306,13.171497792989001,3.7732884595245677,1.482575506652672,13.263404058135288,2.4905187691408806]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl new file mode 100644 index 000000000000..8abdaad6220e --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl @@ -0,0 +1,78 @@ +#!/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: log, cdf, InverseGaussian +import JSON + +""" + gen( x, mu, lambda, name ) + +Generate fixture data and write to file. + +# Arguments + +* `x`: input value +* `mu`: mean +* `lambda`: shape parameter +* `name::AbstractString`: output filename + +# Examples + +``` julia +julia> x = rand( 100 ) .* 15.0 .+ 0.5; +julia> mu = rand( 100 ) .* 10.0 .+ 0.5; +julia> lambda = rand( 100 ) .* 5.0 .+ 0.5; +julia> gen( x, mu, lambda, "data.json" ); +``` +""" +function gen( x, mu, lambda, name ) + z = Array{Float64}( undef, length(x) ); + for i in eachindex(x) + z[ i ] = log( cdf( InverseGaussian( mu[i], lambda[i] ), x[i] ) ); + end + + # Store data to be written to file as a collection: + data = Dict([ + ("x", x), + ("mu", mu), + ("lambda", lambda), + ("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: +x = rand( 100 ) .* 15.0 .+ 0.5; +mu = rand( 100 ) .* 10.0 .+ 0.5; +lambda = rand( 100 ) .* 5.0 .+ 0.5; +gen( x, mu, lambda, "data.json" ); + From 931ffdd8c16d50acccaff89e8e48a5d6addf8930 Mon Sep 17 00:00:00 2001 From: Neeraj Date: Mon, 3 Aug 2026 13:18:39 +0530 Subject: [PATCH 2/4] feat: add stats/base/dists/wald/logcdf --- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - 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 --- --- .../stats/base/dists/wald/logcdf/README.md | 279 ++++++++++++++++++ .../dists/wald/logcdf/benchmark/benchmark.js | 90 ++++++ .../wald/logcdf/benchmark/benchmark.native.js | 71 +++++ .../dists/wald/logcdf/benchmark/c/Makefile | 146 +++++++++ .../dists/wald/logcdf/benchmark/c/benchmark.c | 143 +++++++++ .../stats/base/dists/wald/logcdf/binding.gyp | 170 +++++++++++ .../base/dists/wald/logcdf/docs/repl.txt | 83 ++++++ .../dists/wald/logcdf/docs/types/index.d.ts | 121 ++++++++ .../base/dists/wald/logcdf/docs/types/test.ts | 119 ++++++++ .../dists/wald/logcdf/examples/c/Makefile | 146 +++++++++ .../dists/wald/logcdf/examples/c/example.c | 44 +++ .../base/dists/wald/logcdf/examples/index.js | 33 +++ .../stats/base/dists/wald/logcdf/include.gypi | 53 ++++ .../stdlib/stats/base/dists/wald/logcdf.h | 38 +++ .../base/dists/wald/logcdf/lib/factory.js | 109 +++++++ .../stats/base/dists/wald/logcdf/lib/index.js | 51 ++++ .../stats/base/dists/wald/logcdf/lib/main.js | 122 ++++++++ .../base/dists/wald/logcdf/lib/native.js | 83 ++++++ .../base/dists/wald/logcdf/manifest.json | 99 +++++++ .../stats/base/dists/wald/logcdf/package.json | 73 +++++ .../stats/base/dists/wald/logcdf/src/Makefile | 70 +++++ .../stats/base/dists/wald/logcdf/src/addon.c | 22 ++ .../stats/base/dists/wald/logcdf/src/main.c | 76 +++++ .../dists/wald/logcdf/test/test.factory.js | 198 +++++++++++++ .../stats/base/dists/wald/logcdf/test/test.js | 38 +++ .../base/dists/wald/logcdf/test/test.main.js | 149 ++++++++++ .../dists/wald/logcdf/test/test.native.js | 158 ++++++++++ 27 files changed, 2784 insertions(+) create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/benchmark.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/binding.gyp create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/example.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/include.gypi create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/include/stdlib/stats/base/dists/wald/logcdf.h create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/factory.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/native.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/package.json create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/Makefile create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/addon.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js create mode 100644 lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md new file mode 100644 index 000000000000..a7825426cc74 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md @@ -0,0 +1,279 @@ + + +# Logarithm of Cumulative Distribution Function + +> [Wald][wald-distribution] distribution logarithm of [cumulative distribution function][cdf]. + +
+ +The [cumulative distribution function][cdf] for a [Wald][wald-distribution] random variable is + + + +```math +F(x;\mu,\lambda) = \Phi\!\left(\sqrt{\frac{\lambda}{x}}\left(\frac{x}{\mu}-1\right)\right) + \exp\!\left(\frac{2\lambda}{\mu}\right)\,\Phi\!\left(-\sqrt{\frac{\lambda}{x}}\left(\frac{x}{\mu}+1\right)\right) +``` + + + +where `μ > 0` is the mean and `λ > 0` is the shape parameter. + +
+ + + +
+ +## Usage + +```javascript +var logcdf = require( '@stdlib/stats/base/dists/wald/logcdf' ); +``` + +#### logcdf( x, mu, lambda ) + +Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```javascript +var y = logcdf( 2.0, 2.0, 1.0 ); +// returns ~-0.337 + +y = logcdf( 1.0, 2.0, 1.0 ); +// returns ~-0.713 + +y = logcdf( 4.0, 2.0, 1.0 ); +// returns ~-0.136 +``` + +If provided `NaN` as any argument, the function returns `NaN`. + +```javascript +var y = logcdf( NaN, 2.0, 1.0 ); +// returns NaN + +y = logcdf( 2.0, NaN, 1.0 ); +// returns NaN + +y = logcdf( 2.0, 2.0, NaN ); +// returns NaN +``` + +If provided `mu <= 0` or `lambda < 0`, the function returns `NaN`. + +```javascript +var y = logcdf( 2.0, 0.0, -3.0 ); +// returns NaN + +y = logcdf( 2.0, -1.0, -2.0 ); +// returns NaN + +y = logcdf( 2.0, -2.0, -1.0 ); +// returns NaN +``` + +If provided `x <= 0`, the function returns `-Infinity`. + +```javascript +var y = logcdf( 0.0, 2.0, 1.0 ); +// returns -Infinity + +y = logcdf( -1.0, 2.0, 1.0 ); +// returns -Infinity +``` + +If `lambda = 0`, the function evaluates the logarithm of the [CDF][cdf] of a [degenerate distribution][degenerate-distribution] centered at `mu`. + +```javascript +var y = logcdf( 2.0, 8.0, 0.0 ); +// returns -Infinity + +y = logcdf( 8.0, 8.0, 0.0 ); +// returns 0.0 + +y = logcdf( 10.0, 8.0, 0.0 ); +// returns 0.0 +``` + +#### logcdf.factory( mu, lambda ) + +Returns a function for evaluating the natural logarithm of the [cumulative distribution function][cdf] of a [Wald][wald-distribution] distribution with parameters `mu` and `lambda`. + +```javascript +var mylogcdf = logcdf.factory( 1.0, 1.0 ); + +var y = mylogcdf( 2.0 ); +// returns ~-0.122 + +y = mylogcdf( 8.0 ); +// returns ~-0.001 +``` + +
+ + + +
+ +## Examples + + + +```javascript +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var logcdf = require( '@stdlib/stats/base/dists/wald/logcdf' ); + +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 10, EPS, 10.0, opts ); +var mu = uniform( 10, EPS, 10.0, opts ); +var lambda = uniform( 10, EPS, 20.0, opts ); + +logEachMap( 'x: %0.4f, μ: %0.4f, λ: %0.4f, ln(F(x;μ,λ)): %0.4f', x, mu, lambda, logcdf ); +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/stats/base/dists/wald/logcdf.h" +``` + +#### stdlib_base_dists_wald_logcdf( x, mu, lambda ) + +Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter). + +```c +double out = stdlib_base_dists_wald_logcdf( 2.0, 1.0, 1.0 ); +// returns ~-0.122 +``` + +The function accepts the following arguments: + +- **x**: `[in] double` input value. +- **mu**: `[in] double` mean. +- **lambda**: `[in] double` shape parameter. + +```c +double stdlib_base_dists_wald_logcdf( const double x, const double mu, const double lambda ); +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```c +#include "stdlib/stats/base/dists/wald/logcdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#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 lambda; + double mu; + double x; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + x = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + mu = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + lambda = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + y = stdlib_base_dists_wald_logcdf( x, mu, lambda ); + printf( "x: %lf, μ: %lf, λ: %lf, ln(F(x;μ,λ)): %lf\n", x, mu, lambda, y ); + } +} +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.js new file mode 100644 index 000000000000..390962b3f302 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.js @@ -0,0 +1,90 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var logcdf = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var arrayOpts; + var lambda; + var mu; + var x; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + x = uniform( 100, EPS, 100.0, arrayOpts ); + mu = uniform( 100, EPS, 50.0, arrayOpts ); + lambda = uniform( 100, EPS, 20.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = logcdf( x[ i % x.length ], mu[ i % mu.length ], lambda[ i % lambda.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(); +}); + +bench( format( '%s:factory', pkg ), function benchmark( b ) { + var arrayOpts; + var mylogcdf; + var x; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + mylogcdf = logcdf.factory( 1.0, 1.5 ); + x = uniform( 100, EPS, 10.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = mylogcdf( x[ i % x.length ] ); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( isnan( y ) ) { + b.fail( 'should not return NaN' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.native.js new file mode 100644 index 000000000000..27c59ac3c43d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/benchmark.native.js @@ -0,0 +1,71 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var bench = require( '@stdlib/bench' ); +var uniform = require( '@stdlib/random/array/uniform' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var tryRequire = require( '@stdlib/utils/try-require' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; + + +// VARIABLES // + +var logcdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logcdf instanceof Error ) +}; + + +// MAIN // + +bench( format( '%s::native', pkg ), opts, function benchmark( b ) { + var arrayOpts; + var lambda; + var mu; + var x; + var y; + var i; + + arrayOpts = { + 'dtype': 'float64' + }; + x = uniform( 100, EPS, 100.0, arrayOpts ); + mu = uniform( 100, EPS, 50.0, arrayOpts ); + lambda = uniform( 100, EPS, 20.0, arrayOpts ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = logcdf( x[ i % x.length ], mu[ i % mu.length ], lambda[ i % lambda.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/wald/logcdf/benchmark/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/Makefile new file mode 100644 index 000000000000..979768abbcec --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := benchmark.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled benchmarks. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/benchmark.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/benchmark.c new file mode 100644 index 000000000000..98f51a79a407 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/benchmark/c/benchmark.c @@ -0,0 +1,143 @@ +/** +* @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/wald/logcdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#include +#include +#include +#include + +#define NAME "wald-logcdf" +#define ITERATIONS 1000000 +#define REPEATS 3 + +/** +* Prints the TAP version. +*/ +static void print_version( void ) { + printf( "TAP version 13\n" ); +} + +/** +* Prints the TAP summary. +* +* @param total total number of tests +* @param passing total number of passing tests +*/ +static void print_summary( int total, int passing ) { + printf( "#\n" ); + printf( "1..%d\n", total ); // TAP plan + printf( "# total %d\n", total ); + printf( "# pass %d\n", passing ); + printf( "#\n" ); + printf( "# ok\n" ); +} + +/** +* Prints benchmarks results. +* +* @param elapsed elapsed time in seconds +*/ +static void print_results( double elapsed ) { + double rate = (double)ITERATIONS / elapsed; + printf( " ---\n" ); + printf( " iterations: %d\n", ITERATIONS ); + printf( " elapsed: %0.9f\n", elapsed ); + printf( " rate: %0.9f\n", rate ); + printf( " ...\n" ); +} + +/** +* Returns a clock time. +* +* @return clock time +*/ +static double tic( void ) { + struct timeval now; + gettimeofday( &now, NULL ); + return (double)now.tv_sec + (double)now.tv_usec/1.0e6; +} + +/** +* Generates a random number on the interval [min,max). +* +* @param min minimum value (inclusive) +* @param max maximum value (exclusive) +* @return random number +*/ +static double random_uniform( const double min, const double max ) { + double v = (double)rand() / ( (double)RAND_MAX + 1.0 ); + return min + ( v*(max-min) ); +} + +/** +* Runs a benchmark. +* +* @return elapsed time in seconds +*/ +static double benchmark( void ) { + double lambda[ 100 ]; + double mu[ 100 ]; + double x[ 100 ]; + double elapsed; + double y; + double t; + int i; + + for ( i = 0; i < 100; i++ ) { + x[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 100.0 ); + mu[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 50.0 ); + lambda[ i ] = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 ); + } + + t = tic(); + for ( i = 0; i < ITERATIONS; i++ ) { + y = stdlib_base_dists_wald_logcdf( x[ i%100 ], mu[ i%100 ], lambda[ 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/wald/logcdf/binding.gyp b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/repl.txt new file mode 100644 index 000000000000..1e1d2d056668 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/repl.txt @@ -0,0 +1,83 @@ + +{{alias}}( x, μ, λ ) + Evaluates the natural logarithm of the cumulative distribution function + (CDF) for a Wald distribution with mean `μ` and shape parameter `λ` at a + value `x`. + + 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 + ---------- + x: number + Input value. + + μ: number + Mean parameter. + + λ: number + Shape parameter. + + Returns + ------- + out: number + Evaluated logCDF. + + Examples + -------- + > var y = {{alias}}( 2.0, 1.0, 1.0 ) + ~-0.122 + > y = {{alias}}( 0.5, 2.0, 3.0 ) + ~-2.897 + > y = {{alias}}( -1.0, 4.0, 2.0 ) + -Infinity + > y = {{alias}}( NaN, 1.0, 1.0 ) + NaN + > y = {{alias}}( 0.0, NaN, 1.0 ) + NaN + > y = {{alias}}( 0.0, 1.0, NaN ) + NaN + + // Negative shape parameter: + > y = {{alias}}( 2.0, 1.0, -1.0 ) + NaN + + // Degenerate distribution when `λ = 0.0`: + > y = {{alias}}( 2.0, 8.0, 0.0 ) + -Infinity + > y = {{alias}}( 8.0, 8.0, 0.0 ) + 0.0 + > y = {{alias}}( 10.0, 8.0, 0.0 ) + 0.0 + + +{{alias}}.factory( μ, λ ) + Returns a function for evaluating the natural logarithm of the cumulative + distribution function (CDF) of a Wald distribution with mean `μ` and shape + parameter `λ`. + + Parameters + ---------- + μ: number + Mean parameter. + + λ: number + Shape parameter. + + Returns + ------- + logcdf: Function + Logarithm of cumulative distribution function (CDF). + + Examples + -------- + > var mylogcdf = {{alias}}.factory( 10.0, 2.0 ); + > var y = mylogcdf( 10.0 ) + ~-0.253 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/index.d.ts new file mode 100644 index 000000000000..a4616fbf0a4c --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/index.d.ts @@ -0,0 +1,121 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Wald distribution. +* +* @param x - input value +* @returns evaluated logCDF +*/ +type Unary = ( x: number ) => number; + +/** +* Interface for the natural logarithm of the cumulative distribution function (CDF) of a Wald distribution. +*/ +interface LogCDF { + /** + * Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. + * + * ## Notes + * + * - If provided `mu <= 0` or `lambda < 0`, the function returns `NaN`. + * + * @param x - input value + * @param mu - mean + * @param lambda - shape parameter + * @returns evaluated logCDF + * + * @example + * var y = logcdf( 2.0, 1.0, 1.0 ); + * // returns ~-0.122 + * + * @example + * var y = logcdf( 0.5, 2.0, 3.0 ); + * // returns ~-2.897 + * + * @example + * var y = logcdf( NaN, 1.0, 1.0 ); + * // returns NaN + * + * @example + * var y = logcdf( 0.0, NaN, 1.0 ); + * // returns NaN + * + * @example + * var y = logcdf( 0.0, 1.0, NaN ); + * // returns NaN + * + * @example + * // Nonpositive mean: + * var y = logcdf( 2.0, 0.0, 1.0 ); + * // returns NaN + * + * @example + * // Negative shape parameter: + * var y = logcdf( 2.0, 1.0, -1.0 ); + * // returns NaN + * + * @example + * // Degenerate distribution when `lambda = 0.0`: + * var y = logcdf( 2.0, 8.0, 0.0 ); + * // returns -Infinity + */ + ( x: number, mu: number, lambda: number ): number; + + /** + * Returns a function for evaluating the natural logarithm of the cumulative distribution function (CDF) for a Wald distribution. + * + * @param mu - mean + * @param lambda - shape parameter + * @returns function to evaluate the natural logarithm of the cumulative distribution function + * + * @example + * var mylogcdf = logcdf.factory( 10.0, 2.0 ); + * var y = mylogcdf( 10.0 ); + * // returns ~-0.253 + * + * y = mylogcdf( 12.0 ); + * // returns ~-0.213 + */ + factory( mu: number, lambda: number ): Unary; +} + +/** +* Wald distribution natural logarithm of the cumulative distribution function (CDF). +* +* @param x - input value +* @param mu - mean +* @param lambda - shape parameter +* @returns evaluated logCDF +* +* @example +* var y = logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +* +* var mylogcdf = logcdf.factory( 10.0, 2.0 ); +* y = mylogcdf( 10.0 ); +* // returns ~-0.253 +*/ +declare var logcdf: LogCDF; + + +// EXPORTS // + +export = logcdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/test.ts new file mode 100644 index 000000000000..784bffdc827a --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/docs/types/test.ts @@ -0,0 +1,119 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import logcdf = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + logcdf( 2, 2, 4 ); // $ExpectType number + logcdf( 1, 2, 8 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided values other than three numbers... +{ + logcdf( true, 3, 6 ); // $ExpectError + logcdf( false, 2, 4 ); // $ExpectError + logcdf( '5', 1, 2 ); // $ExpectError + logcdf( [], 1, 2 ); // $ExpectError + logcdf( {}, 2, 4 ); // $ExpectError + logcdf( ( x: number ): number => x, 2, 4 ); // $ExpectError + + logcdf( 9, true, 12 ); // $ExpectError + logcdf( 9, false, 12 ); // $ExpectError + logcdf( 5, '5', 10 ); // $ExpectError + logcdf( 8, [], 16 ); // $ExpectError + logcdf( 9, {}, 18 ); // $ExpectError + logcdf( 8, ( x: number ): number => x, 16 ); // $ExpectError + + logcdf( 9, 5, true ); // $ExpectError + logcdf( 9, 5, false ); // $ExpectError + logcdf( 5, 2, '5' ); // $ExpectError + logcdf( 8, 4, [] ); // $ExpectError + logcdf( 9, 4, {} ); // $ExpectError + logcdf( 8, 5, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + logcdf(); // $ExpectError + logcdf( 2 ); // $ExpectError + logcdf( 2, 0 ); // $ExpectError + logcdf( 2, 0, 4, 1 ); // $ExpectError +} + +// Attached to main export is a `factory` method which returns a function... +{ + logcdf.factory( 3, 4 ); // $ExpectType Unary +} + +// The `factory` method returns a function which returns a number... +{ + const fcn = logcdf.factory( 3, 4 ); + fcn( 2 ); // $ExpectType number +} + +// The compiler throws an error if the function returned by the `factory` method is provided invalid arguments... +{ + const fcn = logcdf.factory( 3, 4 ); + fcn( true ); // $ExpectError + fcn( false ); // $ExpectError + fcn( '5' ); // $ExpectError + fcn( [] ); // $ExpectError + fcn( {} ); // $ExpectError + fcn( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function returned by the `factory` method is provided an unsupported number of arguments... +{ + const fcn = logcdf.factory( 3, 4 ); + fcn(); // $ExpectError + fcn( 2, 0 ); // $ExpectError + fcn( 2, 0, 1 ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided values other than two numbers... +{ + logcdf.factory( true, 3 ); // $ExpectError + logcdf.factory( false, 2 ); // $ExpectError + logcdf.factory( '5', 1 ); // $ExpectError + logcdf.factory( [], 1 ); // $ExpectError + logcdf.factory( {}, 2 ); // $ExpectError + logcdf.factory( ( x: number ): number => x, 2 ); // $ExpectError + + logcdf.factory( 9, true ); // $ExpectError + logcdf.factory( 9, false ); // $ExpectError + logcdf.factory( 5, '5' ); // $ExpectError + logcdf.factory( 8, [] ); // $ExpectError + logcdf.factory( 9, {} ); // $ExpectError + logcdf.factory( 8, ( x: number ): number => x ); // $ExpectError + + logcdf.factory( [], true ); // $ExpectError + logcdf.factory( {}, false ); // $ExpectError + logcdf.factory( false, '5' ); // $ExpectError + logcdf.factory( {}, [] ); // $ExpectError + logcdf.factory( '5', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `factory` method is provided an unsupported number of arguments... +{ + logcdf.factory( 0 ); // $ExpectError + logcdf.factory( 0, 4, 8 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/Makefile new file mode 100644 index 000000000000..c8f8e9a1517b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/Makefile @@ -0,0 +1,146 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + +# Define the program used for compiling C source files: +ifdef C_COMPILER + CC := $(C_COMPILER) +else + CC := gcc +endif + +# Define the command-line options when compiling C files: +CFLAGS ?= \ + -std=c99 \ + -O3 \ + -Wall \ + -pedantic + +# Determine whether to generate position independent code ([1][1], [2][2]). +# +# [1]: https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#Code-Gen-Options +# [2]: http://stackoverflow.com/questions/5311515/gcc-fpic-option +ifeq ($(OS), WINNT) + fPIC ?= +else + fPIC ?= -fPIC +endif + +# List of includes (e.g., `-I /foo/bar -I /beep/boop/include`): +INCLUDE ?= + +# List of source files: +SOURCE_FILES ?= + +# List of libraries (e.g., `-lopenblas -lpthread`): +LIBRARIES ?= + +# List of library paths (e.g., `-L /foo/bar -L /beep/boop`): +LIBPATH ?= + +# List of C targets: +c_targets := example.out + + +# RULES # + +#/ +# Compiles source files. +# +# @param {string} [C_COMPILER] - C compiler (e.g., `gcc`) +# @param {string} [CFLAGS] - C compiler options +# @param {(string|void)} [fPIC] - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} [INCLUDE] - list of includes (e.g., `-I /foo/bar -I /beep/boop/include`) +# @param {string} [SOURCE_FILES] - list of source files +# @param {string} [LIBPATH] - list of library paths (e.g., `-L /foo/bar -L /beep/boop`) +# @param {string} [LIBRARIES] - list of libraries (e.g., `-lopenblas -lpthread`) +# +# @example +# make +# +# @example +# make all +#/ +all: $(c_targets) + +.PHONY: all + +#/ +# Compiles C source files. +# +# @private +# @param {string} CC - C compiler (e.g., `gcc`) +# @param {string} CFLAGS - C compiler options +# @param {(string|void)} fPIC - compiler flag determining whether to generate position independent code (e.g., `-fPIC`) +# @param {string} INCLUDE - list of includes (e.g., `-I /foo/bar`) +# @param {string} SOURCE_FILES - list of source files +# @param {string} LIBPATH - list of library paths (e.g., `-L /foo/bar`) +# @param {string} LIBRARIES - list of libraries (e.g., `-lopenblas`) +#/ +$(c_targets): %.out: %.c + $(QUIET) $(CC) $(CFLAGS) $(fPIC) $(INCLUDE) -o $@ $(SOURCE_FILES) $< $(LIBPATH) -lm $(LIBRARIES) + +#/ +# Runs compiled examples. +# +# @example +# make run +#/ +run: $(c_targets) + $(QUIET) ./$< + +.PHONY: run + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: + $(QUIET) -rm -f *.o *.out + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/example.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/example.c new file mode 100644 index 000000000000..a7ef62dcc032 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/c/example.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/wald/logcdf.h" +#include "stdlib/constants/float64/eps.h" +#include +#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 lambda; + double mu; + double x; + double y; + int i; + + for ( i = 0; i < 10; i++ ) { + x = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + mu = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + lambda = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 10.0 ); + y = stdlib_base_dists_wald_logcdf( x, mu, lambda ); + printf( "x: %lf, μ: %lf, λ: %lf, ln(F(x;μ,λ)): %lf\n", x, mu, lambda, y ); + } +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/index.js new file mode 100644 index 000000000000..81fc7d325ec0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/examples/index.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var uniform = require( '@stdlib/random/array/uniform' ); +var logEachMap = require( '@stdlib/console/log-each-map' ); +var EPS = require( '@stdlib/constants/float64/eps' ); +var logcdf = require( './../lib' ); + +var opts = { + 'dtype': 'float64' +}; +var x = uniform( 10, EPS, 10.0, opts ); +var mu = uniform( 10, EPS, 10.0, opts ); +var lambda = uniform( 10, EPS, 20.0, opts ); + +logEachMap( 'x: %0.4f, μ: %0.4f, λ: %0.4f, ln(F(x;μ,λ)): %0.4f', x, mu, lambda, logcdf ); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/include.gypi b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' + */ + function logcdf( x ) { + var t1; + var t2; + var a; + var b; + var z; + + if ( isnan( x ) ) { + return NaN; + } + if ( x <= 0.0 ) { + return NINF; + } + if ( x === PINF ) { + return 0.0; + } + z = sqrt( lambda / x ); + a = ( z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ); + b = ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ); + + // Φ(a) = 0.5 * erfc( -a / √2 ) + t1 = 0.5 * erfc( -a ); + + // exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² ), as b² - a² = 2λ/μ; computing via `erfcx` avoids overflow of the exponential term for large `λ/μ`: + t2 = 0.5 * erfcx( b ) * exp( -a * a ); + return ln( t1 + t2 ); + } +} + + +// EXPORTS // + +module.exports = factory; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js new file mode 100644 index 000000000000..70d6cec3346d --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js @@ -0,0 +1,51 @@ +/** +* @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'; + +/** +* Wald distribution logarithm of cumulative distribution function (CDF). +* +* @module @stdlib/stats/base/dists/wald/logcdf +* +* @example +* var logcdf = require( '@stdlib/stats/base/dists/wald/logcdf' ); +* +* var y = logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +* +* var mylogcdf = logcdf.factory( 2.0, 1.0 ); +* y = mylogcdf( 2.0 ); +* // returns ~-0.337 +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var factory = require( './factory.js' ); + + +// MAIN // + +setReadOnly( main, 'factory', factory ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js new file mode 100644 index 000000000000..02a7826776d9 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js @@ -0,0 +1,122 @@ +/** +* @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 erfcx = require( '@stdlib/math/base/special/erfcx' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var erfc = require( '@stdlib/math/base/special/erfc' ); +var exp = require( '@stdlib/math/base/special/exp' ); +var ln = require( '@stdlib/math/base/special/ln' ); +var PINF = require( '@stdlib/constants/float64/pinf' ); +var NINF = require( '@stdlib/constants/float64/ninf' ); + + +// MAIN // + +/** +* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. +* +* @param {number} x - input value +* @param {PositiveNumber} mu - mean +* @param {NonNegativeNumber} lambda - shape parameter +* @returns {number} evaluated logCDF +* +* @example +* var y = logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +* +* @example +* var y = logcdf( 0.5, 2.0, 3.0 ); +* // returns ~-2.897 +* +* @example +* var y = logcdf( NaN, 1.0, 1.0 ); +* // returns NaN +* +* @example +* var y = logcdf( 1.0, NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = logcdf( 1.0, 1.0, NaN ); +* // returns NaN +* +* @example +* // Non-positive mean: +* var y = logcdf( 2.0, 0.0, 1.0 ); +* // returns NaN +* +* @example +* // Negative shape parameter: +* var y = logcdf( 2.0, 1.0, -1.0 ); +* // returns NaN +* +* @example +* // Zero shape parameter (degenerate distribution): +* var y = logcdf( 1.0, 1.0, 0.0 ); +* // returns 0.0 +* +* @example +* var y = logcdf( 0.0, 1.0, 1.0 ); +* // returns -Infinity +*/ +function logcdf( x, mu, lambda ) { + var t1; + var t2; + var a; + var b; + var z; + + if ( + isnan( x ) || + isnan( mu ) || + isnan( lambda ) || + mu <= 0.0 || + lambda < 0.0 + ) { + return NaN; + } + if ( lambda === 0.0 ) { + return ( x < mu ) ? NINF : 0.0; + } + if ( x <= 0.0 ) { + return NINF; + } + if ( x === PINF ) { + return 0.0; + } + z = sqrt( lambda / x ); + a = ( z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ); + b = ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ); + + // Φ(a) = 0.5 * erfc( -a / sqrt( 2 ) ) + t1 = 0.5 * erfc( -a ); + + // exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² ), as b² - a² = 2λ/μ; computing via `erfcx` avoids overflow of the exponential term for large `λ/μ`: + t2 = 0.5 * erfcx( b ) * exp( -a * a ); + return ln( t1 + t2 ); +} + + +// EXPORTS // + +module.exports = logcdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/native.js new file mode 100644 index 000000000000..0118420b5470 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/native.js @@ -0,0 +1,83 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. +* +* @private +* @param {number} x - input value +* @param {PositiveNumber} mu - mean +* @param {number} lambda - shape parameter +* @returns {number} evaluated logCDF +* +* @example +* var y = logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +* +* @example +* var y = logcdf( 0.5, 2.0, 3.0 ); +* // returns ~-2.897 +* +* @example +* var y = logcdf( NaN, 1.0, 1.0 ); +* // returns NaN +* +* @example +* var y = logcdf( 1.0, NaN, 1.0 ); +* // returns NaN +* +* @example +* var y = logcdf( 1.0, 1.0, NaN ); +* // returns NaN +* +* @example +* // Non-positive mean: +* var y = logcdf( 2.0, 0.0, 1.0 ); +* // returns NaN +* +* @example +* // Negative shape parameter: +* var y = logcdf( 2.0, 1.0, -1.0 ); +* // returns NaN +* +* @example +* // Zero shape parameter (degenerate distribution): +* var y = logcdf( 1.0, 1.0, 0.0 ); +* // returns 0.0 +* +* @example +* var y = logcdf( 0.0, 1.0, 1.0 ); +* // returns -Infinity +*/ +function logcdf( x, mu, lambda ) { + return addon( x, mu, lambda ); +} + + +// EXPORTS // + +module.exports = logcdf; diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json new file mode 100644 index 000000000000..1a6ffa070c8b --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json @@ -0,0 +1,99 @@ +{ + "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", + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/erfcx", + "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/exp", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf" + ] + }, + { + "task": "benchmark", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/erfcx", + "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/exp", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/eps" + ] + }, + { + "task": "examples", + "wasm": false, + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/math/base/assert/is-nan", + "@stdlib/math/base/special/erfcx", + "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/sqrt", + "@stdlib/math/base/special/exp", + "@stdlib/math/base/special/ln", + "@stdlib/constants/float64/pinf", + "@stdlib/constants/float64/ninf", + "@stdlib/constants/float64/eps" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/package.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/package.json new file mode 100644 index 000000000000..a3fb80dec351 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/stats/base/dists/wald/logcdf", + "version": "0.0.0", + "description": "Natural logarithm of the cumulative distribution function (CDF) for a Wald distribution.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "gypfile": true, + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "statistics", + "stats", + "distribution", + "dist", + "probability", + "cdf", + "logcdf", + "cumulative distribution", + "distribution function", + "logarithm", + "inverse gaussian", + "inverse-gaussian", + "wald", + "univariate", + "continuous" + ] +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/Makefile b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 The Stdlib Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/addon.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/addon.c new file mode 100644 index 000000000000..2c546488b674 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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/wald/logcdf.h" +#include "stdlib/math/base/napi/ternary.h" + +STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_wald_logcdf ) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c new file mode 100644 index 000000000000..4e88555706db --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c @@ -0,0 +1,76 @@ +/** +* @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/wald/logcdf.h" +#include "stdlib/math/base/assert/is_nan.h" +#include "stdlib/math/base/special/erfcx.h" +#include "stdlib/math/base/special/sqrt.h" +#include "stdlib/math/base/special/erfc.h" +#include "stdlib/math/base/special/exp.h" +#include "stdlib/math/base/special/ln.h" +#include "stdlib/constants/float64/pinf.h" +#include "stdlib/constants/float64/ninf.h" + +/** +* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Wald distribution with mean `mu` and shape parameter `lambda` at a value `x`. +* +* @param x input value +* @param mu mean +* @param lambda shape parameter +* @return evaluated logCDF +* +* @example +* double y = stdlib_base_dists_wald_logcdf( 2.0, 1.0, 1.0 ); +* // returns ~-0.122 +*/ +double stdlib_base_dists_wald_logcdf( const double x, const double mu, const double lambda ) { + double t1; + double t2; + double a; + double b; + double z; + + if ( + stdlib_base_is_nan( x ) || + stdlib_base_is_nan( mu ) || + stdlib_base_is_nan( lambda ) || + mu <= 0.0 || + lambda < 0.0 + ) { + return 0.0 / 0.0; // NaN + } + if ( lambda == 0.0 ) { + return ( x < mu ) ? STDLIB_CONSTANT_FLOAT64_NINF : 0.0; + } + if ( x <= 0.0 ) { + return STDLIB_CONSTANT_FLOAT64_NINF; + } + if ( x == STDLIB_CONSTANT_FLOAT64_PINF ) { + return 0.0; + } + z = stdlib_base_sqrt( lambda / x ); + a = ( z * ( ( x / mu ) - 1.0 ) ) / stdlib_base_sqrt( 2.0 ); + b = ( z * ( ( x / mu ) + 1.0 ) ) / stdlib_base_sqrt( 2.0 ); + + // Φ(a) = 0.5 * erfc( -a / sqrt( 2 ) ) + t1 = 0.5 * stdlib_base_erfc( -a ); + + // exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² ), as b² - a² = 2λ/μ; computing via `erfcx` avoids overflow of the exponential term for large `λ/μ`: + t2 = 0.5 * stdlib_base_erfcx( b ) * stdlib_base_exp( -a * a ); + return stdlib_base_ln( t1 + t2 ); +} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js new file mode 100644 index 000000000000..8b8f8c6f6d02 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js @@ -0,0 +1,198 @@ +/** +* @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 factory = require( './../lib/factory.js' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof factory, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a function', function test( t ) { + var logcdf = factory( 1.0, 1.0 ); + t.strictEqual( typeof logcdf, 'function', 'returns expected value' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the created function returns `NaN`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 1.0, 1.0 ); + y = logcdf( NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NaN, 1.0 ); + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( 1.0, NaN ); + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NaN, NaN ); + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NaN, NaN ); + y = logcdf( NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a valid `mu` and `lambda`, the function returns a function which returns `0` when provided `+infinity` for `x`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 1.0, 0.0 ); + y = logcdf( PINF ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + logcdf = factory( 1.0, 1.0 ); + y = logcdf( PINF ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a valid `mu` and `lambda`, the function returns a function which returns `-infinity` when provided `-infinity` for `x`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 1.0, 0.0 ); + y = logcdf( NINF ); + t.strictEqual( y, NINF, 'returns expected value' ); + + logcdf = factory( 1.0, 1.0 ); + y = logcdf( NINF ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the created function always returns `NaN`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 0.0, 1.0 ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( -1.0, 1.0 ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NINF, 1.0 ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a negative `lambda`, the created function always returns `NaN`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 0.0, -1.0 ); + + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( 0.0, NINF ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( PINF, NINF ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NINF, NINF ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + logcdf = factory( NaN, NINF ); + y = logcdf( 2.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if `lambda` equals `0`, the created function evaluates a degenerate distribution centered at `mu`', function test( t ) { + var logcdf; + var y; + + logcdf = factory( 2.0, 0.0 ); + + y = logcdf( 2.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = logcdf( 3.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = logcdf( 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function evaluates the logcdf for `x` given parameters `mu` and `lambda`', function test( t ) { + var expected; + var lambda; + var logcdf; + var mu; + var x; + var y; + var i; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + logcdf = factory( mu[i], lambda[i] ); + y = logcdf( x[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[ i ], 70 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.js new file mode 100644 index 000000000000..b45719a84984 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var logcdf = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logcdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a factory method for generating `logcdf` functions', function test( t ) { + t.strictEqual( typeof logcdf.factory, 'function', 'exports a factory method' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js new file mode 100644 index 000000000000..25f41b057266 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js @@ -0,0 +1,149 @@ +/** +* @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 logcdf = require( './../lib' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logcdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) { + var y = logcdf( NaN, 1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logcdf( 0.0, NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logcdf( 0.0, 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the function always returns `NaN`', function test( t ) { + var y; + + y = logcdf( 2.0, 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, -1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `+infinity` for `x` and a valid `mu` and `lambda`, the function returns `0`', function test( t ) { + var y = logcdf( PINF, 1.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = logcdf( PINF, 1.0, 1.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `-infinity` for `x` and a valid `mu` and `lambda`, the function returns `-infinity`', function test( t ) { + var y = logcdf( NINF, 1.0, 0.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + y = logcdf( NINF, 1.0, 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a negative `lambda`, the function always returns `NaN`', function test( t ) { + var y; + + y = logcdf( 2.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `lambda` equals `0`, the function evaluates a degenerate distribution centered at `mu`', function test( t ) { + var y; + + y = logcdf( 2.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x equal to mu' ); + + y = logcdf( 3.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x greater than mu' ); + + y = logcdf( 1.0, 2.0, 0.0 ); + t.strictEqual( y, NINF, 'returns -infinity for x smaller than mu' ); + + t.end(); +}); + +tape( 'the function evaluates the logcdf for `x` given parameters `mu` and `lambda`', function test( t ) { + var expected; + var lambda; + var mu; + var i; + var x; + var y; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + y = logcdf( x[i], mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[ i ], 70 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js new file mode 100644 index 000000000000..bf24920680d0 --- /dev/null +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js @@ -0,0 +1,158 @@ +/** +* @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' ); + + +// FIXTURES // + +var data = require( './fixtures/julia/data.json' ); + + +// VARIABLES // + +var logcdf = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( logcdf instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof logcdf, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, function test( t ) { + var y = logcdf( NaN, 1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logcdf( 0.0, NaN, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + y = logcdf( 0.0, 1.0, NaN ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'if provided a nonpositive `mu`, the function always returns `NaN`', opts, function test( t ) { + var y; + + y = logcdf( 2.0, 0.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, -1.0, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NINF, 1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `+infinity` for `x` and a valid `mu` and `lambda`, the function returns `0`', opts, function test( t ) { + var y = logcdf( PINF, 1.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + y = logcdf( PINF, 1.0, 1.0 ); + t.strictEqual( y, 0.0, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `-infinity` for `x` and a valid `mu` and `lambda`, the function returns `-infinity`', opts, function test( t ) { + var y = logcdf( NINF, 1.0, 0.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + y = logcdf( NINF, 1.0, 1.0 ); + t.strictEqual( y, NINF, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided a negative `lambda`, the function always returns `NaN`', opts, function test( t ) { + var y; + + y = logcdf( 2.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 0.0, 0.0, -1.0 ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, 0.0, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, PINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NINF, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + y = logcdf( 2.0, NaN, NINF ); + t.strictEqual( isnan( y ), true, 'returns expected value' ); + + t.end(); +}); + +tape( 'if provided `lambda` equals `0`, the function evaluates a degenerate distribution centered at `mu`', opts, function test( t ) { + var y; + + y = logcdf( 2.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x equal to mu' ); + + y = logcdf( 3.0, 2.0, 0.0 ); + t.strictEqual( y, 0.0, 'returns 0 for x greater than mu' ); + + y = logcdf( 1.0, 2.0, 0.0 ); + t.strictEqual( y, NINF, 'returns -infinity for x smaller than mu' ); + + t.end(); +}); + +tape( 'the function evaluates the logcdf for `x` given parameters `mu` and `lambda`', opts, function test( t ) { + var expected; + var lambda; + var mu; + var x; + var y; + var i; + + expected = data.expected; + x = data.x; + mu = data.mu; + lambda = data.lambda; + for ( i = 0; i < x.length; i++ ) { + y = logcdf( x[i], mu[i], lambda[i] ); + if ( y === expected[i] ) { + t.strictEqual( y, expected[i], 'x: '+x[i]+', mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); + } else { + t.ok( isAlmostSameValue( y, expected[ i ], 70 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + } + } + t.end(); +}); From 14ba076b3460f95605946ba4d1f0490508c4349f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 18 Aug 2026 23:01:14 -0500 Subject: [PATCH 3/4] fix: improve tail accuracy by computing in log-space and regenerate fixtures --- .../base/dists/wald/logcdf/lib/factory.js | 26 +++++++++---------- .../stats/base/dists/wald/logcdf/lib/main.js | 24 ++++++++--------- .../base/dists/wald/logcdf/manifest.json | 18 +++++-------- .../stats/base/dists/wald/logcdf/src/main.c | 24 ++++++++--------- .../wald/logcdf/test/fixtures/julia/data.json | 2 +- .../wald/logcdf/test/fixtures/julia/runner.jl | 5 ++-- .../dists/wald/logcdf/test/test.factory.js | 2 +- .../base/dists/wald/logcdf/test/test.main.js | 2 +- .../dists/wald/logcdf/test/test.native.js | 2 +- 9 files changed, 47 insertions(+), 58 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/factory.js index 2238fb9deeeb..26f9564c1675 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/factory.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/factory.js @@ -22,12 +22,10 @@ var constantFunction = require( '@stdlib/utils/constant-function' ); var degenerate = require( '@stdlib/stats/base/dists/degenerate/logcdf' ).factory; -var erfcx = require( '@stdlib/math/base/special/erfcx' ); +var normalLogcdf = require( '@stdlib/stats/base/dists/normal/logcdf' ); +var log1pexp = require( '@stdlib/math/base/special/log1pexp' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); -var erfc = require( '@stdlib/math/base/special/erfc' ); -var exp = require( '@stdlib/math/base/special/exp' ); -var ln = require( '@stdlib/math/base/special/ln' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); @@ -50,6 +48,7 @@ var NINF = require( '@stdlib/constants/float64/ninf' ); * // returns ~-1.008 */ function factory( mu, lambda ) { + var c; if ( isnan( mu ) || isnan( lambda ) || @@ -61,6 +60,7 @@ function factory( mu, lambda ) { if ( lambda === 0.0 ) { return degenerate( mu ); } + c = ( 2.0 * lambda ) / mu; return logcdf; /** @@ -75,10 +75,9 @@ function factory( mu, lambda ) { * // returns */ function logcdf( x ) { - var t1; - var t2; var a; var b; + var v; var z; if ( isnan( x ) ) { @@ -91,15 +90,16 @@ function factory( mu, lambda ) { return 0.0; } z = sqrt( lambda / x ); - a = ( z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ); - b = ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ); + v = x / mu; - // Φ(a) = 0.5 * erfc( -a / √2 ) - t1 = 0.5 * erfc( -a ); + // First term: ln( Φ( √(λ/x)·(x/μ-1) ) ): + a = normalLogcdf( z * ( v - 1.0 ), 0.0, 1.0 ); - // exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² ), as b² - a² = 2λ/μ; computing via `erfcx` avoids overflow of the exponential term for large `λ/μ`: - t2 = 0.5 * erfcx( b ) * exp( -a * a ); - return ln( t1 + t2 ); + // Second term, in log-space to avoid overflow of exp( 2λ/μ ): + b = c + normalLogcdf( -z * ( v + 1.0 ), 0.0, 1.0 ); + + // Sum the terms in log-space: ln( e^a + e^b ) = a + ln( 1 + e^(b-a) ): + return a + log1pexp( b - a ); } } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js index 02a7826776d9..ccc8885bc80f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/main.js @@ -20,12 +20,10 @@ // MODULES // -var erfcx = require( '@stdlib/math/base/special/erfcx' ); +var normalLogcdf = require( '@stdlib/stats/base/dists/normal/logcdf' ); +var log1pexp = require( '@stdlib/math/base/special/log1pexp' ); var isnan = require( '@stdlib/math/base/assert/is-nan' ); var sqrt = require( '@stdlib/math/base/special/sqrt' ); -var erfc = require( '@stdlib/math/base/special/erfc' ); -var exp = require( '@stdlib/math/base/special/exp' ); -var ln = require( '@stdlib/math/base/special/ln' ); var PINF = require( '@stdlib/constants/float64/pinf' ); var NINF = require( '@stdlib/constants/float64/ninf' ); @@ -80,10 +78,9 @@ var NINF = require( '@stdlib/constants/float64/ninf' ); * // returns -Infinity */ function logcdf( x, mu, lambda ) { - var t1; - var t2; var a; var b; + var v; var z; if ( @@ -105,15 +102,16 @@ function logcdf( x, mu, lambda ) { return 0.0; } z = sqrt( lambda / x ); - a = ( z * ( ( x / mu ) - 1.0 ) ) / sqrt( 2.0 ); - b = ( z * ( ( x / mu ) + 1.0 ) ) / sqrt( 2.0 ); + v = x / mu; - // Φ(a) = 0.5 * erfc( -a / sqrt( 2 ) ) - t1 = 0.5 * erfc( -a ); + // First term: ln( Φ( √(λ/x)·(x/μ-1) ) ): + a = normalLogcdf( z * ( v - 1.0 ), 0.0, 1.0 ); - // exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² ), as b² - a² = 2λ/μ; computing via `erfcx` avoids overflow of the exponential term for large `λ/μ`: - t2 = 0.5 * erfcx( b ) * exp( -a * a ); - return ln( t1 + t2 ); + // Second term, in log-space to avoid overflow of exp( 2λ/μ ): + b = ( ( 2.0 * lambda ) / mu ) + normalLogcdf( -z * ( v + 1.0 ), 0.0, 1.0 ); + + // Sum the terms in log-space: ln( e^a + e^b ) = a + ln( 1 + e^(b-a) ): + return a + log1pexp( b - a ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json index 1a6ffa070c8b..d5f9501d698f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/manifest.json @@ -40,11 +40,9 @@ "dependencies": [ "@stdlib/math/base/napi/ternary", "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/erfcx", - "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/log1pexp", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/exp", - "@stdlib/math/base/special/ln", + "@stdlib/stats/base/dists/normal/logcdf", "@stdlib/constants/float64/pinf", "@stdlib/constants/float64/ninf" ] @@ -62,11 +60,9 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/erfcx", - "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/log1pexp", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/exp", - "@stdlib/math/base/special/ln", + "@stdlib/stats/base/dists/normal/logcdf", "@stdlib/constants/float64/pinf", "@stdlib/constants/float64/ninf", "@stdlib/constants/float64/eps" @@ -85,11 +81,9 @@ "libpath": [], "dependencies": [ "@stdlib/math/base/assert/is-nan", - "@stdlib/math/base/special/erfcx", - "@stdlib/math/base/special/erfc", + "@stdlib/math/base/special/log1pexp", "@stdlib/math/base/special/sqrt", - "@stdlib/math/base/special/exp", - "@stdlib/math/base/special/ln", + "@stdlib/stats/base/dists/normal/logcdf", "@stdlib/constants/float64/pinf", "@stdlib/constants/float64/ninf", "@stdlib/constants/float64/eps" diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c index 4e88555706db..6b7b4647d5d5 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/src/main.c @@ -17,12 +17,10 @@ */ #include "stdlib/stats/base/dists/wald/logcdf.h" +#include "stdlib/stats/base/dists/normal/logcdf.h" #include "stdlib/math/base/assert/is_nan.h" -#include "stdlib/math/base/special/erfcx.h" +#include "stdlib/math/base/special/log1pexp.h" #include "stdlib/math/base/special/sqrt.h" -#include "stdlib/math/base/special/erfc.h" -#include "stdlib/math/base/special/exp.h" -#include "stdlib/math/base/special/ln.h" #include "stdlib/constants/float64/pinf.h" #include "stdlib/constants/float64/ninf.h" @@ -39,10 +37,9 @@ * // returns ~-0.122 */ double stdlib_base_dists_wald_logcdf( const double x, const double mu, const double lambda ) { - double t1; - double t2; double a; double b; + double v; double z; if ( @@ -64,13 +61,14 @@ double stdlib_base_dists_wald_logcdf( const double x, const double mu, const dou return 0.0; } z = stdlib_base_sqrt( lambda / x ); - a = ( z * ( ( x / mu ) - 1.0 ) ) / stdlib_base_sqrt( 2.0 ); - b = ( z * ( ( x / mu ) + 1.0 ) ) / stdlib_base_sqrt( 2.0 ); + v = x / mu; - // Φ(a) = 0.5 * erfc( -a / sqrt( 2 ) ) - t1 = 0.5 * stdlib_base_erfc( -a ); + // First term: ln( Φ( √(λ/x)·(x/μ-1) ) ): + a = stdlib_base_dists_normal_logcdf( z * ( v - 1.0 ), 0.0, 1.0 ); - // exp( 2λ/μ ) * erfc( b ) = erfcx( b ) * exp( -a² ), as b² - a² = 2λ/μ; computing via `erfcx` avoids overflow of the exponential term for large `λ/μ`: - t2 = 0.5 * stdlib_base_erfcx( b ) * stdlib_base_exp( -a * a ); - return stdlib_base_ln( t1 + t2 ); + // Second term, in log-space to avoid overflow of exp( 2λ/μ ): + b = ( ( 2.0 * lambda ) / mu ) + stdlib_base_dists_normal_logcdf( -z * ( v + 1.0 ), 0.0, 1.0 ); + + // Sum the terms in log-space: ln( e^a + e^b ) = a + ln( 1 + e^(b-a) ): + return a + stdlib_base_log1pexp( b - a ); } diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json index e39ea0fbdc54..2e699a2a0452 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/data.json @@ -1 +1 @@ -{"expected":[-0.7677471309208188,-0.2787086340220627,0.0,-0.29186588079971265,-0.1914971235172907,-0.12731826437327878,-0.0610086784073224,-0.19028425707461988,-0.42681525205624893,-0.27244540801438005,-0.21251158404533438,-7.845946115029059e-13,-0.03849048984358715,-0.39578618408422156,-0.1898310436301173,-0.1318845431741165,-0.40646684018544416,-0.3032891917840776,-0.055637733176745294,-8.455943621096414e-7,-0.343219796523212,-0.30141601654141464,-0.10333296295995086,-0.05455642821892258,-0.04690587719185412,-1.2720808052052244,-0.0796962282143258,-0.47193573066608335,-0.4134530021156068,-0.11314697005967272,-0.03216471247353266,-0.020954752134945673,-0.015599520523660508,-0.022494116512983355,-0.4180621901857225,-0.18835293326522334,-0.16834635837723289,-0.3472847724996076,-0.24962076409812362,-0.08246932615110435,-0.128564918241411,-0.5020499338920977,-0.29038754396175376,-0.31169717833873184,-0.06904784684357243,-0.41970306762870274,-0.13612005685448972,-0.007271828416049349,-0.00015796160625364324,-0.3311220546908127,-0.11981911864755566,-0.13022790414103966,-0.0653217646127126,-4.003896732022639e-5,-0.4620331299491943,-0.0003188154680565489,-0.38204564060956536,-0.8363929373195002,-0.9756308487481092,-4.9411845947719495e-8,-0.07582593148795107,-0.11930444004258285,-0.0668266210026477,-0.30539528705537283,-0.08481174372338386,-0.4053973718067023,-0.0006811817874303994,-0.15181102110853595,-1.1102230246251571e-15,-0.23894111947821683,-0.4055153021544522,-0.5295901072426727,-0.7862467843532569,-0.23625035118551335,-0.7486181436475855,-0.2265031845816536,-0.23736214416237184,-2.734723628742852e-5,-7.799821085523022e-7,-1.9762834684280597,-0.17720845862335044,-1.6047335064319812,-0.06880222614093277,-1.4355755358673525,-0.6239490729338388,-0.44181840911139736,-0.004426075765944797,-0.7023753511957961,-9.821689340075041e-7,-0.16860071469676394,-3.60587923479994e-6,-0.3160273270864338,-0.3911833228365226,-0.006534973023468772,-0.2151583507497586,-0.21306433776438144,-0.4856215167778689,-1.0184441802713948,-0.01465861472109714,-0.44445041735898383],"lambda":[3.4182949858077,0.9845087298645656,5.465527946273955,2.5987593899852373,1.9216955103800584,4.579307057884379,1.1343018721139326,2.849717984377608,3.2133430829381417,0.9625108956354124,3.371665659695282,2.805442223488767,4.44468565429758,4.433179917864226,2.576160379504697,2.8223135910564094,1.2429981405376247,4.0473949070773045,1.1047542930351129,5.051094499713389,1.3111616354411055,2.4791400567783675,1.9453897196172838,2.127033864180355,0.7435161144635856,5.089596050430019,0.7752557258865956,4.691790733935846,4.281872205292993,0.5634391957954256,5.132801344678098,3.29014221448661,4.448297918820132,2.195027101153086,2.688822324137505,2.765846447298146,4.354168793562432,1.0658269785567476,2.178053638839283,2.4465233576499212,1.0990075318128263,3.228971380463501,4.1765257232579,2.0902869722580726,5.045447362285321,4.047817024997428,2.2199700297012663,3.2203653321442385,2.763466252624867,2.1367585182007534,2.4745642757442203,4.858879927127423,0.9078811141958649,3.6810595480822585,0.8716694632316103,4.085871270710637,4.709679246255085,1.1092181441653954,4.733287410506161,1.1788727460919293,3.540469013320017,3.8588567647538903,1.0619959125897238,0.8854344423505351,1.8389559714572234,4.6743120740445345,2.3544039623848314,1.1756405668437453,3.9509919918045346,0.7575567061807799,1.1668854923906204,0.8918320819250132,4.696797384360636,5.2324232762413505,5.2506265556158125,5.389614103339855,1.3940498868748703,1.2958007081806506,3.0941573004056924,3.9362339077236843,0.708912296787423,2.4916859851471442,3.7517927984576716,3.7068430245034776,3.583063243333941,3.7601678800755503,5.1289404412236514,2.4361888788779726,4.833015774842675,1.4828963428654718,3.7508439675908103,2.278758223315224,3.457467368389411,5.234726366211575,5.231852707886034,3.696323350359666,2.5707934765856386,2.576901884357016,4.49598988830824,0.7690569644559482],"mu":[3.8160297895874224,5.415908329124594,0.5098294457677306,8.665746474677183,10.490841684140882,7.1991516914171445,4.032161592390338,9.070624432050852,8.95913754370084,10.146402603476993,10.3407887338936,0.6393188110327748,3.145518185330049,9.616540905114231,8.967259935062401,5.443979290251943,8.29334647693589,8.09163507594657,3.9833185116217127,1.7374280764998846,10.452407505971397,3.8370171293839834,4.809014301721888,1.4821914990086722,3.3320938535172333,1.639139987037665,2.076902173790744,7.2304256442179655,2.412671924751886,4.255038874649795,4.277911019408543,0.812347895555013,3.5602582965202876,3.067131107032048,5.704614939345904,6.508542890761502,6.385499153243318,5.455690900264028,8.28023740277153,0.5799358125122351,7.512617541092614,8.748534915987456,7.756998715695716,10.23885645518659,3.995320845136445,6.490540061067665,6.785084839722879,2.8691921705940233,1.752709849172211,7.161709560199388,5.790151123415305,4.565825012287347,3.3744926752138635,1.3665683138289182,3.816929208869981,1.369492173041193,5.378418315644382,7.906194742649857,9.504535724332658,0.7024185800711331,2.9638803445504376,6.645498718228065,4.1742419240277355,3.4434500311712366,2.2486516607363467,9.609355017691701,1.6218297864010573,7.8910398111913835,0.9104660748344702,9.6503359649901,2.4004774221277865,6.356006929162634,7.4573009069662035,5.36451840194582,9.623368354860267,8.098812331662867,10.192812496623592,0.5020784910025795,1.351259073741264,7.433207181952219,6.113145747998349,6.602175262408755,5.426094194351745,8.691377983453759,8.123292392337401,5.377197644699508,3.031751898527508,5.176441314240477,1.2760245361187845,10.008952169986545,1.6231979378457735,7.677283728015991,5.00564795025744,2.255467934246715,4.465342050489921,9.362791987802348,5.264922150484514,3.403574128136217,3.373899777469633,7.00522245725154],"x":[2.2886880843138413,4.661388669370461,15.164537825110578,8.580338485008458,13.73915494763048,14.78806163179938,14.565318272075649,13.568291100825938,6.465840749368759,6.392777340057905,14.114190165765205,7.952657002508393,9.114945824077552,8.161810069690503,13.23329832865447,11.083797993173047,4.072572698806404,8.847293054194239,15.332814992757871,15.091450707842013,5.733962582801725,4.414253408195529,11.692845103537817,3.8068812632230715,14.916144031773209,1.0340519826411827,6.049544567572894,5.834829491402029,2.541050075694834,8.926839111319834,13.913346183645592,1.8991106264926323,14.162118502537885,13.7975473492501,4.63823867808127,10.206891349779566,11.007962728402008,3.7602702308618947,9.201457611508358,1.007840623581448,14.103987083350495,5.415650665670313,8.913242428108818,8.161362544753588,9.752927151712433,5.710525221039752,13.502196663522962,14.673184141520277,14.337243800801662,6.233993636353876,12.681184607155295,8.758226788742023,11.701801914149112,9.061904964813463,2.041727696636957,6.809354705327678,5.464970651498978,1.4324613631118366,3.44743466072849,11.453329627931085,7.069475744432183,14.31014936889021,14.333518753828798,3.085512672342392,5.547598155269018,8.114922860121514,11.372559054774827,12.47228776059942,14.081165874504084,6.484826227477347,2.0262069868905974,2.1184974441980264,3.783768749367585,7.5108876362044645,4.783809857133653,11.478873751152472,9.330246900115748,3.557435343536315,14.1381728603775,1.3212892380120955,7.414683128332771,1.1483921882614285,15.3653829284134,1.8773257335438212,4.372427980998328,4.673844934708131,13.958932918188475,2.5509970305581966,9.055487743895595,14.077839259589743,14.935055984159352,6.994637543926216,4.775892906574661,8.219044669142614,6.58180954850306,13.171497792989001,3.7732884595245677,1.482575506652672,13.263404058135288,2.4905187691408806]} +{"expected":[-0.3821180827634222,-0.07912080700799984,-0.33862433119012963,-0.8556260694464137,-0.16333741314071965,-0.07761780151793704,-9.175601795528503e-24,-0.13453402573681386,-0.23234618313992772,-0.8596870242102908,-2.387138814840894,-1.695365363310557,-0.4036122945518386,-0.9008954627980195,-0.0012662203143284597,-0.11137237959976057,-0.0016110105624690691,-0.0867691179405918,-4.478403128420931e-29,-0.135935455367235,-0.8607293567268204,-1.29864591836839,-0.3381839556168812,-0.17755454426839362,-0.3202249080788569,-0.08084171816017868,-0.9459565514103956,-0.15551997418035335,-0.0889515045894328,-0.10218120158459978,-3.258665241052597e-5,-0.3092111716998122,-0.02430352154552152,-0.0003633322292988793,-0.8383528256896645,-0.36623917175271953,-1.1642869125945726e-20,-0.09355134292076306,-0.005384387593154178,-2.565312546088896,-4.607446552937712e-28,-0.04850994853140565,-0.12061007140723151,-0.49264360477503877,-0.11439755682885536,-0.1928636243241382,-0.00023690530724387285,-0.36734298629165607,-4.59214443450453,-0.1657592312929393,-0.00013898619053781612,-0.660222236296917,-0.003328428570885231,-0.3674400249190921,-0.23033253994353425,-0.7816961671167895,-1.2802620149039414,-0.13594455819950452,-0.18510671611387897,-0.016745284272829487,-0.9875618835787822,-0.09815459110285979,-0.08470448182663895,-0.43597528936207064,-0.09772680696655123,-0.36908432932428037,-0.8285237385250217,-0.7034055676683307,-0.334005738664796,-0.18569098420934665,-0.21652082950235368,-0.37947564915191234,-0.19667272905935113,-0.0029947897659826006,-0.347447234452384,-0.28112161029618343,-0.0008894017521918476,-0.2245394010087597,-0.15979550923643762,-0.1237615135660976,-0.09686952009889152,-0.3734841045740614,-8.422311221607939e-14,-0.21340321029839304,-0.32042878506146044,-0.19939328097202713,-0.279797745568347,-3.019617888914462e-9,-1.7365879268668094,-0.010732170881302343,-0.01693821481217428,-0.12806231312210897,-0.48844906543455446,-0.2746975400430869,-0.06776835995406198,-0.0725352126249339,-0.2108940088215318,-1.0255232372129064,-0.2768461124611029,-0.3466656715326828],"x":[8.176970368522735,14.699950957136616,7.399856276424404,3.5785530370839687,12.134483197488507,13.66027629964521,15.1763212566113,15.307040574149559,5.271531964386848,3.2698843703443874,0.7597087680656862,1.084535840489262,6.904650887901094,0.5495560142586227,12.163895083525858,13.052066308268754,5.877617717398893,13.627813991448535,7.7997287004130245,12.610196063648466,3.3028333238931964,2.5408489714536544,4.872231014593523,10.309957422847503,9.281086128131514,2.2801248162147343,1.8908262974543895,14.344453834224439,13.212803321345243,10.008493733982123,5.790165122795808,11.05885357205121,5.373421966899427,4.064996361766376,3.5170211986012903,4.854437450690207,12.089635897839731,13.260923349925488,4.333272568644501,0.7309136322867567,13.057822327182556,12.941307635794018,11.738408107278918,3.6596582727445437,12.350158480158818,7.755738836806834,9.358587778732371,4.463403783880839,0.5994943152460598,10.285255510573249,11.236265201007859,2.062849924665943,12.629585482444575,6.18734006944358,8.054602378784326,4.380533149467114,2.193384017663978,12.70187594504336,7.1216288433652455,9.701112476636132,3.5744883727382093,13.840405355525558,11.011482510763738,7.425976468663685,9.991078827772553,9.336990025079091,0.6878203013779134,3.0671871583715076,4.020937589666972,12.016127852949301,12.468035218643852,5.520112508134655,5.172768961884603,14.99558995135919,7.56798353841973,3.9848914754320406,12.718377437730297,12.17819039873291,7.740587959798203,9.898542618978261,13.546856057018969,6.228045068533032,4.067537227102244,11.481457785900151,8.551900031834307,14.600747283425383,2.2541813990905086,14.154163459149338,0.8611240495909346,8.355247708210294,14.993353515638347,9.906972277951096,2.751610351609056,8.432886205692784,11.565208786133127,15.392237604698838,14.551532246520932,1.1439086067484256,4.226568637927821,2.062804773488611],"lambda":[5.134494609604874,0.9731827907069724,2.771448162463563,4.2554376611906175,1.8642294094907659,4.981621897470267,4.569086608652158,3.8058710469662707,4.17054532078154,3.780027041127529,2.7059768403018643,2.9072847640233075,3.2522390834998163,2.042849250669401,3.7242306500775415,3.7940128373002615,0.6201270719385461,1.66161376180205,4.938427490576917,1.423293465524162,5.283573006139779,4.515817699287796,3.299840893532971,1.583940806799459,5.145676611883677,3.7975037217644285,2.1477437427820103,5.368032482202275,1.1216548522409497,4.816187409901678,4.181622827810449,5.123608360753709,1.8216915111133183,4.400044391137244,4.74330072341243,4.592676436767965,3.965775551345555,1.122144346211515,2.9823982337934165,2.62940573128035,3.9909107391663907,2.074268849011107,0.7284507301611993,3.6917878392559818,2.4534549843469673,3.0971004600010077,1.4736604057800808,2.2028021373603757,4.573250642393948,1.6152902869753283,2.140189168390027,3.5165193918895716,4.5131238183231455,2.2103942830739163,4.593305758085133,4.570311855719508,5.2975624886637,2.3697535162016834,0.9681839040857882,1.0507938399813135,4.856802721772531,1.0766901849938249,2.8057303233112156,4.347892803106083,4.055625884847416,5.113011803445795,2.4277319511258613,2.3772446827092795,1.592051054430521,1.6208946163698719,3.324387066170142,2.1912585915593557,0.8268740084538274,5.470405839135821,2.5235434816486197,2.60529941198979,1.1558370132408342,3.920139406622265,2.2965157410161576,0.5486569732497116,3.598371789422191,2.09773085753792,5.062107699426211,2.647798447447427,4.346471103419904,4.098841685701016,2.3496052573457877,0.6248009362618913,2.4700624700801193,2.312777240404789,4.20554566183363,0.7396252650156383,1.5046696432211317,2.1538102533042824,3.145846170746947,0.9126890602176181,5.4160470656827195,2.1072657653680205,3.1876816642134314,4.814615723189635],"mu":[8.730318890361664,4.809504080408425,8.385371165489456,8.704352008396507,7.320168440156022,5.440248732854268,0.8085706457806159,7.607597787908723,3.7263923347005994,8.330015185458358,5.8450313687739115,4.509781281164594,9.03091617370392,0.7415570318665228,2.1424784486671995,5.882105700306841,0.7085787274642348,4.903357742383686,0.5286886662319574,6.589442736635727,6.171648640911516,10.37068122975021,4.5262438950554005,6.856548103783643,8.55336359855843,1.2220288944423714,6.506446558786692,7.918642863512814,4.758716011741414,4.634763268139105,1.0832958388409237,10.288364800516485,1.5133710448680944,1.022410554156707,7.215396550160252,4.5460226921561295,0.722749196440859,4.977000708339358,1.1902872523856585,8.974861725156826,0.6414177796996585,3.663502579098918,6.163792859583731,4.371708351827246,5.4765618690054945,4.916380729574466,1.0883476069368232,4.974374755454179,7.80514905694416,6.278188903494237,1.3537164051156032,2.7449589981292464,2.620853460615315,8.290261233002962,5.691943641148256,10.14414279467756,5.474677366849933,6.346759937336101,5.228402619406513,1.7820397345407397,10.316343113135309,5.439943466702017,4.277275031206288,9.636938202569102,4.429691688446331,10.046244786435159,0.8891464889897267,8.065214870644448,4.346382242995629,8.892906655929387,9.095635599359952,7.2731617524976855,3.8876296170260947,3.095035841331871,9.60798801055265,3.2067103461195208,1.3468268343362029,8.895999602996216,4.328120306768233,5.707112896891352,5.634684531258972,9.046649487763807,0.5473860998421949,8.525891189053423,8.056384346031312,9.751245483947484,1.7619806504801245,0.5347970792894214,3.371370691633542,1.8848157872335032,3.7003693064888483,5.320402805064984,4.533641554208023,8.452365243325282,4.143652408227114,4.688715887645365,9.893499611076287,2.516508055739906,3.326231141800226,1.772787065961154]} diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl index 8abdaad6220e..b930c494718a 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/fixtures/julia/runner.jl +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/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: log, cdf, InverseGaussian +import Distributions: logcdf, InverseGaussian import JSON """ @@ -43,7 +43,7 @@ julia> gen( x, mu, lambda, "data.json" ); function gen( x, mu, lambda, name ) z = Array{Float64}( undef, length(x) ); for i in eachindex(x) - z[ i ] = log( cdf( InverseGaussian( mu[i], lambda[i] ), x[i] ) ); + z[ i ] = logcdf( InverseGaussian( mu[i], lambda[i] ), x[i] ); end # Store data to be written to file as a collection: @@ -75,4 +75,3 @@ x = rand( 100 ) .* 15.0 .+ 0.5; mu = rand( 100 ) .* 10.0 .+ 0.5; lambda = rand( 100 ) .* 5.0 .+ 0.5; gen( x, mu, lambda, "data.json" ); - diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js index 8b8f8c6f6d02..3fbd9ddee70f 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.factory.js @@ -191,7 +191,7 @@ tape( 'the function evaluates the logcdf for `x` given parameters `mu` and `lamb if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - t.ok( isAlmostSameValue( y, expected[ i ], 70 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + t.ok( isAlmostSameValue( y, expected[ i ], 1760 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js index 25f41b057266..e31636bfd2b6 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.main.js @@ -142,7 +142,7 @@ tape( 'the function evaluates the logcdf for `x` given parameters `mu` and `lamb if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', mu: '+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - t.ok( isAlmostSameValue( y, expected[ i ], 70 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + t.ok( isAlmostSameValue( y, expected[ i ], 1760 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js index bf24920680d0..0358d3070fcb 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/test/test.native.js @@ -151,7 +151,7 @@ tape( 'the function evaluates the logcdf for `x` given parameters `mu` and `lamb if ( y === expected[i] ) { t.strictEqual( y, expected[i], 'x: '+x[i]+', mu:'+mu[i]+', lambda: '+lambda[i]+', y: '+y+', expected: '+expected[i] ); } else { - t.ok( isAlmostSameValue( y, expected[ i ], 70 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); + t.ok( isAlmostSameValue( y, expected[ i ], 1760 ), 'within tolerance. x: '+x[ i ]+'. mu: '+mu[i]+'. lambda: '+lambda[i]+'. y: '+y+'. E: '+expected[ i ]+'.' ); } } t.end(); From 15864fd4d8f24ec8c81f6773508ded1bb8283c55 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 18 Aug 2026 23:01:14 -0500 Subject: [PATCH 4/4] docs: update descriptions --- lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md | 2 +- .../@stdlib/stats/base/dists/wald/logcdf/lib/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md index a7825426cc74..841a97c2f625 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/README.md @@ -20,7 +20,7 @@ limitations under the License. # Logarithm of Cumulative Distribution Function -> [Wald][wald-distribution] distribution logarithm of [cumulative distribution function][cdf]. +> [Wald][wald-distribution] distribution natural logarithm of [cumulative distribution function][cdf].
diff --git a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js index 70d6cec3346d..058cb6fda782 100644 --- a/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js +++ b/lib/node_modules/@stdlib/stats/base/dists/wald/logcdf/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Wald distribution logarithm of cumulative distribution function (CDF). +* Wald distribution natural logarithm of cumulative distribution function (CDF). * * @module @stdlib/stats/base/dists/wald/logcdf *