@stdlib/stats-base-dists-laplace-logcdf 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -142,21 +142,111 @@ y = mylogcdf( 4.0 );
142
142
  <!-- eslint no-undef: "error" -->
143
143
 
144
144
  ```javascript
145
- var randu = require( '@stdlib/random-base-randu' );
145
+ var uniform = require( '@stdlib/random-array-uniform' );
146
+ var logEachMap = require( '@stdlib/console-log-each-map' );
146
147
  var logcdf = require( '@stdlib/stats-base-dists-laplace-logcdf' );
147
148
 
148
- var mu;
149
- var b;
150
- var x;
151
- var y;
152
- var i;
153
-
154
- for ( i = 0; i < 100; i++ ) {
155
- x = randu() * 10.0;
156
- mu = randu() * 10.0;
157
- b = randu() * 10.0;
158
- y = logcdf( x, mu, b );
159
- console.log( 'x: %d, µ: %d, b: %d, ln(F(x;µ,b)): %d', x.toFixed( 4 ), mu.toFixed( 4 ), b.toFixed( 4 ), y.toFixed( 4 ) );
149
+ var opts = {
150
+ 'dtype': 'float64'
151
+ };
152
+ var x = uniform( 100, 0.0, 10.0, opts );
153
+ var mu = uniform( 100, 0.0, 10.0, opts );
154
+ var b = uniform( 100, 0.0, 10.0, opts );
155
+
156
+ logEachMap( 'x: %0.4f, µ: %0.4f, b: %0.4f, ln(F(x;µ,b)): %0.4f', x, mu, b, logcdf );
157
+ ```
158
+
159
+ </section>
160
+
161
+ <!-- /.examples -->
162
+
163
+ <!-- C interface documentation. -->
164
+
165
+ * * *
166
+
167
+ <section class="c">
168
+
169
+ ## C APIs
170
+
171
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
172
+
173
+ <section class="intro">
174
+
175
+ </section>
176
+
177
+ <!-- /.intro -->
178
+
179
+ <!-- C usage documentation. -->
180
+
181
+ <section class="usage">
182
+
183
+ ### Usage
184
+
185
+ ```c
186
+ #include "stdlib/stats/base/dists/laplace/logcdf.h"
187
+ ```
188
+
189
+ #### stdlib_base_dists_laplace_logcdf( x, mu, b )
190
+
191
+ Evaluates the logarithm of the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a value `x`.
192
+
193
+ ```c
194
+ double out = stdlib_base_dists_laplace_logcdf( 2.0, 0.0, 1.0 );
195
+ // returns ~-0.07
196
+ ```
197
+
198
+ The function accepts the following arguments:
199
+
200
+ - **x**: `[in] double` input value.
201
+ - **mu**: `[in] double` location parameter.
202
+ - **b**: `[in] double` rate parameter.
203
+
204
+ ```c
205
+ double stdlib_base_dists_laplace_logcdf( const double x, const double mu, const double b );
206
+ ```
207
+
208
+ </section>
209
+
210
+ <!-- /.usage -->
211
+
212
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
213
+
214
+ <section class="notes">
215
+
216
+ </section>
217
+
218
+ <!-- /.notes -->
219
+
220
+ <!-- C API usage examples. -->
221
+
222
+ <section class="examples">
223
+
224
+ ### Examples
225
+
226
+ ```c
227
+ #include "stdlib/stats/base/dists/laplace/logcdf.h"
228
+ #include <stdlib.h>
229
+ #include <stdio.h>
230
+
231
+ static double random_uniform( const double min, const double max ) {
232
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
233
+ return min + ( v*(max-min) );
234
+ }
235
+
236
+ int main( void ) {
237
+ double mu;
238
+ double b;
239
+ double x;
240
+ double y;
241
+ int i;
242
+
243
+ for ( i = 0; i < 25; i++ ) {
244
+ mu = random_uniform( -5.0, 5.0 );
245
+ b = random_uniform( 0.0, 20.0 );
246
+ x = random_uniform( 0.0, 20.0 );
247
+ y = stdlib_base_dists_laplace_logcdf( x, mu, b );
248
+ printf( "x: %lf, µ: %lf, b: %lf, ln(F(x;µ,b)): %lf\n", x, mu, b, y );
249
+ }
160
250
  }
161
251
  ```
162
252
 
