@stdlib/stats-base-dists-levy-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
@@ -165,6 +165,105 @@ for ( i = 0; i < 10; i++ ) {
165
165
 
166
166
  <!-- /.examples -->
167
167
 
168
+ <!-- C interface documentation. -->
169
+
170
+ * * *
171
+
172
+ <section class="c">
173
+
174
+ ## C APIs
175
+
176
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
177
+
178
+ <section class="intro">
179
+
180
+ </section>
181
+
182
+ <!-- /.intro -->
183
+
184
+ <!-- C usage documentation. -->
185
+
186
+ <section class="usage">
187
+
188
+ ### Usage
189
+
190
+ ```c
191
+ #include "stdlib/stats/base/dists/levy/logpdf.h"
192
+ ```
193
+
194
+ #### stdlib_base_dists_levy_logpdf( x, mu, c )
195
+
196
+ Evaluates the natural logarithm of the [probability density function][pdf] for a [Lévy][levy-distribution] distribution with input value `x`, location parameter `mu`, and scale parameter `c`.
197
+
198
+ ```c
199
+ double out = stdlib_base_dists_levy_logpdf( 2.0, 0.0, 1.0 );
200
+ // returns ~-2.209
201
+ ```
202
+
203
+ The function accepts the following arguments:
204
+
205
+ - **x**: `[in] double` input value.
206
+ - **mu**: `[in] double` location parameter.
207
+ - **c**: `[in] double` scale parameter.
208
+
209
+ ```c
210
+ double stdlib_base_dists_levy_logpdf( const double x, const double mu, const double c );
211
+ ```
212
+
213
+ </section>
214
+
215
+ <!-- /.usage -->
216
+
217
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
218
+
219
+ <section class="notes">
220
+
221
+ </section>
222
+
223
+ <!-- /.notes -->
224
+
225
+ <!-- C API usage examples. -->
226
+
227
+ <section class="examples">
228
+
229
+ ### Examples
230
+
231
+ ```c
232
+ #include "stdlib/stats/base/dists/levy/logpdf.h"
233
+ #include "stdlib/constants/float64/eps.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 x;
245
+ double c;
246
+ double y;
247
+ int i;
248
+
249
+ for ( i = 0; i < 25; i++ ) {
250
+ mu = random_uniform( 0.0, 10.0 );
251
+ x = random_uniform( mu, mu + 10.0 );
252
+ c = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
253
+ y = stdlib_base_dists_levy_logpdf( x, mu, c );
254
+ printf( "x: %lf, µ: %lf, c: %lf, ln(f(x;µ,c)): %lf\n", x, mu, c, y );
255
+ }
256
+ }
257
+ ```
258
+
259
+ </section>
260
+
261
+ <!-- /.examples -->
262
+
263
+ </section>
264
+
265
+ <!-- /.c -->
266
+
168
267
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
169
268
 
170
269
  <section class="related">
@@ -199,7 +298,7 @@ See [LICENSE][stdlib-license].
199
298
 
200
299
  ## Copyright
201
300
 
202
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
301
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
203
302
 
204
303
  </section>
205
304
 
@@ -212,8 +311,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
212
311
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-levy-logpdf.svg
213
312
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-levy-logpdf
214
313
 
215
- [test-image]: https://github.com/stdlib-js/stats-base-dists-levy-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
216
- [test-url]: https://github.com/stdlib-js/stats-base-dists-levy-logpdf/actions/workflows/test.yml?query=branch:v0.2.2
314
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-levy-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
315
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-levy-logpdf/actions/workflows/test.yml?query=branch:v0.3.0
217
316
 
218
317
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-levy-logpdf/main.svg
219
318
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-levy-logpdf?branch=main
@@ -225,8 +324,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
225
324
 
226
325
  -->
227
326
 
228
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
229
- [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
230
329
 
231
330
  [stdlib]: https://github.com/stdlib-js/stdlib
232
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;
@@ -103,9 +103,9 @@ interface LogPDF {
103
103
  * y = mylogpdf( 11.0 );
104
104
  * // returns ~-1.572
105
105
  */
106
- declare var logPDF: LogPDF;
106
+ declare var logpdf: LogPDF;
107
107
 
108
108
 
109
109
  // EXPORTS //
110
110
 
111
- export = logPDF;
111
+ 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_LEVY_LOGPDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_LEVY_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 natural logarithm of the probability density function (logPDF) for a Lévy distribution.
31
+ */
32
+ double stdlib_base_dists_levy_logpdf( const double x, const double mu, const double c );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_LEVY_LOGPDF_H
package/lib/native.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var addon = require( './../src/addon.node' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Evaluates the natural logarithm of the probability density function (logPDF) for a Lévy distribution with location parameter `mu` and scale parameter `c` at a value `x`.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {number} mu - location parameter
34
+ * @param {PositiveNumber} c - scale parameter
35
+ * @returns {number} evaluated logPDF
36
+ *
37
+ * @example
38
+ * var y = logpdf( 2.0, 0.0, 1.0 );
39
+ * // returns ~-2.209
40
+ *
41
+ * @example
42
+ * var y = logpdf( -1.0, 4.0, 2.0 );
43
+ * // returns -Infinity
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
+ function logpdf( x, mu, c ) {
63
+ return addon( x, mu, c );
64
+ }
65
+
66
+
67
+ // EXPORTS //
68
+
69
+ module.exports = logpdf;
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-ternary",
42
+ "@stdlib/math-base-assert-is-nan",
43
+ "@stdlib/math-base-special-ln",
44
+ "@stdlib/constants-float64-ln-two-pi",
45
+ "@stdlib/constants-float64-ninf"
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/constants-float64-eps",
61
+ "@stdlib/math-base-assert-is-nan",
62
+ "@stdlib/math-base-special-ln",
63
+ "@stdlib/constants-float64-ln-two-pi",
64
+ "@stdlib/constants-float64-ninf"
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/constants-float64-eps",
80
+ "@stdlib/math-base-assert-is-nan",
81
+ "@stdlib/math-base-special-ln",
82
+ "@stdlib/constants-float64-ln-two-pi",
83
+ "@stdlib/constants-float64-ninf"
84
+ ]
85
+ }
86
+ ]
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-levy-logpdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Lévy 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,9 +36,11 @@
33
36
  "@stdlib/constants-float64-ln-two-pi": "^0.2.2",
34
37
  "@stdlib/constants-float64-ninf": "^0.2.2",
35
38
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
36
- "@stdlib/math-base-special-ln": "^0.2.3",
39
+ "@stdlib/math-base-napi-ternary": "^0.3.1",
40
+ "@stdlib/math-base-special-ln": "^0.2.4",
37
41
  "@stdlib/utils-constant-function": "^0.2.2",
38
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
42
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
43
+ "@stdlib/utils-library-manifest": "^0.2.3"
39
44
  },
