@stdlib/stats-base-dists-planck-pmf 0.1.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/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,324 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2024 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
32
+ # Probability Mass Function
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > Planck (discrete exponential) distribution [probability mass function][pmf] (PMF).
37
+
38
+ <section class="intro">
39
+
40
+ The [probability mass function][pmf] (PMF) for a Planck random variable is defined as
41
+
42
+ <!-- <equation class="equation" label="eq:planck_pmf" align="center" raw="\Pr(X = x, \lambda) = \begin{cases}(1 - e^{-\lambda})e^{-\lambda x} & \text{for } x = 0, 1, 2, \ldots \\ 0 & \text{otherwise} \end{cases}" alt="Probability mass function (PMF) for a Planck (discrete exponential) distribution."> -->
43
+
44
+ <!-- </equation> -->
45
+
46
+ where `λ` is the shape parameter. The random variable `X` denotes the count of events in a quantized system.
47
+
48
+ </section>
49
+
50
+ <!-- /.intro -->
51
+
52
+ <section class="installation">
53
+
54
+ ## Installation
55
+
56
+ ```bash
57
+ npm install @stdlib/stats-base-dists-planck-pmf
58
+ ```
59
+
60
+ </section>
61
+
62
+ <section class="usage">
63
+
64
+ ## Usage
65
+
66
+ ```javascript
67
+ var pmf = require( '@stdlib/stats-base-dists-planck-pmf' );
68
+ ```
69
+
70
+ #### pmf( x, lambda )
71
+
72
+ Evaluates the [probability mass function][pmf] (PMF) of a Planck (discrete exponential) distribution with shape parameter `lambda`.
73
+
74
+ ```javascript
75
+ var y = pmf( 4.0, 0.3 );
76
+ // returns ~0.0781
77
+
78
+ y = pmf( 2.0, 1.7 );
79
+ // returns ~0.0273
80
+
81
+ y = pmf( -1.0, 2.5 );
82
+ // returns 0.0
83
+ ```
84
+
85
+ If provided `NaN` as any argument, the function returns `NaN`.
86
+
87
+ ```javascript
88
+ var y = pmf( NaN, 0.0 );
89
+ // returns NaN
90
+
91
+ y = pmf( 0.0, NaN );
92
+ // returns NaN
93
+ ```
94
+
95
+ If provided a shape parameter `lambda` which is a nonpositive number, the function returns `NaN`.
96
+
97
+ ```javascript
98
+ var y = pmf( 2.0, -1.0 );
99
+ // returns NaN
100
+ ```
101
+
102
+ #### pmf.factory( lambda )
103
+
104
+ Returns a function for evaluating the [probability mass function][pmf] (PMF) of a Planck (discrete exponential) distribution with shape parameter `lambda`.
105
+
106
+ ```javascript
107
+ var mypmf = pmf.factory( 0.5 );
108
+ var y = mypmf( 3.0 );
109
+ // returns ~0.0878
110
+
111
+ y = mypmf( 1.0 );
112
+ // returns ~0.2387
113
+ ```
114
+
115
+ </section>
116
+
117
+ <!-- /.usage -->
118
+
119
+ <section class="examples">
120
+
121
+ ## Examples
122
+
123
+ <!-- eslint no-undef: "error" -->
124
+
125
+ ```javascript
126
+ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
127
+ var uniform = require( '@stdlib/random-array-uniform' );
128
+ var logEachMap = require( '@stdlib/console-log-each-map' );
129
+ var pmf = require( '@stdlib/stats-base-dists-planck-pmf' );
130
+
131
+ var opts = {
132
+ 'dtype': 'float64'
133
+ };
134
+ var x = discreteUniform( 10, 0, 5, opts );
135
+ var lambda = uniform( 10, 0.1, 5.0, opts );
136
+
137
+ logEachMap( 'x: %d, λ: %0.4f, P(X = x; λ): %0.4f', x, lambda, pmf );
138
+ ```
139
+
140
+ </section>
141
+
142
+ <!-- /.examples -->
143
+
144
+ <!-- C interface documentation. -->
145
+
146
+ * * *
147
+
148
+ <section class="c">
149
+
150
+ ## C APIs
151
+
152
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
153
+
154
+ <section class="intro">
155
+
156
+ </section>
157
+
158
+ <!-- /.intro -->
159
+
160
+ <!-- C usage documentation. -->
161
+
162
+ <section class="usage">
163
+
164
+ ### Usage
165
+
166
+ ```c
167
+ #include "stdlib/stats/base/dists/planck/pmf.h"
168
+ ```
169
+
170
+ #### stdlib_base_dists_planck_pmf( x, lambda )
171
+
172
+ Evaluates the [probability mass function][pmf] for a Planck (discrete exponential) distribution with input value `x` and shape parameter `lambda`.
173
+
174
+ ```c
175
+ double out = stdlib_base_dists_planck_pmf( 4.0, 0.3 );
176
+ // returns ~0.0781
177
+ ```
178
+
179
+ The function accepts the following arguments:
180
+
181
+ - **x**: `[in] double` input value.
182
+ - **lambda**: `[in] double` shape parameter.
183
+
184
+ ```c
185
+ double stdlib_base_dists_planck_pmf( const double x, const double lambda );
186
+ ```
187
+
188
+ </section>
189
+
190
+ <!-- /.usage -->
191
+
192
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
193
+
194
+ <section class="notes">
195
+
196
+ </section>
197
+
198
+ <!-- /.notes -->
199
+
200
+ <!-- C API usage examples. -->
201
+
202
+ <section class="examples">
203
+
204
+ ### Examples
205
+
206
+ ```c
207
+ #include "stdlib/stats/base/dists/planck/pmf.h"
208
+ #include "stdlib/math/base/special/round.h"
209
+ #include <stdlib.h>
210
+ #include <stdio.h>
211
+
212
+ static double random_uniform( const double min, const double max ) {
213
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
214
+ return min + ( v*(max-min) );
215
+ }
216
+
217
+ int main( void ) {
218
+ double x;
219
+ double lambda;
220
+ double y;
221
+ int i;
222
+
223
+ for ( i = 0; i < 25; i++ ) {
224
+ x = stdlib_base_round( random_uniform( 0.0, 11.0 ) );
225
+ lambda = random_uniform( 0.1, 5.0 );
226
+ y = stdlib_base_dists_planck_pmf( x, lambda );
227
+ printf( "x: %.0f, λ: %lf, P(X = x; λ): %lf\n", x, lambda, y );
228
+ }
229
+ }
230
+ ```
231
+
232
+ </section>
233
+
234
+ <!-- /.examples -->
235
+
236
+ </section>
237
+
238
+ <!-- /.c -->
239
+
240
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
241
+
242
+ <section class="related">
243
+
244
+ </section>
245
+
246
+ <!-- /.related -->
247
+
248
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
249
+
250
+
251
+ <section class="main-repo" >
252
+
253
+ * * *
254
+
255
+ ## Notice
256
+
257
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
258
+
259
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
260
+
261
+ #### Community
262
+
263
+ [![Chat][chat-image]][chat-url]
264
+
265
+ ---
266
+
267
+ ## License
268
+
269
+ See [LICENSE][stdlib-license].
270
+
271
+
272
+ ## Copyright
273
+
274
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
275
+
276
+ </section>
277
+
278
+ <!-- /.stdlib -->
279
+
280
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
281
+
282
+ <section class="links">
283
+
284
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-planck-pmf.svg
285
+ [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-planck-pmf
286
+
287
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-planck-pmf/actions/workflows/test.yml/badge.svg?branch=v0.1.0
288
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-planck-pmf/actions/workflows/test.yml?query=branch:v0.1.0
289
+
290
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-planck-pmf/main.svg
291
+ [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-planck-pmf?branch=main
292
+
293
+ <!--
294
+
295
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/stats-base-dists-planck-pmf.svg
296
+ [dependencies-url]: https://david-dm.org/stdlib-js/stats-base-dists-planck-pmf/main
297
+
298
+ -->
299
+
300
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
301
+ [chat-url]: https://stdlib.zulipchat.com
302
+
303
+ [stdlib]: https://github.com/stdlib-js/stdlib
304
+
305
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
306
+
307
+ [umd]: https://github.com/umdjs/umd
308
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
309
+
310
+ [deno-url]: https://github.com/stdlib-js/stats-base-dists-planck-pmf/tree/deno
311
+ [deno-readme]: https://github.com/stdlib-js/stats-base-dists-planck-pmf/blob/deno/README.md
312
+ [umd-url]: https://github.com/stdlib-js/stats-base-dists-planck-pmf/tree/umd
313
+ [umd-readme]: https://github.com/stdlib-js/stats-base-dists-planck-pmf/blob/umd/README.md
314
+ [esm-url]: https://github.com/stdlib-js/stats-base-dists-planck-pmf/tree/esm
315
+ [esm-readme]: https://github.com/stdlib-js/stats-base-dists-planck-pmf/blob/esm/README.md
316
+ [branches-url]: https://github.com/stdlib-js/stats-base-dists-planck-pmf/blob/main/branches.md
317
+
318
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/stats-base-dists-planck-pmf/main/LICENSE
319
+
320
+ [pmf]: https://en.wikipedia.org/wiki/Probability_mass_function
321
+
322
+ </section>
323
+
324
+ <!-- /.links -->
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import pmf from '../docs/types/index';
3
+ export = pmf;
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";var t=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=t(function(j,u){
2
+ var q=require('@stdlib/math-base-assert-is-nonnegative-integer/dist'),n=require('@stdlib/math-base-assert-is-nan/dist'),c=require('@stdlib/math-base-special-exp/dist'),N=require('@stdlib/math-base-special-expm1/dist');function p(e,r){return n(e)||n(r)||r<=0?NaN:q(e)?-N(-r)*c(-r*e):0}u.exports=p
3
+ });var f=t(function(k,a){
4
+ var g=require('@stdlib/math-base-assert-is-nonnegative-integer/dist'),y=require('@stdlib/utils-constant-function/dist'),v=require('@stdlib/math-base-assert-is-nan/dist'),x=require('@stdlib/math-base-special-exp/dist'),I=require('@stdlib/math-base-special-expm1/dist');function F(e){if(v(e)||e<=0)return y(NaN);return r;function r(i){return v(i)?NaN:g(i)?-I(-e)*x(-e*i):0}}a.exports=F
5
+ });var O=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),o=s(),R=f();O(o,"factory",R);module.exports=o;
6
+ /** @license Apache-2.0 */
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/main.js", "../lib/factory.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 isNonNegativeInteger = require( '@stdlib/math-base-assert-is-nonnegative-integer' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\n\n\n// MAIN //\n\n/**\n* Evaluates the probability mass function (PMF) for a Planck distribution with shape parameter `lambda` at a value `x`.\n*\n* @param {number} x - input value\n* @param {PositiveNumber} lambda - shape parameter\n* @returns {Probability} evaluated PMF\n*\n* @example\n* var y = pmf( 4.0, 0.3 );\n* // returns ~0.0781\n*\n* @example\n* var y = pmf( 2.0, 1.7 );\n* // returns ~0.0273\n*\n* @example\n* var y = pmf( -1.0, 2.5 );\n* // returns 0.0\n*\n* @example\n* var y = pmf( 0.0, NaN );\n* // returns NaN\n*\n* @example\n* var y = pmf( NaN, 0.5 );\n* // returns NaN\n*\n* @example\n* // Invalid shape parameter:\n* var y = pmf( 2.0, -1.0 );\n* // returns NaN\n*/\nfunction pmf( x, lambda ) {\n\tif ( isnan( x ) || isnan( lambda ) || lambda <= 0.0 ) {\n\t\treturn NaN;\n\t}\n\tif ( isNonNegativeInteger( x ) ) {\n\t\treturn -expm1( -lambda ) * exp( -lambda * x );\n\t}\n\treturn 0.0;\n}\n\n\n// EXPORTS //\n\nmodule.exports = pmf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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 isNonNegativeInteger = require( '@stdlib/math-base-assert-is-nonnegative-integer' );\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the probability mass function (PMF) for a Planck distribution with shape parameter `lambda`.\n*\n* @param {PositiveNumber} lambda - shape parameter\n* @returns {Function} PMF\n*\n* @example\n* var pmf = factory( 0.5 );\n* var y = pmf( 3.0 );\n* // returns ~0.0878\n*\n* y = pmf( 1.0 );\n* // returns ~0.2387\n*/\nfunction factory( lambda ) {\n\tif ( isnan( lambda ) || lambda <= 0.0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\treturn pmf;\n\n\t/**\n\t* Evaluates the probability mass function (PMF) for a Planck distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {Probability} evaluated PMF\n\t*\n\t* @example\n\t* var y = pmf( 2.0 );\n\t* // returns <number>\n\t*/\n\tfunction pmf( x ) {\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( isNonNegativeInteger( x ) ) {\n\t\t\treturn -expm1( -lambda ) * exp( -lambda * x );\n\t\t}\n\t\treturn 0.0;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 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* Planck distribution probability mass function (PMF).\n*\n* @module @stdlib/stats-base-dists-planck-pmf\n*\n* @example\n* var pmf = require( '@stdlib/stats-base-dists-planck-pmf' );\n*\n* var y = pmf( 4.0, 0.3 );\n* // returns ~0.0781\n*\n* y = pmf( 2.0, 1.7 );\n* // returns ~0.0273\n*\n* y = pmf( -1.0, 0.5 );\n* // returns 0.0\n*\n* var mypmf = pmf.factory( 0.5 );\n* y = mypmf( 3.0 );\n* // returns ~0.0878\n*\n* y = mypmf( 1.0 );\n* // returns ~0.2387\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
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,iDAAkD,EAClFC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAQ,QAAS,iCAAkC,EAqCvD,SAASC,EAAKC,EAAGC,EAAS,CACzB,OAAKL,EAAOI,CAAE,GAAKJ,EAAOK,CAAO,GAAKA,GAAU,EACxC,IAEHN,EAAsBK,CAAE,EACrB,CAACF,EAAO,CAACG,CAAO,EAAIJ,EAAK,CAACI,EAASD,CAAE,EAEtC,CACR,CAKAN,EAAO,QAAUK,IC3EjB,IAAAG,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAuB,QAAS,iDAAkD,EAClFC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAQ,QAAS,iCAAkC,EAmBvD,SAASC,EAASC,EAAS,CAC1B,GAAKJ,EAAOI,CAAO,GAAKA,GAAU,EACjC,OAAOL,EAAkB,GAAI,EAE9B,OAAOM,EAaP,SAASA,EAAKC,EAAI,CACjB,OAAKN,EAAOM,CAAE,EACN,IAEHR,EAAsBQ,CAAE,EACrB,CAACJ,EAAO,CAACE,CAAO,EAAIH,EAAK,CAACG,EAASE,CAAE,EAEtC,CACR,CACD,CAKAT,EAAO,QAAUM,IC7BjB,IAAII,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "isnan", "exp", "expm1", "pmf", "x", "lambda", "require_factory", "__commonJSMin", "exports", "module", "isNonNegativeInteger", "constantFunction", "isnan", "exp", "expm1", "factory", "lambda", "pmf", "x", "setReadOnly", "main", "factory"]
7
+ }
@@ -0,0 +1,117 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ // TypeScript Version: 4.1
20
+
21
+ /**
22
+ * Evaluates the probability mass function (PMF) for a Planck distribution.
23
+ *
24
+ * @param x - input value
25
+ * @returns evaluated PMF
26
+ */
27
+ type Unary = ( x: number ) => number;
28
+
29
+ /**
30
+ * Interface for the probability mass function (PMF) of a Planck distribution.
31
+ */
32
+ interface PMF {
33
+ /**
34
+ * Evaluates the probability mass function (PMF) for a Planck distribution with shape parameter `lambda` at a value `x`.
35
+ *
36
+ * ## Notes
37
+ *
38
+ * - If `lambda <= 0`, the function returns `NaN`.
39
+ *
40
+ * @param x - input value
41
+ * @param lambda - shape parameter
42
+ * @returns evaluated PMF
43
+ *
44
+ * @example
45
+ * var y = pmf( 4.0, 0.3 );
46
+ * // returns ~0.0781
47
+ *
48
+ * @example
49
+ * var y = pmf( 2.0, 1.7 );
50
+ * // returns ~0.0273
51
+ *
52
+ * @example
53
+ * var y = pmf( -1.0, 2.5 );
54
+ * // returns 0.0
55
+ *
56
+ * @example
57
+ * var y = pmf( 0.0, NaN );
58
+ * // returns NaN
59
+ *
60
+ * @example
61
+ * var y = pmf( NaN, 0.5 );
62
+ * // returns NaN
63
+ *
64
+ * @example
65
+ * // Invalid shape parameter:
66
+ * var y = pmf( 2.0, -1.0 );
67
+ * // returns NaN
68
+ */
69
+ ( x: number, lambda: number ): number;
70
+
71
+ /**
72
+ * Returns a function for evaluating the probability mass function (PMF) for a Planck distribution with shape parameter `lambda`.
73
+ *
74
+ * @param lambda - shape parameter
75
+ * @returns PMF
76
+ *
77
+ * @example
78
+ * var mypmf = pmf.factory( 0.5 );
79
+ * var y = mypmf( 3.0 );
80
+ * // returns ~0.0878
81
+ *
82
+ * y = mypmf( 1.0 );
83
+ * // returns ~0.239
84
+ */
85
+ factory( lambda: number ): Unary;
86
+ }
87
+
88
+ /**
89
+ * Planck distribution probability mass function (PMF).
90
+ *
91
+ * @param x - input value
92
+ * @param lambda - shape parameter
93
+ * @returns evaluated PMF
94
+ *
95
+ * @example
96
+ * var y = pmf( 4.0, 0.3 );
97
+ * // returns ~0.0781
98
+ *
99
+ * y = pmf( 2.0, 1.7 );
100
+ * // returns ~0.0273
101
+ *
102
+ * y = pmf( -1.0, 0.5 );
103
+ * // returns 0.0
104
+ *
105
+ * var mypmf = pmf.factory( 0.5 );
106
+ * y = mypmf( 3.0 );
107
+ * // returns ~0.0878
108
+ *
109
+ * y = mypmf( 1.0 );
110
+ * // returns ~0.2387
111
+ */
112
+ declare var pmf: PMF;
113
+
114
+
115
+ // EXPORTS //
116
+
117
+ export = pmf;
@@ -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_PLANCK_PMF_H
20
+ #define STDLIB_STATS_BASE_DISTS_PLANCK_PMF_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 probability mass function (PMF) for a Planck distribution with shape parameter `lambda`.
31
+ */
32
+ double stdlib_base_dists_planck_pmf( const double x, const double lambda );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_PLANCK_PMF_H
package/lib/factory.js ADDED
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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 isNonNegativeInteger = require( '@stdlib/math-base-assert-is-nonnegative-integer' );
24
+ var constantFunction = require( '@stdlib/utils-constant-function' );
25
+ var isnan = require( '@stdlib/math-base-assert-is-nan' );
26
+ var exp = require( '@stdlib/math-base-special-exp' );
27
+ var expm1 = require( '@stdlib/math-base-special-expm1' );
28
+
29
+
30
+ // MAIN //
31
+
32
+ /**
33
+ * Returns a function for evaluating the probability mass function (PMF) for a Planck distribution with shape parameter `lambda`.
34
+ *
35
+ * @param {PositiveNumber} lambda - shape parameter
36
+ * @returns {Function} PMF
37
+ *
38
+ * @example
39
+ * var pmf = factory( 0.5 );
40
+ * var y = pmf( 3.0 );
41
+ * // returns ~0.0878
42
+ *
43
+ * y = pmf( 1.0 );
44
+ * // returns ~0.2387
45
+ */
46
+ function factory( lambda ) {
47
+ if ( isnan( lambda ) || lambda <= 0.0 ) {
48
+ return constantFunction( NaN );
49
+ }
50
+ return pmf;
51
+
52
+ /**
53
+ * Evaluates the probability mass function (PMF) for a Planck distribution.
54
+ *
55
+ * @private
56
+ * @param {number} x - input value
57
+ * @returns {Probability} evaluated PMF
58
+ *
59
+ * @example
60
+ * var y = pmf( 2.0 );
61
+ * // returns <number>
62
+ */
63
+ function pmf( x ) {
64
+ if ( isnan( x ) ) {
65
+ return NaN;
66
+ }
67
+ if ( isNonNegativeInteger( x ) ) {
68
+ return -expm1( -lambda ) * exp( -lambda * x );
69
+ }
70
+ return 0.0;
71
+ }
72
+ }
73
+
74
+
75
+ // EXPORTS //
76
+
77
+ module.exports = factory;
package/lib/index.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ /**
22
+ * Planck distribution probability mass function (PMF).
23
+ *
24
+ * @module @stdlib/stats-base-dists-planck-pmf
25
+ *
26
+ * @example
27
+ * var pmf = require( '@stdlib/stats-base-dists-planck-pmf' );
28
+ *
29
+ * var y = pmf( 4.0, 0.3 );
30
+ * // returns ~0.0781
31
+ *
32
+ * y = pmf( 2.0, 1.7 );
33
+ * // returns ~0.0273
34
+ *
35
+ * y = pmf( -1.0, 0.5 );
36
+ * // returns 0.0
37
+ *
38
+ * var mypmf = pmf.factory( 0.5 );
39
+ * y = mypmf( 3.0 );
40
+ * // returns ~0.0878
41
+ *
42
+ * y = mypmf( 1.0 );
43
+ * // returns ~0.2387
44
+ */
45
+
46
+ // MODULES //
47
+
48
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
49
+ var main = require( './main.js' );
50
+ var factory = require( './factory.js' );
51
+
52
+
53
+ // MAIN //
54
+
55
+ setReadOnly( main, 'factory', factory );
56
+
57
+
58
+ // EXPORTS //
59
+
60
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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 isNonNegativeInteger = require( '@stdlib/math-base-assert-is-nonnegative-integer' );
24
+ var isnan = require( '@stdlib/math-base-assert-is-nan' );
25
+ var exp = require( '@stdlib/math-base-special-exp' );
26
+ var expm1 = require( '@stdlib/math-base-special-expm1' );
27
+
28
+
29
+ // MAIN //
30
+
31
+ /**
32
+ * Evaluates the probability mass function (PMF) for a Planck distribution with shape parameter `lambda` at a value `x`.
33
+ *
34
+ * @param {number} x - input value
35
+ * @param {PositiveNumber} lambda - shape parameter
36
+ * @returns {Probability} evaluated PMF
37
+ *
38
+ * @example
39
+ * var y = pmf( 4.0, 0.3 );
40
+ * // returns ~0.0781
41
+ *
42
+ * @example
43
+ * var y = pmf( 2.0, 1.7 );
44
+ * // returns ~0.0273
45
+ *
46
+ * @example
47
+ * var y = pmf( -1.0, 2.5 );
48
+ * // returns 0.0
49
+ *
50
+ * @example
51
+ * var y = pmf( 0.0, NaN );
52
+ * // returns NaN
53
+ *
54
+ * @example
55
+ * var y = pmf( NaN, 0.5 );
56
+ * // returns NaN
57
+ *
58
+ * @example
59
+ * // Invalid shape parameter:
60
+ * var y = pmf( 2.0, -1.0 );
61
+ * // returns NaN
62
+ */
63
+ function pmf( x, lambda ) {
64
+ if ( isnan( x ) || isnan( lambda ) || lambda <= 0.0 ) {
65
+ return NaN;
66
+ }
67
+ if ( isNonNegativeInteger( x ) ) {
68
+ return -expm1( -lambda ) * exp( -lambda * x );
69
+ }
70
+ return 0.0;
71
+ }
72
+
73
+
74
+ // EXPORTS //
75
+
76
+ module.exports = pmf;
package/lib/native.js ADDED
@@ -0,0 +1,63 @@
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 probability mass function (PMF) for a Planck distribution with shape parameter `lambda`.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {PositiveNumber} lambda - shape parameter
34
+ * @returns {Probability} evaluated PMF
35
+ *
36
+ * @example
37
+ * var y = pmf( 2, 0.5 );
38
+ * // returns ~0.1447
39
+ *
40
+ * @example
41
+ * var y = pmf( 2, 1.5 );
42
+ * // returns ~0.0387
43
+ *
44
+ * @example
45
+ * var y = pmf( NaN, 0.5 );
46
+ * // returns NaN
47
+ *
48
+ * @example
49
+ * var y = pmf( 0, NaN );
50
+ * // returns NaN
51
+ *
52
+ * @example
53
+ * var y = pmf( 2, -1.0 );
54
+ * // returns NaN
55
+ */
56
+ function pmf( x, lambda ) {
57
+ return addon( x, lambda );
58
+ }
59
+
60
+
61
+ // EXPORTS //
62
+
63
+ module.exports = pmf;
package/manifest.json ADDED
@@ -0,0 +1,87 @@
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-binary",
42
+ "@stdlib/math-base-assert-is-nan",
43
+ "@stdlib/math-base-assert-is-nonnegative-integer",
44
+ "@stdlib/math-base-special-exp",
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-assert-is-nonnegative-integer",
62
+ "@stdlib/math-base-special-exp",
63
+ "@stdlib/math-base-special-expm1",
64
+ "@stdlib/math-base-special-round"
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-assert-is-nonnegative-integer",
81
+ "@stdlib/math-base-special-exp",
82
+ "@stdlib/math-base-special-expm1",
83
+ "@stdlib/math-base-special-round"
84
+ ]
85
+ }
86
+ ]
87
+ }
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@stdlib/stats-base-dists-planck-pmf",
3
+ "version": "0.1.0",
4
+ "description": "Planck (discrete exponential) distribution probability mass function (PMF).",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "gypfile": false,
18
+ "directories": {
19
+ "doc": "./docs",
20
+ "include": "./include",
21
+ "lib": "./lib",
22
+ "src": "./src",
23
+ "dist": "./dist"
24
+ },
25
+ "types": "./docs/types",
26
+ "scripts": {},
27
+ "homepage": "https://stdlib.io",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git://github.com/stdlib-js/stats-base-dists-planck-pmf.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/stdlib-js/stdlib/issues"
34
+ },
35
+ "dependencies": {
36
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
37
+ "@stdlib/math-base-assert-is-nonnegative-integer": "^0.2.2",
38
+ "@stdlib/math-base-napi-binary": "^0.3.1",
39
+ "@stdlib/math-base-special-exp": "^0.2.4",
40
+ "@stdlib/math-base-special-expm1": "^0.2.3",
41
+ "@stdlib/utils-constant-function": "^0.2.2",
42
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
43
+ "@stdlib/utils-library-manifest": "^0.2.3"
44
+ },
45
+ "devDependencies": {},
46
+ "engines": {
47
+ "node": ">=0.10.0",
48
+ "npm": ">2.7.0"
49
+ },
50
+ "os": [
51
+ "aix",
52
+ "darwin",
53
+ "freebsd",
54
+ "linux",
55
+ "macos",
56
+ "openbsd",
57
+ "sunos",
58
+ "win32",
59
+ "windows"
60
+ ],
61
+ "keywords": [
62
+ "stdlib",
63
+ "stdmath",
64
+ "statistics",
65
+ "stats",
66
+ "distribution",
67
+ "dist",
68
+ "probability",
69
+ "pmf",
70
+ "discrete distribution",
71
+ "planck",
72
+ "univariate",
73
+ "discrete"
74
+ ],
75
+ "funding": {
76
+ "type": "opencollective",
77
+ "url": "https://opencollective.com/stdlib"
78
+ }
79
+ }
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/planck/pmf.h"
20
+ #include "stdlib/math/base/napi/binary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_planck_pmf )
package/src/main.c ADDED
@@ -0,0 +1,44 @@
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/planck/pmf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/assert/is_nonnegative_integer.h"
22
+ #include "stdlib/math/base/special/exp.h"
23
+ #include "stdlib/math/base/special/expm1.h"
24
+
25
+ /**
26
+ * Evaluates the probability mass function (PMF) for a Planck distribution with shape parameter `lambda`.
27
+ *
28
+ * @param x input value
29
+ * @param lambda shape parameter
30
+ * @return evaluated PMF
31
+ *
32
+ * @example
33
+ * double y = stdlib_base_dists_planck_pmf( 2.0, 0.5 );
34
+ * // returns ~0.1839
35
+ */
36
+ double stdlib_base_dists_planck_pmf( const double x, const double lambda ) {
37
+ if ( stdlib_base_is_nan( x ) || stdlib_base_is_nan( lambda ) || lambda <= 0.0 ) {
38
+ return 0.0/0.0; // NaN
39
+ }
40
+ if ( !stdlib_base_is_nonnegative_integer( x ) ) {
41
+ return 0.0;
42
+ }
43
+ return -stdlib_base_expm1( -lambda ) * stdlib_base_exp( -lambda * x );
44
+ }