@stdlib/stats-base-dists-logistic-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
@@ -149,21 +149,111 @@ y = mylogpdf( 5.0 );
149
149
  <!-- eslint no-undef: "error" -->
150
150
 
151
151
  ```javascript
152
- var randu = require( '@stdlib/random-base-randu' );
152
+ var uniform = require( '@stdlib/random-array-uniform' );
153
+ var logEachMap = require( '@stdlib/console-log-each-map' );
153
154
  var logpdf = require( '@stdlib/stats-base-dists-logistic-logpdf' );
154
155
 
155
- var mu;
156
- var s;
157
- var x;
158
- var y;
159
- var i;
160
-
161
- for ( i = 0; i < 10; i++ ) {
162
- x = randu() * 10.0;
163
- mu = randu() * 10.0;
164
- s = randu() * 10.0;
165
- y = logpdf( x, mu, s );
166
- console.log( 'x: %d, µ: %d, s: %d, ln(f(x;µ,s)): %d', x, mu, s, y );
156
+ var opts = {
157
+ 'dtype': 'float64'
158
+ };
159
+ var x = uniform( 10, 0.0, 10.0, opts );
160
+ var mu = uniform( 10, 0.0, 10.0, opts );
161
+ var s = uniform( 10, 0.0, 10.0, opts );
162
+
163
+ logEachMap( 'x: %0.4f, µ: %0.4f, s: %0.4f, ln(f(x;µ,s)): %0.4f', x, mu, s, logpdf );
164
+ ```
165
+
166
+ </section>
167
+
168
+ <!-- /.examples -->
169
+
170
+ <!-- C interface documentation. -->
171
+
172
+ * * *
173
+
174
+ <section class="c">
175
+
176
+ ## C APIs
177
+
178
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
179
+
180
+ <section class="intro">
181
+
182
+ </section>
183
+
184
+ <!-- /.intro -->
185
+
186
+ <!-- C usage documentation. -->
187
+
188
+ <section class="usage">
189
+
190
+ ### Usage
191
+
192
+ ```c
193
+ #include "stdlib/stats/base/dists/logistic/logpdf.h"
194
+ ```
195
+
196
+ #### stdlib_base_dists_logistic_logpdf( x, mu, s )
197
+
198
+ Evaluates the logarithm of the probability density function (PDF) for a logistic distribution with location parameter `mu` and scale parameter `s` at a value `x`.
199
+
200
+ ```c
201
+ double out = stdlib_base_dists_logistic_logpdf( 2.0, 0.0, 1.0 );
202
+ // returns ~-2.254
203
+ ```
204
+
205
+ The function accepts the following arguments:
206
+
207
+ - **x**: `[in] double` input value.
208
+ - **mu**: `[in] double` location parameter.
209
+ - **s**: `[in] double` scale parameter.
210
+
211
+ ```c
212
+ double stdlib_base_dists_logistic_logpdf( const double x, const double mu, const double s );
213
+ ```
214
+
215
+ </section>
216
+
217
+ <!-- /.usage -->
218
+
219
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
220
+
221
+ <section class="notes">
222
+
223
+ </section>
224
+
225
+ <!-- /.notes -->
226
+
227
+ <!-- C API usage examples. -->
228
+
229
+ <section class="examples">
230
+
231
+ ### Examples
232
+
233
+ ```c
234
+ #include "stdlib/stats/base/dists/logistic/logpdf.h"
235
+ #include <stdlib.h>
236
+ #include <stdio.h>
237
+
238
+ static double random_uniform( const double min, const double max ) {
239
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
240
+ return min + ( v*(max-min) );
241
+ }
242
+
243
+ int main( void ) {
244
+ double mu;
245
+ double s;
246
+ double x;
247
+ double y;
248
+ int i;
249
+
250
+ for ( i = 0; i < 25; i++ ) {
251
+ x = random_uniform( -5.0, 5.0 );
252
+ mu = random_uniform( -5.0, 5.0 );
253
+ s = random_uniform( 0.0, 20.0 );
254
+ y = stdlib_base_dists_logistic_logpdf( x, mu, s );
255
+ printf( "x: %lf, µ: %lf, s: %lf, ln(f(x;µ,s)): %lf\n", x, mu, s, y );
256
+ }
167
257
  }
168
258
  ```