40
45
  "devDependencies": {},
41
46
  "engines": {
package/src/addon.c ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2025 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include "stdlib/stats/base/dists/levy/logpdf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_levy_logpdf )
package/src/main.c ADDED
@@ -0,0 +1,53 @@
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/levy/logpdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/ln.h"
22
+ #include "stdlib/constants/float64/ln_two_pi.h"
23
+ #include "stdlib/constants/float64/ninf.h"
24
+
25
+ /**
26
+ * Evaluates the natural logarithm of the probability density function (logPDF) for a Lévy distribution with location parameter `mu` and scale parameter `c` at a value `x`.
27
+ *
28
+ * @param x input value
29
+ * @param mu location parameter
30
+ * @param c scale parameter
31
+ * @return evaluated logPDF
32
+ *
33
+ * @example
34
+ * double y = stdlib_base_dists_levy_logpdf( 2.0, 0.0, 1.0 );
35
+ * // returns ~-2.209
36
+ */
37
+ double stdlib_base_dists_levy_logpdf( const double x, const double mu, const double c ) {
38
+ double z;
39
+
40
+ if (
41
+ stdlib_base_is_nan( x ) ||
42
+ stdlib_base_is_nan( mu ) ||
43
+ stdlib_base_is_nan( c ) ||
44
+ c <= 0.0
45
+ ) {
46
+ return 0.0/0.0; // NaN
47
+ }
48
+ if ( x <= mu ) {
49
+ return STDLIB_CONSTANT_FLOAT64_NINF;
50
+ }
51
+ z = x - mu;
52
+ return 0.5 * ( stdlib_base_ln( c ) - STDLIB_CONSTANT_FLOAT64_LN_TWO_PI - ( c/z ) - ( 3.0*stdlib_base_ln( z ) ) );
53
+ }