@stdlib/stats-base-dists-laplace-logpdf 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
@@ -112,7 +112,7 @@ y = logpdf( 2.0, 8.0, 0.0 );
112
112
 
113
113
  #### logpdf.factory( mu, b )
114
114
 
115
- Return a `function` for evaluating the logarithm of the [PDF][pdf] for a [Laplace][laplace-distribution] distribution with parameters `mu` (location parameter) and `b > 0` (scale parameter).
115
+ Returns a `function` for evaluating the logarithm of the [PDF][pdf] for a [Laplace][laplace-distribution] distribution with parameters `mu` (location parameter) and `b > 0` (scale parameter).
116
116
 
117
117
  ```javascript
118
118
  var mylogpdf = logpdf.factory( 10.0, 2.0 );
@@ -148,21 +148,111 @@ y = mylogpdf( 12.0 );
148
148
  <!-- eslint no-undef: "error" -->
149
149
 
150
150
  ```javascript
151
- var randu = require( '@stdlib/random-base-randu' );
151
+ var uniform = require( '@stdlib/random-array-uniform' );
152
+ var logEachMap = require( '@stdlib/console-log-each-map' );
152
153
  var logpdf = require( '@stdlib/stats-base-dists-laplace-logpdf' );
153
154
 
154
- var mu;
155
- var b;
156
- var x;
157
- var y;
158
- var i;
159
-
160
- for ( i = 0; i < 100; i++ ) {
161
- x = randu() * 10.0;
162
- mu = randu() * 10.0;
163
- b = randu() * 10.0;
164
- y = logpdf( x, mu, b );
165
- console.log( 'x: %d, µ: %d, b: %d, ln(f(x;µ,b)): %d', x.toFixed( 4 ), mu.toFixed( 4 ), b.toFixed( 4 ), y.toFixed( 4 ) );
155
+ var opts = {
156
+ 'dtype': 'float64'
157
+ };
158
+ var x = uniform( 100, 0.0, 10.0, opts );
159
+ var mu = uniform( 100, 0.0, 10.0, opts );
160
+ var b = uniform( 100, 0.0, 10.0, opts );
161
+
162
+ logEachMap( 'x: %0.4f, µ: %0.4f, b: %0.4f, ln(f(x;µ,b)): %0.4f', x, mu, b, logpdf );
163
+ ```
164
+
165
+ </section>
166
+
167
+ <!-- /.examples -->
168
+
169
+ <!-- C interface documentation. -->
170
+
171
+ * * *
172
+
173
+ <section class="c">
174
+
175
+ ## C APIs
176
+
177
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
178
+
179
+ <section class="intro">
180
+
181
+ </section>
182
+
183
+ <!-- /.intro -->
184
+
185
+ <!-- C usage documentation. -->
186
+
187
+ <section class="usage">
188
+
189
+ ### Usage
190
+
191
+ ```c
192
+ #include "stdlib/stats/base/dists/laplace/logpdf.h"
193
+ ```
194
+
195
+ #### stdlib_base_dists_laplace_logpdf( x, mu, b )
196
+
197
+ Evaluates the logarithm of the probability density function (PDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a value `x`.
198
+
199
+ ```c
200
+ double out = stdlib_base_dists_laplace_logpdf( 2.0, 0.0, 1.0 );
201
+ // returns ~-2.693
202
+ ```
203
+
204
+ The function accepts the following arguments:
205
+
206
+ - **x**: `[in] double` input value.
207
+ - **mu**: `[in] double` location parameter.
208
+ - **b**: `[in] double` rate parameter.
209
+
210
+ ```c
211
+ double stdlib_base_dists_laplace_logpdf( const double x, const double mu, const double b );
212
+ ```
213
+
214
+ </section>
215
+
216
+ <!-- /.usage -->
217
+
218
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
219
+
220
+ <section class="notes">
221
+
222
+ </section>
223
+
224
+ <!-- /.notes -->
225
+
226
+ <!-- C API usage examples. -->
227
+
228
+ <section class="examples">
229
+
230
+ ### Examples
231
+
232
+ ```c
233
+ #include "stdlib/stats/base/dists/laplace/logpdf.h"
234
+ #include <stdlib.h>
235
+ #include <stdio.h>
236
+
237
+ static double random_uniform( const double min, const double max ) {
238
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
239
+ return min + ( v*(max-min) );
240
+ }
241
+
242
+ int main( void ) {
243
+ double mu;
244
+ double b;
245
+ double x;
246
+ double y;
247
+ int i;
248
+
249
+ for ( i = 0; i < 25; i++ ) {
250
+ mu = random_uniform( -5.0, 5.0 );
251
+ b = random_uniform( 0.0, 20.0 );
252
+ x = random_uniform( 0.0, 20.0 );
253
+ y = stdlib_base_dists_laplace_logpdf( x, mu, b );
254
+ printf( "x: %lf, µ: %lf, b: %lf, ln(f(x;µ,b)): %lf\n", x, mu, b, y );
255
+ }
166
256
  }
167
257
  ```
168
258
 
@@ -170,6 +260,10 @@ for ( i = 0; i < 100; i++ ) {
170
260
 
171
261
  <!-- /.examples -->
172
262
 
263
+ </section>
264
+
265
+ <!-- /.c -->
266
+
173
267
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
174
268
 
175
269
  <section class="related">
@@ -204,7 +298,7 @@ See [LICENSE][stdlib-license].
204
298
 
205
299
  ## Copyright
206
300
 
207
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
301
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
208
302
 
209
303
  </section>
210
304
 
@@ -217,8 +311,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
217
311
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-laplace-logpdf.svg
218
312
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-laplace-logpdf
219
313
 
220
- [test-image]: https://github.com/stdlib-js/stats-base-dists-laplace-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
221
- [test-url]: https://github.com/stdlib-js/stats-base-dists-laplace-logpdf/actions/workflows/test.yml?query=branch:v0.2.2
314
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-laplace-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
315
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-laplace-logpdf/actions/workflows/test.yml?query=branch:v0.3.0
222
316
 
223
317
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-laplace-logpdf/main.svg
224
318
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-laplace-logpdf?branch=main
@@ -230,8 +324,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
230
324
 
231
325
  -->
232
326
 
233
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
234
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
327
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
328
+ [chat-url]: https://stdlib.zulipchat.com
235
329
 
236
330
  [stdlib]: https://github.com/stdlib-js/stdlib
237
331
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference path="../docs/types/index.d.ts" />
2
- import logPDF from '../docs/types/index';
3
- export = logPDF;
2
+ import logpdf from '../docs/types/index';
3
+ export = logpdf;
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 abs = require( '@stdlib/math-base-special-abs' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the probability density function (PDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a 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 logPDF\n*\n* @example\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.693\n*\n* @example\n* var y = logpdf( -1.0, 2.0, 3.0 );\n* // returns ~-2.792\n*\n* @example\n* var y = logpdf( 2.5, 2.0, 3.0 );\n* // returns ~-1.958\n*\n* @example\n* var y = logpdf( NaN, 0.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, 0.0, NaN );\n* // returns NaN\n*\n* @example\n* // Negative scale parameter:\n* var y = logpdf( 2.0, 0.0, -1.0 );\n* // returns NaN\n*/\nfunction logpdf( 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\treturn -( abs( z ) + ln( 2.0 * b ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = logpdf;\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 abs = require( '@stdlib/math-base-special-abs' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the logarithm of the probability density function (PDF) 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} logPDF\n*\n* @example\n* var logpdf = factory( 10.0, 2.0 );\n*\n* var y = logpdf( 10.0 );\n* // returns ~-1.386\n*\n* y = logpdf( 5.0 );\n* // returns ~-3.886\n*\n* y = logpdf( 12.0 );\n* // returns ~-2.386\n*/\nfunction factory( mu, b ) {\n\tif (\n\t\tisnan( mu ) ||\n\t\tisnan( b ) ||\n\t\tb <= 0.0\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the logarithm of the probability density function (PDF) for a Laplace distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logarithm of PDF\n\t*\n\t* @example\n\t* var y = logpdf( -3.14 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( 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\treturn -( abs( z ) + ln( 2.0 * b ) );\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 probability density function (PDF).\n*\n* @module @stdlib/stats-base-dists-laplace-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-laplace-logpdf' );\n*\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.688\n*\n* var mylogPDF = logpdf.factory( 10.0, 2.0 );\n* y = mylogPDF( 10.0 );\n* // returns -1.386\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 abs = require( '@stdlib/math-base-special-abs' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the probability density function (PDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a 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 logPDF\n*\n* @example\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.693\n*\n* @example\n* var y = logpdf( -1.0, 2.0, 3.0 );\n* // returns ~-2.792\n*\n* @example\n* var y = logpdf( 2.5, 2.0, 3.0 );\n* // returns ~-1.958\n*\n* @example\n* var y = logpdf( NaN, 0.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, 0.0, NaN );\n* // returns NaN\n*\n* @example\n* // Negative scale parameter:\n* var y = logpdf( 2.0, 0.0, -1.0 );\n* // returns NaN\n*/\nfunction logpdf( 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\treturn -( abs( z ) + ln( 2.0 * b ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = logpdf;\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 abs = require( '@stdlib/math-base-special-abs' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the logarithm of the probability density function (PDF) 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} logPDF\n*\n* @example\n* var logpdf = factory( 10.0, 2.0 );\n*\n* var y = logpdf( 10.0 );\n* // returns ~-1.386\n*\n* y = logpdf( 5.0 );\n* // returns ~-3.886\n*\n* y = logpdf( 12.0 );\n* // returns ~-2.386\n*/\nfunction factory( mu, b ) {\n\tif (\n\t\tisnan( mu ) ||\n\t\tisnan( b ) ||\n\t\tb <= 0.0\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the logarithm of the probability density function (PDF) for a Laplace distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logarithm of PDF\n\t*\n\t* @example\n\t* var y = logpdf( -3.14 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( 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\treturn -( abs( z ) + ln( 2.0 * b ) );\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 probability density function (PDF).\n*\n* @module @stdlib/stats-base-dists-laplace-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-laplace-logpdf' );\n*\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.693\n*\n* var mylogPDF = logpdf.factory( 10.0, 2.0 );\n* y = mylogPDF( 10.0 );\n* // returns ~-1.386\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,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EA0CjD,SAASC,EAAQC,EAAGC,EAAIC,EAAI,CAC3B,IAAIC,EACJ,OACCP,EAAOI,CAAE,GACTJ,EAAOK,CAAG,GACVL,EAAOM,CAAE,GACTA,GAAK,EAEE,KAERC,GAAMH,EAAIC,GAAOC,EACV,EAAGL,EAAKM,CAAE,EAAIL,EAAI,EAAMI,CAAE,GAClC,CAKAP,EAAO,QAAUI,ICnFjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAwBjD,SAASC,EAASC,EAAIC,EAAI,CACzB,GACCL,EAAOI,CAAG,GACVJ,EAAOK,CAAE,GACTA,GAAK,EAEL,OAAON,EAAkB,GAAI,EAE9B,OAAOO,EAaP,SAASA,EAAQC,EAAI,CACpB,IAAIC,EACJ,OAAKR,EAAOO,CAAE,EACN,KAERC,GAAMD,EAAIH,GAAOC,EACV,EAAGJ,EAAKO,CAAE,EAAIN,EAAI,EAAMG,CAAE,GAClC,CACD,CAKAP,EAAO,QAAUK,IC7CjB,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", "abs", "ln", "logpdf", "x", "mu", "b", "z", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "isnan", "abs", "ln", "factory", "mu", "b", "logpdf", "x", "z", "setReadOnly", "main", "factory"]
7
7
  }
@@ -105,15 +105,15 @@ interface LogPDF {
105
105
  *
106
106
  * @example
107
107
  * var y = logpdf( 2.0, 0.0, 1.0 );
108
- * // returns ~-2.688
108
+ * // returns ~-2.693
109
109
  *
110
110
  * var mylogpdf = logpdf.factory( 10.0, 2.0 );
111
111
  * y = mylogpdf( 10.0 );
112
- * // returns -1.386
112
+ * // returns ~-1.386
113
113
  */
114
- declare var logPDF: LogPDF;
114
+ declare var logpdf: LogPDF;
115
115
 
116
116
 
117
117
  // EXPORTS //
118
118
 
119
- export = logPDF;
119
+ export = logpdf;
@@ -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_LOGPDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_LAPLACE_LOGPDF_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
+ * Evaluates the logarithm of the probability density function (PDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a value `x`.
31
+ */
32
+ double stdlib_base_dists_laplace_logpdf( const double x, const double mu, const double b );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_LAPLACE_LOGPDF_H
package/lib/index.js CHANGED
@@ -27,11 +27,11 @@
27
27
  * var logpdf = require( '@stdlib/stats-base-dists-laplace-logpdf' );
28
28
  *
29
29
  * var y = logpdf( 2.0, 0.0, 1.0 );
30
- * // returns ~-2.688
30
+ * // returns ~-2.693
31
31
  *
32
32
  * var mylogPDF = logpdf.factory( 10.0, 2.0 );
33
33
  * y = mylogPDF( 10.0 );
34
- * // returns -1.386
34
+ * // returns ~-1.386
35
35
  */
36
36
 
37
37
  // MODULES //
package/lib/native.js ADDED
@@ -0,0 +1,73 @@
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 probability density function (PDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a 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 logPDF
36
+ *
37
+ * @example
38
+ * var y = logpdf( 2.0, 0.0, 1.0 );
39
+ * // returns ~-2.693
40
+ *
41
+ * @example
42
+ * var y = logpdf( -1.0, 2.0, 3.0 );
43
+ * // returns ~-2.792
44
+ *
45
+ * @example
46
+ * var y = logpdf( 2.5, 2.0, 3.0 );
47
+ * // returns ~-1.958
48
+ *
49
+ * @example
50
+ * var y = logpdf( NaN, 0.0, 1.0 );
51
+ * // returns NaN
52
+ *
53
+ * @example
54
+ * var y = logpdf( 0.0, NaN, 1.0 );
55
+ * // returns NaN
56
+ *
57
+ * @example
58
+ * var y = logpdf( 0.0, 0.0, NaN );
59
+ * // returns NaN
60
+ *
61
+ * @example
62
+ * // Negative scale parameter:
63
+ * var y = logpdf( 2.0, 0.0, -1.0 );
64
+ * // returns NaN
65
+ */
66
+ function logpdf( x, mu, b ) {
67
+ return addon( x, mu, b );
68
+ }
69
+
70
+
71
+ // EXPORTS //
72
+
73
+ module.exports = logpdf;
package/manifest.json ADDED
@@ -0,0 +1,83 @@
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-abs",
44
+ "@stdlib/math-base-special-ln"
45
+ ]
46
+ },
47
+ {
48
+ "task": "benchmark",
49
+ "wasm": false,
50
+ "src": [
51
+ "./src/main.c"
52
+ ],
53
+ "include": [
54
+ "./include"
55
+ ],
56
+ "libraries": [],
57
+ "libpath": [],
58
+ "dependencies": [
59
+ "@stdlib/math-base-assert-is-nan",
60
+ "@stdlib/constants-float64-eps",
61
+ "@stdlib/math-base-special-abs",
62
+ "@stdlib/math-base-special-ln"
63
+ ]
64
+ },
65
+ {
66
+ "task": "examples",
67
+ "wasm": false,
68
+ "src": [
69
+ "./src/main.c"
70
+ ],
71
+ "include": [
72
+ "./include"
73
+ ],
74
+ "libraries": [],
75
+ "libpath": [],
76
+ "dependencies": [
77
+ "@stdlib/math-base-assert-is-nan",
78
+ "@stdlib/math-base-special-abs",
79
+ "@stdlib/math-base-special-ln"
80
+ ]
81
+ }
82
+ ]
83
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-laplace-logpdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Laplace distribution logarithm of probability density function (PDF).",
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",
@@ -31,10 +34,12 @@
31
34
  },
32
35
  "dependencies": {
33
36
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
34
- "@stdlib/math-base-special-abs": "^0.2.1",
37
+ "@stdlib/math-base-napi-ternary": "^0.3.1",
38
+ "@stdlib/math-base-special-abs": "^0.2.2",
35
39
  "@stdlib/math-base-special-ln": "^0.2.4",
36
40
  "@stdlib/utils-constant-function": "^0.2.2",
37
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
41
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
42
+ "@stdlib/utils-library-manifest": "^0.2.3"
38
43
  },
39
44
  "devDependencies": {},
40
45
  "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/logpdf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_laplace_logpdf )
package/src/main.c ADDED
@@ -0,0 +1,48 @@
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/logpdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/abs.h"
22
+ #include "stdlib/math/base/special/ln.h"
23
+
24
+ /**
25
+ * Evaluates the logarithm of the probability density function (PDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a value `x`.
26
+ *
27
+ * @param x input value
28
+ * @param mu location parameter
29
+ * @param b scale parameter
30
+ * @return evaluated logPDF
31
+ *
32
+ * @example
33
+ * double y = stdlib_base_dists_laplace_logpdf( 2.0, 0.0, 1.0 );
34
+ * // returns ~-2.693
35
+ */
36
+ double stdlib_base_dists_laplace_logpdf( const double x, const double mu, const double b ) {
37
+ double z;
38
+ if (
39
+ stdlib_base_is_nan( x ) ||
40
+ stdlib_base_is_nan( mu ) ||
41
+ stdlib_base_is_nan( b ) ||
42
+ b <= 0.0
43
+ ) {
44
+ return 0.0/0.0; // NaN
45
+ }
46
+ z = ( x - mu ) / b;
47
+ return -( stdlib_base_abs( z ) + stdlib_base_ln( 2.0 * b ) );
48
+ }