169
259
 
@@ -171,6 +261,10 @@ for ( i = 0; i < 10; i++ ) {
171
261
 
172
262
  <!-- /.examples -->
173
263
 
264
+ </section>
265
+
266
+ <!-- /.c -->
267
+
174
268
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
175
269
 
176
270
  <section class="related">
@@ -205,7 +299,7 @@ See [LICENSE][stdlib-license].
205
299
 
206
300
  ## Copyright
207
301
 
208
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
302
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
209
303
 
210
304
  </section>
211
305
 
@@ -218,8 +312,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
218
312
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-logistic-logpdf.svg
219
313
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-logistic-logpdf
220
314
 
221
- [test-image]: https://github.com/stdlib-js/stats-base-dists-logistic-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
222
- [test-url]: https://github.com/stdlib-js/stats-base-dists-logistic-logpdf/actions/workflows/test.yml?query=branch:v0.2.2
315
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-logistic-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
316
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-logistic-logpdf/actions/workflows/test.yml?query=branch:v0.3.0
223
317
 
224
318
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-logistic-logpdf/main.svg
225
319
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-logistic-logpdf?branch=main
@@ -231,8 +325,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
231
325
 
232
326
  -->
233
327
 
234
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
235
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
328
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
329
+ [chat-url]: https://stdlib.zulipchat.com
236
330
 
237
331
  [stdlib]: https://github.com/stdlib-js/stdlib
238
332
 
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 log1p = require( '@stdlib/math-base-special-log1p' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the probability density function (PDF) for a logistic distribution with location parameter `mu` and scale parameter `s` at a value `x`.\n*\n* @param {number} x - input value\n* @param {number} mu - location parameter\n* @param {NonNegativeNumber} s - scale parameter\n* @returns {number} evaluated logPDF\n*\n* @example\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.254\n*\n* @example\n* var y = logpdf( -1.0, 4.0, 2.0 );\n* // returns ~-3.351\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*\n* @example\n* var y = logpdf( 2.0, 8.0, 0.0 );\n* // returns -Infinity\n*\n* @example\n* var y = logpdf( 8.0, 8.0, 0.0 );\n* // returns Infinity\n*/\nfunction logpdf( x, mu, s ) {\n\tvar az;\n\tvar z;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( mu ) ||\n\t\tisnan( s ) ||\n\t\ts < 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( x === NINF ) {\n\t\treturn NINF;\n\t}\n\tif ( s === 0.0 ) {\n\t\treturn ( x === mu ) ? PINF : NINF;\n\t}\n\tz = ( x - mu ) / s;\n\taz = -abs( z );\n\treturn az - (2.0 * log1p( exp( az ) )) - ln( s );\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 degenerate = require( '@stdlib/stats-base-dists-degenerate-logpdf' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the logarithm of the probability density function (PDF) for a logistic distribution.\n*\n* @param {number} mu - location parameter\n* @param {NonNegativeNumber} s - scale parameter\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 10.0, 2.0 );\n* var y = logpdf( 10.0 );\n* // returns ~-2.079\n*\n* y = logpdf( 5.0 );\n* // returns ~-3.351\n*/\nfunction factory( mu, s ) {\n\tvar ls;\n\tif ( isnan( mu ) || isnan( s ) || s < 0.0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tif ( s === 0.0 ) {\n\t\treturn degenerate( mu );\n\t}\n\tls = ln( s );\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the logarithm of the probability density function (PDF) for a logistic distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logPDF\n\t*\n\t* @example\n\t* var y = logpdf( -1.2 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tvar az;\n\t\tvar z;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x === NINF ) {\n\t\t\treturn NINF;\n\t\t}\n\t\tz = ( x - mu ) / s;\n\t\taz = -abs( z );\n\t\treturn az - (2.0 * log1p( exp( az ) )) - ls;\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* Logistic distribution logarithm of probability density function (PDF).\n*\n* @module @stdlib/stats-base-dists-logistic-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-logistic-logpdf' );\n*\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.254\n*\n* var mylogpdf = logpdf.factory( 10.0, 2.0 );\n* y = mylogpdf( 10.0 );\n* // returns -2.079\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 log1p = require( '@stdlib/math-base-special-log1p' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the probability density function (PDF) for a logistic distribution with location parameter `mu` and scale parameter `s` at a value `x`.\n*\n* @param {number} x - input value\n* @param {number} mu - location parameter\n* @param {NonNegativeNumber} s - scale parameter\n* @returns {number} evaluated logPDF\n*\n* @example\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.254\n*\n* @example\n* var y = logpdf( -1.0, 4.0, 2.0 );\n* // returns ~-3.351\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*\n* @example\n* var y = logpdf( 2.0, 8.0, 0.0 );\n* // returns -Infinity\n*\n* @example\n* var y = logpdf( 8.0, 8.0, 0.0 );\n* // returns Infinity\n*/\nfunction logpdf( x, mu, s ) {\n\tvar az;\n\tvar z;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( mu ) ||\n\t\tisnan( s ) ||\n\t\ts < 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( x === NINF ) {\n\t\treturn NINF;\n\t}\n\tif ( s === 0.0 ) {\n\t\treturn ( x === mu ) ? PINF : NINF;\n\t}\n\tz = ( x - mu ) / s;\n\taz = -abs( z );\n\treturn az - (2.0 * log1p( exp( az ) )) - ln( s );\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 degenerate = require( '@stdlib/stats-base-dists-degenerate-logpdf' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar abs = require( '@stdlib/math-base-special-abs' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the logarithm of the probability density function (PDF) for a logistic distribution.\n*\n* @param {number} mu - location parameter\n* @param {NonNegativeNumber} s - scale parameter\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 10.0, 2.0 );\n* var y = logpdf( 10.0 );\n* // returns ~-2.079\n*\n* y = logpdf( 5.0 );\n* // returns ~-3.351\n*/\nfunction factory( mu, s ) {\n\tvar ls;\n\tif ( isnan( mu ) || isnan( s ) || s < 0.0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tif ( s === 0.0 ) {\n\t\treturn degenerate( mu );\n\t}\n\tls = ln( s );\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the logarithm of the probability density function (PDF) for a logistic distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logPDF\n\t*\n\t* @example\n\t* var y = logpdf( -1.2 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tvar az;\n\t\tvar z;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x === NINF ) {\n\t\t\treturn NINF;\n\t\t}\n\t\tz = ( x - mu ) / s;\n\t\taz = -abs( z );\n\t\treturn az - (2.0 * log1p( exp( az ) )) - ls;\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* Logistic distribution logarithm of probability density function (PDF).\n*\n* @module @stdlib/stats-base-dists-logistic-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-logistic-logpdf' );\n*\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.254\n*\n* var mylogpdf = logpdf.factory( 10.0, 2.0 );\n* y = mylogpdf( 10.0 );\n* // returns ~-2.079\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,EAAM,QAAS,+BAAgC,EAC/CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EACjDC,EAAO,QAAS,gCAAiC,EA8CrD,SAASC,EAAQC,EAAGC,EAAIC,EAAI,CAC3B,IAAIC,EACAC,EACJ,OACCZ,EAAOQ,CAAE,GACTR,EAAOS,CAAG,GACVT,EAAOU,CAAE,GACTA,EAAI,EAEG,IAEHF,IAAMH,EACHA,EAEHK,IAAM,EACDF,IAAMC,EAAOH,EAAOD,GAE9BO,GAAMJ,EAAIC,GAAOC,EACjBC,EAAK,CAACT,EAAKU,CAAE,EACND,EAAM,EAAMV,EAAOE,EAAKQ,CAAG,CAAE,EAAKP,EAAIM,CAAE,EAChD,CAKAX,EAAO,QAAUQ,ICnGjB,IAAAM,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAa,QAAS,4CAA6C,EAAE,QACrEC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EAoBrD,SAASC,EAASC,EAAIC,EAAI,CACzB,IAAIC,EACJ,GAAKT,EAAOO,CAAG,GAAKP,EAAOQ,CAAE,GAAKA,EAAI,EACrC,OAAOV,EAAkB,GAAI,EAE9B,GAAKU,IAAM,EACV,OAAOT,EAAYQ,CAAG,EAEvB,OAAAE,EAAKL,EAAII,CAAE,EACJE,EAaP,SAASA,EAAQC,EAAI,CACpB,IAAIC,EACAC,EACJ,OAAKb,EAAOW,CAAE,EACN,IAEHA,IAAMN,EACHA,GAERQ,GAAMF,EAAIJ,GAAOC,EACjBI,EAAK,CAACV,EAAKW,CAAE,EACND,EAAM,EAAMX,EAAOE,EAAKS,CAAG,CAAE,EAAKH,EAC1C,CACD,CAKAZ,EAAO,QAAUS,ICnDjB,IAAIQ,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", "log1p", "abs", "exp", "ln", "NINF", "PINF", "logpdf", "x", "mu", "s", "az", "z", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "degenerate", "isnan", "log1p", "abs", "exp", "ln", "NINF", "factory", "mu", "s", "ls", "logpdf", "x", "az", "z", "setReadOnly", "main", "factory"]
7
7
  }
@@ -109,11 +109,11 @@ interface LogPDF {
109
109
  *
110
110
  * var mylogpdf = logpdf.factory( 10.0, 2.0 );
111
111
  * y = mylogpdf( 10.0 );
112
- * // returns -2.079
112
+ * // returns ~-2.079
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_LOGISTIC_LOGPDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_LOGISTIC_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 logistic distribution with location parameter `mu` and scale parameter `s` at a value `x`.
31
+ */
32
+ double stdlib_base_dists_logistic_logpdf( const double x, const double mu, const double s );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_LOGISTIC_LOGPDF_H
package/lib/index.js CHANGED
@@ -31,7 +31,7 @@
31
31
  *
32
32
  * var mylogpdf = logpdf.factory( 10.0, 2.0 );
33
33
  * y = mylogpdf( 10.0 );
34
- * // returns -2.079
34
+ * // returns ~-2.079
35
35
  */
36
36
 
37
37
  // MODULES //
package/lib/native.js ADDED
@@ -0,0 +1,77 @@
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 logistic distribution with location parameter `mu` and scale parameter `s` at a value `x`.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {number} mu - location parameter
34
+ * @param {NonNegativeNumber} s - scale parameter
35
+ * @returns {number} evaluated logPDF
36
+ *
37
+ * @example
38
+ * var y = logpdf( 2.0, 0.0, 1.0 );
39
+ * // returns ~-2.254
40
+ *
41
+ * @example
42
+ * var y = logpdf( -1.0, 4.0, 2.0 );
43
+ * // returns ~-3.351
44
+ *
45
+ * @example
46
+ * var y = logpdf( NaN, 0.0, 1.0 );
47
+ * // returns NaN
48
+ *
49
+ * @example
50
+ * var y = logpdf( 0.0, NaN, 1.0 );
51
+ * // returns NaN
52
+ *
53
+ * @example
54
+ * var y = logpdf( 0.0, 0.0, NaN );
55
+ * // returns NaN
56
+ *
57
+ * @example
58
+ * // Negative scale parameter:
59
+ * var y = logpdf( 2.0, 0.0, -1.0 );
60
+ * // returns NaN
61
+ *
62
+ * @example
63
+ * var y = logpdf( 2.0, 8.0, 0.0 );
64
+ * // returns -Infinity
65
+ *
66
+ * @example
67
+ * var y = logpdf( 8.0, 8.0, 0.0 );
68
+ * // returns Infinity
69
+ */
70
+ function logpdf( x, mu, s ) {
71
+ return addon( x, mu, s );
72
+ }
73
+
74
+
75
+ // EXPORTS //
76
+
77
+ module.exports = logpdf;
package/manifest.json ADDED
@@ -0,0 +1,95 @@
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/math-base-special-abs",
45
+ "@stdlib/math-base-special-exp",
46
+ "@stdlib/math-base-special-ln",
47
+ "@stdlib/constants-float64-ninf",
48
+ "@stdlib/constants-float64-pinf"
49
+ ]
50
+ },
51
+ {
52
+ "task": "benchmark",
53
+ "wasm": false,
54
+ "src": [
55
+ "./src/main.c"
56
+ ],
57
+ "include": [
58
+ "./include"
59
+ ],
60
+ "libraries": [],
61
+ "libpath": [],
62
+ "dependencies": [
63
+ "@stdlib/math-base-assert-is-nan",
64
+ "@stdlib/math-base-special-log1p",
65
+ "@stdlib/math-base-special-abs",
66
+ "@stdlib/math-base-special-exp",
67
+ "@stdlib/math-base-special-ln",
68
+ "@stdlib/constants-float64-ninf",
69
+ "@stdlib/constants-float64-eps",
70
+ "@stdlib/constants-float64-pinf"
71
+ ]
72
+ },
73
+ {
74
+ "task": "examples",
75
+ "wasm": false,
76
+ "src": [
77
+ "./src/main.c"
78
+ ],
79
+ "include": [
80
+ "./include"
81
+ ],
82
+ "libraries": [],
83
+ "libpath": [],
84
+ "dependencies": [
85
+ "@stdlib/math-base-assert-is-nan",
86
+ "@stdlib/math-base-special-log1p",
87
+ "@stdlib/math-base-special-abs",
88
+ "@stdlib/math-base-special-exp",
89
+ "@stdlib/math-base-special-ln",
90
+ "@stdlib/constants-float64-ninf",
91
+ "@stdlib/constants-float64-pinf"
92
+ ]
93
+ }
94
+ ]
95
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-logistic-logpdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Logistic 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",
@@ -33,13 +36,15 @@
33
36
  "@stdlib/constants-float64-ninf": "^0.2.2",