@@ -164,6 +254,10 @@ for ( i = 0; i < 100; i++ ) {
164
254
 
165
255
  <!-- /.examples -->
166
256
 
257
+ </section>
258
+
259
+ <!-- /.c -->
260
+
167
261
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
168
262
 
169
263
  <section class="related">
@@ -198,7 +292,7 @@ See [LICENSE][stdlib-license].
198
292
 
199
293
  ## Copyright
200
294
 
201
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
295
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
202
296
 
203
297
  </section>
204
298
 
@@ -211,8 +305,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
211
305
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-laplace-logcdf.svg
212
306
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-laplace-logcdf
213
307
 
214
- [test-image]: https://github.com/stdlib-js/stats-base-dists-laplace-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
215
- [test-url]: https://github.com/stdlib-js/stats-base-dists-laplace-logcdf/actions/workflows/test.yml?query=branch:v0.2.2
308
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-laplace-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
309
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-laplace-logcdf/actions/workflows/test.yml?query=branch:v0.3.0
216
310
 
217
311
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-laplace-logcdf/main.svg
218
312
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-laplace-logcdf?branch=main
@@ -224,8 +318,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
224
318
 
225
319
  -->
226
320
 
227
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
228
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
321
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
322
+ [chat-url]: https://stdlib.zulipchat.com
229
323
 
230
324
  [stdlib]: https://github.com/stdlib-js/stdlib
231
325
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference path="../docs/types/index.d.ts" />
2
- import logCDF from '../docs/types/index';
3
- export = logCDF;
2
+ import logcdf from '../docs/types/index';
3
+ export = logcdf;
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../lib/main.js", "../lib/factory.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar LNHALF = require( '@stdlib/constants-float64-ln-half' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at value `x`.\n*\n* @param {number} x - input value\n* @param {number} mu - location parameter\n* @param {PositiveNumber} b - scale parameter\n* @returns {number} evaluated logarithm of CDF\n*\n* @example\n* var y = logcdf( 2.0, 0.0, 1.0 );\n* // returns ~-0.07\n*\n* @example\n* var y = logcdf( 5.0, 10.0, 3.0 );\n* // returns ~-2.36\n*\n* @example\n* var y = logcdf( NaN, 0.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logcdf( 2, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logcdf( 2.0, 0.0, NaN );\n* // returns NaN\n*\n* @example\n* // Negative scale parameter:\n* var y = logcdf( 2.0, 0.0, -1.0 );\n* // returns NaN\n*/\nfunction logcdf( x, mu, b ) {\n\tvar z;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( mu ) ||\n\t\tisnan( b ) ||\n\t\tb <= 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tz = ( x - mu ) / b;\n\tif ( x < mu ) {\n\t\treturn LNHALF + z;\n\t}\n\treturn LNHALF + log1p( -expm1( -z ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = logcdf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar LNHALF = require( '@stdlib/constants-float64-ln-half' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the logarithm of the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b`.\n*\n* @param {number} mu - location parameter\n* @param {PositiveNumber} b - scale parameter\n* @returns {Function} logCDF\n*\n* @example\n* var logcdf = factory( 3.0, 1.5 );\n*\n* var y = logcdf( 1.0 );\n* // returns ~-2.026\n*\n* y = logcdf( 4.0 );\n* // returns ~-0.297\n*/\nfunction factory( mu, b ) {\n\tif ( isnan( mu ) || isnan( b ) || b <= 0.0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\treturn logcdf;\n\n\t/**\n\t* Evaluates the logarithm of the cumulative distribution function (CDF) for a Laplace distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logCDF\n\t*\n\t* @example\n\t* var y = logcdf( 2.0 );\n\t* // returns <number>\n\t*/\n\tfunction logcdf( x ) {\n\t\tvar z;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tz = ( x - mu ) / b;\n\t\tif ( x < mu ) {\n\t\t\treturn LNHALF + z;\n\t\t}\n\t\treturn LNHALF + log1p( -expm1( -z ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Laplace distribution logarithm of cumulative distribution function (CDF).\n*\n* @module @stdlib/stats-base-dists-laplace-logcdf\n*\n* @example\n* var logcdf = require( '@stdlib/stats-base-dists-laplace-logcdf' );\n*\n* var y = logcdf( 10.0, 0.0, 3.0 );\n* // returns ~-0.018\n*\n* y = logcdf( 0.0, 0.0, 3.0 );\n* // returns ~-0.693\n*\n* var mylogcdf = logcdf.factory( 2.0, 3.0 );\n* y = mylogcdf( 10.0 );\n* // returns ~-0.036\n*\n* y = mylogcdf( 2.0 );\n* // returns ~-0.693\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar LNHALF = require( '@stdlib/constants-float64-ln-half' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at value `x`.\n*\n* @param {number} x - input value\n* @param {number} mu - location parameter\n* @param {PositiveNumber} b - scale parameter\n* @returns {number} evaluated logarithm of CDF\n*\n* @example\n* var y = logcdf( 2.0, 0.0, 1.0 );\n* // returns ~-0.07\n*\n* @example\n* var y = logcdf( 5.0, 10.0, 3.0 );\n* // returns ~-2.36\n*\n* @example\n* var y = logcdf( NaN, 0.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logcdf( 2, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logcdf( 2.0, 0.0, NaN );\n* // returns NaN\n*\n* @example\n* // Negative scale parameter:\n* var y = logcdf( 2.0, 0.0, -1.0 );\n* // returns NaN\n*/\nfunction logcdf( x, mu, b ) {\n\tvar z;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( mu ) ||\n\t\tisnan( b ) ||\n\t\tb <= 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tz = ( x - mu ) / b;\n\tif ( x < mu ) {\n\t\treturn LNHALF + z;\n\t}\n\treturn LNHALF + log1p( -expm1( -z ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = logcdf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar LNHALF = require( '@stdlib/constants-float64-ln-half' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the logarithm of the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b`.\n*\n* @param {number} mu - location parameter\n* @param {PositiveNumber} b - scale parameter\n* @returns {Function} logCDF\n*\n* @example\n* var logcdf = factory( 3.0, 1.5 );\n*\n* var y = logcdf( 1.0 );\n* // returns ~-2.026\n*\n* y = logcdf( 4.0 );\n* // returns ~-0.297\n*/\nfunction factory( mu, b ) {\n\tif ( isnan( mu ) || isnan( b ) || b <= 0.0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\treturn logcdf;\n\n\t/**\n\t* Evaluates the logarithm of the cumulative distribution function (CDF) for a Laplace distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logCDF\n\t*\n\t* @example\n\t* var y = logcdf( 2.0 );\n\t* // returns <number>\n\t*/\n\tfunction logcdf( x ) {\n\t\tvar z;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tz = ( x - mu ) / b;\n\t\tif ( x < mu ) {\n\t\t\treturn LNHALF + z;\n\t\t}\n\t\treturn LNHALF + log1p( -expm1( -z ) );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Laplace distribution logarithm of cumulative distribution function (CDF).\n*\n* @module @stdlib/stats-base-dists-laplace-logcdf\n*\n* @example\n* var logcdf = require( '@stdlib/stats-base-dists-laplace-logcdf' );\n*\n* var y = logcdf( 10.0, 0.0, 3.0 );\n* // returns ~-0.018\n*\n* y = logcdf( 0.0, 0.0, 3.0 );\n* // returns ~-0.693\n*\n* var mylogcdf = logcdf.factory( 2.0, 3.0 );\n* y = mylogcdf( 10.0 );\n* // returns ~-0.035\n*\n* y = mylogcdf( 2.0 );\n* // returns ~-0.693\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
5
  "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAS,QAAS,mCAAoC,EAsC1D,SAASC,EAAQC,EAAGC,EAAIC,EAAI,CAC3B,IAAIC,EACJ,OACCR,EAAOK,CAAE,GACTL,EAAOM,CAAG,GACVN,EAAOO,CAAE,GACTA,GAAK,EAEE,KAERC,GAAMH,EAAIC,GAAOC,EACZF,EAAIC,EACDH,EAASK,EAEVL,EAASD,EAAO,CAACD,EAAO,CAACO,CAAE,CAAE,EACrC,CAKAT,EAAO,QAAUK,ICnFjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAS,QAAS,mCAAoC,EAqB1D,SAASC,EAASC,EAAIC,EAAI,CACzB,GAAKN,EAAOK,CAAG,GAAKL,EAAOM,CAAE,GAAKA,GAAK,EACtC,OAAOP,EAAkB,GAAI,EAE9B,OAAOQ,EAaP,SAASA,EAAQC,EAAI,CACpB,IAAIC,EACJ,OAAKT,EAAOQ,CAAE,EACN,KAERC,GAAMD,EAAIH,GAAOC,EACZE,EAAIH,EACDF,EAASM,EAEVN,EAASD,EAAO,CAACD,EAAO,CAACQ,CAAE,CAAE,EACrC,CACD,CAKAX,EAAO,QAAUM,ICpCjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
6
  "names": ["require_main", "__commonJSMin", "exports", "module", "isnan", "expm1", "log1p", "LNHALF", "logcdf", "x", "mu", "b", "z", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "isnan", "expm1", "log1p", "LNHALF", "factory", "mu", "b", "logcdf", "x", "z", "setReadOnly", "main", "factory"]
7
7
  }
@@ -105,14 +105,14 @@ interface LogCDF {
105
105
  *
106
106
  * var mylogcdf = logcdf.factory( 2.0, 3.0 );
107
107
  * y = mylogcdf( 10.0 );
108
- * // returns ~-0.036
108
+ * // returns ~-0.035
109
109
  *
110
110
  * y = mylogcdf( 2.0 );
111
111
  * // returns ~-0.693
112
112
  */
113
- declare var logCDF: LogCDF;
113
+ declare var logcdf: LogCDF;
114
114
 
115
115
 
116
116
  // EXPORTS //
117
117
 
118
- export = logCDF;
118
+ export = logcdf;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #ifndef STDLIB_STATS_BASE_DISTS_LAPLACE_LOGCDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_LAPLACE_LOGCDF_H
21
+
22
+ /*
23
+ * If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
24
+ */
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ /**
30
+ * Returns the logarithm of the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a value `x`.
31
+ */
32
+ double stdlib_base_dists_laplace_logcdf( const double x, const double mu, const double b );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_LAPLACE_LOGCDF_H
package/lib/index.js CHANGED
@@ -34,7 +34,7 @@
34
34
  *
35
35
  * var mylogcdf = logcdf.factory( 2.0, 3.0 );
36
36
  * y = mylogcdf( 10.0 );
37
- * // returns ~-0.036
37
+ * // returns ~-0.035
38
38
  *
39
39
  * y = mylogcdf( 2.0 );
40
40
  * // returns ~-0.693
package/lib/native.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var addon = require( './../src/addon.node' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Evaluates the logarithm of the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at value `x`.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {number} mu - location parameter
34
+ * @param {PositiveNumber} b - scale parameter
35
+ * @returns {number} evaluated logarithm of CDF
36
+ *
37
+ * @example
38
+ * var y = logcdf( 2.0, 0.0, 1.0 );
39
+ * // returns ~-0.07
40
+ *
41
+ * @example
42
+ * var y = logcdf( 5.0, 10.0, 3.0 );
43
+ * // returns ~-2.36
44
+ *
45
+ * @example
46
+ * var y = logcdf( NaN, 0.0, 1.0 );
47
+ * // returns NaN
48
+ *
49
+ * @example
50
+ * var y = logcdf( 2, NaN, 1.0 );
51
+ * // returns NaN
52
+ *
53
+ * @example
54
+ * var y = logcdf( 2.0, 0.0, NaN );
55
+ * // returns NaN
56
+ *
57
+ * @example
58
+ * // Negative scale parameter:
59
+ * var y = logcdf( 2.0, 0.0, -1.0 );
60
+ * // returns NaN
61
+ */
62
+ function logcdf( x, mu, b ) {
63
+ return addon( x, mu, b );
64
+ }
65
+
66
+
67
+ // EXPORTS //
68
+
69
+ module.exports = logcdf;
package/manifest.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "options": {
3
+ "task": "build",
4
+ "wasm": false
5
+ },
6
+ "fields": [
7
+ {
8
+ "field": "src",
9
+ "resolve": true,
10
+ "relative": true
11
+ },
12
+ {
13
+ "field": "include",
14
+ "resolve": true,
15
+ "relative": true
16
+ },
17
+ {
18
+ "field": "libraries",
19
+ "resolve": false,
20
+ "relative": false
21
+ },
22
+ {
23
+ "field": "libpath",
24
+ "resolve": true,
25
+ "relative": false
26
+ }
27
+ ],
28
+ "confs": [
29
+ {
30
+ "task": "build",
31
+ "wasm": false,
32
+ "src": [
33
+ "./src/main.c"
34
+ ],
35
+ "include": [
36
+ "./include"
37
+ ],
38
+ "libraries": [],
39
+ "libpath": [],
40
+ "dependencies": [
41
+ "@stdlib/math-base-napi-ternary",
42
+ "@stdlib/math-base-assert-is-nan",
43
+ "@stdlib/math-base-special-log1p",
44
+ "@stdlib/constants-float64-ln-half",
45
+ "@stdlib/math-base-special-expm1"
46
+ ]
47
+ },
48
+ {
49
+ "task": "benchmark",
50
+ "wasm": false,
51
+ "src": [
52
+ "./src/main.c"
53
+ ],
54
+ "include": [
55
+ "./include"
56
+ ],
57
+ "libraries": [],
58
+ "libpath": [],
59
+ "dependencies": [
60
+ "@stdlib/math-base-assert-is-nan",
61
+ "@stdlib/math-base-special-log1p",
62
+ "@stdlib/constants-float64-ln-half",
63
+ "@stdlib/constants-float64-eps",
64
+ "@stdlib/math-base-special-expm1"
65
+ ]
66
+ },
67
+ {
68
+ "task": "examples",
69
+ "wasm": false,
70
+ "src": [
71
+ "./src/main.c"
72
+ ],
73
+ "include": [
74
+ "./include"
75
+ ],
76
+ "libraries": [],
77
+ "libpath": [],
78
+ "dependencies": [
79
+ "@stdlib/math-base-assert-is-nan",
80
+ "@stdlib/math-base-special-log1p",
81
+ "@stdlib/constants-float64-ln-half",
82
+ "@stdlib/math-base-special-expm1"
83
+ ]
84
+ }
85
+ ]
86
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-laplace-logcdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Laplace distribution logarithm of cumulative distribution function (CDF).",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -14,9 +14,12 @@
14
14
  }
15
15
  ],
16
16
  "main": "./lib",
17
+ "gypfile": false,
17
18
  "directories": {
18
19
  "doc": "./docs",
20
+ "include": "./include",
19
21
  "lib": "./lib",
22
+ "src": "./src",
20
23
  "dist": "./dist"
21
24
  },
22
25
  "types": "./docs/types",
@@ -32,10 +35,12 @@
32
35
  "dependencies": {
33
36
  "@stdlib/constants-float64-ln-half": "^0.2.2",
34
37
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
35
- "@stdlib/math-base-special-expm1": "^0.2.2",
38
+ "@stdlib/math-base-napi-ternary": "^0.3.1",
39
+ "@stdlib/math-base-special-expm1": "^0.2.3",
36
40
  "@stdlib/math-base-special-log1p": "^0.2.3",
37
41
  "@stdlib/utils-constant-function": "^0.2.2",
38
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
42
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
43
+ "@stdlib/utils-library-manifest": "^0.2.3"
39
44
  },
40
45
  "devDependencies": {},
41
46
  "engines": {
package/src/addon.c ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include "stdlib/stats/base/dists/laplace/logcdf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_laplace_logcdf )
package/src/main.c ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include "stdlib/stats/base/dists/laplace/logcdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/expm1.h"
22
+ #include "stdlib/math/base/special/log1p.h"
23
+ #include "stdlib/constants/float64/ln_half.h"
24
+
25
+ /**
26
+ * Returns the logarithm of the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a value `x`.
27
+ *
28
+ * @param x input value
29
+ * @param mu location parameter
30
+ * @param b scale parameter
31
+ * @return evaluated logarithm of CDF
32
+ *
33
+ * @example
34
+ * double y = stdlib_base_dists_laplace_logcdf( 2.0, 0.0, 1.0 );
35
+ * // returns ~-0.07
36
+ */
37
+ double stdlib_base_dists_laplace_logcdf( const double x, const double mu, const double b ) {
38
+ double z;
39
+ if (
40
+ stdlib_base_is_nan( x ) ||
41
+ stdlib_base_is_nan( mu ) ||
42
+ stdlib_base_is_nan( b ) ||
43
+ b <= 0.0
44
+ ) {
45
+ return 0.0/0.0; // NaN
46
+ }
47
+ z = ( x - mu ) / b;
48
+ if ( x < mu ) {
49
+ return STDLIB_CONSTANT_FLOAT64_LN_HALF + z;
50
+ }
51
+ return STDLIB_CONSTANT_FLOAT64_LN_HALF + stdlib_base_log1p( -stdlib_base_expm1( -z ) );
52
+ }