34
37
  "@stdlib/constants-float64-pinf": "^0.2.2",
35
38
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
39
+ "@stdlib/math-base-napi-ternary": "^0.3.1",
36
40
  "@stdlib/math-base-special-abs": "^0.2.2",
37
41
  "@stdlib/math-base-special-exp": "^0.2.4",
38
42
  "@stdlib/math-base-special-ln": "^0.2.4",
39
43
  "@stdlib/math-base-special-log1p": "^0.2.3",
40
- "@stdlib/stats-base-dists-degenerate-logpdf": "^0.2.1",
44
+ "@stdlib/stats-base-dists-degenerate-logpdf": "^0.3.0",
41
45
  "@stdlib/utils-constant-function": "^0.2.2",
42
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
46
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
47
+ "@stdlib/utils-library-manifest": "^0.2.3"
43
48
  },
44
49
  "devDependencies": {},
45
50
  "engines": {
package/src/addon.c ADDED
@@ -0,0 +1,23 @@
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/logistic/logpdf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ // cppcheck-suppress shadowFunction
23
+ STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_logistic_logpdf )
package/src/main.c ADDED
@@ -0,0 +1,60 @@
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/logistic/logpdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/log1p.h"
22
+ #include "stdlib/math/base/special/abs.h"
23
+ #include "stdlib/math/base/special/exp.h"
24
+ #include "stdlib/math/base/special/ln.h"
25
+ #include "stdlib/constants/float64/ninf.h"
26
+ #include "stdlib/constants/float64/pinf.h"
27
+
28
+ /**
29
+ * Evaluates the logarithm of the probability density function (PDF) for a logistic distribution with location parameter `mu` and scale parameter `s` at a value `x`.
30
+ *
31
+ * @param x input value
32
+ * @param mu location parameter
33
+ * @param s scale parameter
34
+ * @return evaluated logPDF
35
+ *
36
+ * @example
37
+ * double y = stdlib_base_dists_logistic_logpdf( 2.0, 0.0, 1.0 );
38
+ * // returns ~-2.254
39
+ */
40
+ double stdlib_base_dists_logistic_logpdf( const double x, const double mu, const double s ) {
41
+ double az;
42
+ double z;
43
+ if (
44
+ stdlib_base_is_nan( x ) ||
45
+ stdlib_base_is_nan( mu ) ||
46
+ stdlib_base_is_nan( s ) ||
47
+ s < 0.0
48
+ ) {
49
+ return 0.0 / 0.0; //NaN
50
+ }
51
+ if ( x == STDLIB_CONSTANT_FLOAT64_NINF ) {
52
+ return STDLIB_CONSTANT_FLOAT64_NINF;
53
+ }
54
+ if ( s == 0.0 ) {
55
+ return ( x == mu ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF;
56
+ }
57
+ z = ( x - mu ) / s;
58
+ az = -stdlib_base_abs( z );
59
+ return az - (2.0 * stdlib_base_log1p( stdlib_base_exp( az ) )) - stdlib_base_ln( s );
60
+ }