@stdlib/stats-base-dists-pareto-type1-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 +1 -1
- package/README.md +112 -18
- package/dist/index.d.ts +2 -2
- package/docs/types/index.d.ts +2 -2
- package/include/stdlib/stats/base/dists/pareto-type1/logpdf.h +38 -0
- package/lib/native.js +88 -0
- package/manifest.json +82 -0
- package/package.json +8 -3
- package/src/addon.c +23 -0
- package/src/main.c +54 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -163,21 +163,111 @@ y = mylogpdf( 2.0 );
|
|
|
163
163
|
<!-- eslint no-undef: "error" -->
|
|
164
164
|
|
|
165
165
|
```javascript
|
|
166
|
-
var
|
|
166
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
167
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
167
168
|
var logpdf = require( '@stdlib/stats-base-dists-pareto-type1-logpdf' );
|
|
168
169
|
|
|
169
|
-
var
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
var
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
170
|
+
var opts = {
|
|
171
|
+
'dtype': 'float64'
|
|
172
|
+
};
|
|
173
|
+
var alpha = uniform( 10, 0.0, 4.0, opts );
|
|
174
|
+
var beta = uniform( 10, 0.0, 4.0, opts );
|
|
175
|
+
var x = uniform( 10, 0.0, 8.0, opts );
|
|
176
|
+
|
|
177
|
+
logEachMap( 'x: %0.4f, α: %0.4f, β: %0.4f, ln(f(x;α,β)): %0.4f', x, alpha, beta, logpdf );
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
</section>
|
|
181
|
+
|
|
182
|
+
<!-- /.examples -->
|
|
183
|
+
|
|
184
|
+
<!-- C interface documentation. -->
|
|
185
|
+
|
|
186
|
+
* * *
|
|
187
|
+
|
|
188
|
+
<section class="c">
|
|
189
|
+
|
|
190
|
+
## C APIs
|
|
191
|
+
|
|
192
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
193
|
+
|
|
194
|
+
<section class="intro">
|
|
195
|
+
|
|
196
|
+
</section>
|
|
197
|
+
|
|
198
|
+
<!-- /.intro -->
|
|
199
|
+
|
|
200
|
+
<!-- C usage documentation. -->
|
|
201
|
+
|
|
202
|
+
<section class="usage">
|
|
203
|
+
|
|
204
|
+
### Usage
|
|
205
|
+
|
|
206
|
+
```c
|
|
207
|
+
#include "stdlib/stats/base/dists/pareto-type1/logpdf.h"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### stdlib_base_dists_pareto_type1_logpdf( x, alpha, beta )
|
|
211
|
+
|
|
212
|
+
Evaluates the natural logarithm of the probability density function (PDF) for a Pareto (Type I) distribution with parameters `alpha` (shape parameter) and `beta` (scale parameter).
|
|
213
|
+
|
|
214
|
+
```c
|
|
215
|
+
double y = stdlib_base_dists_pareto_type1_logpdf( 4.0, 1.0, 1.0 );
|
|
216
|
+
// returns ~-2.773
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The function accepts the following arguments:
|
|
220
|
+
|
|
221
|
+
- **x**: `[in] double` input value.
|
|
222
|
+
- **alpha**: `[in] double` shape parameter.
|
|
223
|
+
- **beta**: `[in] double` scale parameter.
|
|
224
|
+
|
|
225
|
+
```c
|
|
226
|
+
double stdlib_base_dists_pareto_type1_logpdf( const double x, const double alpha, const double beta );
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
</section>
|
|
230
|
+
|
|
231
|
+
<!-- /.usage -->
|
|
232
|
+
|
|
233
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
234
|
+
|
|
235
|
+
<section class="notes">
|
|
236
|
+
|
|
237
|
+
</section>
|
|
238
|
+
|
|
239
|
+
<!-- /.notes -->
|
|
240
|
+
|
|
241
|
+
<!-- C API usage examples. -->
|
|
242
|
+
|
|
243
|
+
<section class="examples">
|
|
244
|
+
|
|
245
|
+
### Examples
|
|
246
|
+
|
|
247
|
+
```c
|
|
248
|
+
#include "stdlib/stats/base/dists/pareto-type1/logpdf.h"
|
|
249
|
+
#include <stdlib.h>
|
|
250
|
+
#include <stdio.h>
|
|
251
|
+
|
|
252
|
+
static double random_uniform( const double min, const double max ) {
|
|
253
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
254
|
+
return min + ( v*(max-min) );
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
int main( void ) {
|
|
258
|
+
double alpha;
|
|
259
|
+
double beta;
|
|
260
|
+
double x;
|
|
261
|
+
double y;
|
|
262
|
+
int i;
|
|
263
|
+
|
|
264
|
+
for ( i = 0; i < 25; i++ ) {
|
|
265
|
+
alpha = random_uniform( 0.0, 8.0 );
|
|
266
|
+
beta = random_uniform( 0.0, 4.0 );
|
|
267
|
+
x = random_uniform( 0.0, 4.0 );
|
|
268
|
+
y = stdlib_base_dists_pareto_type1_logpdf( x, alpha, beta );
|
|
269
|
+
printf( "x: %lf, α: %lf, β: %lf, ln(f(x;α,β)): %lf\n", x, alpha, beta, y );
|
|
270
|
+
}
|
|
181
271
|
}
|
|
182
272
|
```
|
|
183
273
|
|
|
@@ -185,6 +275,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
185
275
|
|
|
186
276
|
<!-- /.examples -->
|
|
187
277
|
|
|
278
|
+
</section>
|
|
279
|
+
|
|
280
|
+
<!-- /.c -->
|
|
281
|
+
|
|
188
282
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
189
283
|
|
|
190
284
|
<section class="related">
|
|
@@ -219,7 +313,7 @@ See [LICENSE][stdlib-license].
|
|
|
219
313
|
|
|
220
314
|
## Copyright
|
|
221
315
|
|
|
222
|
-
Copyright © 2016-
|
|
316
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
223
317
|
|
|
224
318
|
</section>
|
|
225
319
|
|
|
@@ -232,8 +326,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
232
326
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-pareto-type1-logpdf.svg
|
|
233
327
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-pareto-type1-logpdf
|
|
234
328
|
|
|
235
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-pareto-type1-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
236
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-pareto-type1-logpdf/actions/workflows/test.yml?query=branch:v0.
|
|
329
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-pareto-type1-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
330
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-pareto-type1-logpdf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
237
331
|
|
|
238
332
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-pareto-type1-logpdf/main.svg
|
|
239
333
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-pareto-type1-logpdf?branch=main
|
|
@@ -245,8 +339,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
245
339
|
|
|
246
340
|
-->
|
|
247
341
|
|
|
248
|
-
[chat-image]: https://img.shields.io/
|
|
249
|
-
[chat-url]: https://
|
|
342
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
343
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
250
344
|
|
|
251
345
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
252
346
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference path="../docs/types/index.d.ts" />
|
|
2
|
-
import
|
|
3
|
-
export =
|
|
2
|
+
import logpdf from '../docs/types/index';
|
|
3
|
+
export = logpdf;
|
package/docs/types/index.d.ts
CHANGED
|
@@ -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_PARETO_TYPE1_LOGPDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_PARETO_TYPE1_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 (PDF) for a Pareto (Type I) distribution with shape parameter `alpha` and scale parameter `beta` at a value `x`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_pareto_type1_logpdf( const double x, const double alpha, const double beta );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_PARETO_TYPE1_LOGPDF_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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 (PDF) for a Pareto (Type I) distribution with shape parameter `alpha` and scale parameter `beta` at a value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {PositiveNumber} alpha - shape parameter
|
|
34
|
+
* @param {PositiveNumber} beta - scale parameter
|
|
35
|
+
* @returns {number} evaluated logPDF
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var y = logpdf( 4.0, 1.0, 1.0 );
|
|
39
|
+
* // returns ~-2.773
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var y = logpdf( 20.0, 1.0, 10.0 );
|
|
43
|
+
* // returns ~-3.689
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = logpdf( 7.0, 2.0, 6.0 );
|
|
47
|
+
* // returns ~-1.561
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var y = logpdf( 7.0, 6.0, 3.0 );
|
|
51
|
+
* // returns ~-5.238
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var y = logpdf( 1.0, 4.0, 2.0 );
|
|
55
|
+
* // returns -Infinity
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* var y = logpdf( 1.5, 4.0, 2.0 );
|
|
59
|
+
* // returns -Infinity
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* var y = logpdf( 0.5, -1.0, 0.5 );
|
|
63
|
+
* // returns NaN
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* var y = logpdf( 0.5, 0.5, -1.0 );
|
|
67
|
+
* // returns NaN
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* var y = logpdf( NaN, 1.0, 1.0 );
|
|
71
|
+
* // returns NaN
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* var y = logpdf( 0.5, NaN, 1.0 );
|
|
75
|
+
* // returns NaN
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* var y = logpdf( 0.5, 1.0, NaN );
|
|
79
|
+
* // returns NaN
|
|
80
|
+
*/
|
|
81
|
+
function logpdf( x, alpha, beta ) {
|
|
82
|
+
return addon( x, alpha, beta );
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
// EXPORTS //
|
|
87
|
+
|
|
88
|
+
module.exports = logpdf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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-ninf"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"task": "benchmark",
|
|
49
|
+
"wasm": false,
|
|
50
|
+
"src": [
|
|
51
|
+
"./src/main.c"
|
|
52
|
+
],
|
|
53
|
+
"include": [
|
|
54
|
+
"./include"
|
|
55
|
+
],
|
|
56
|
+
"libraries": [],
|
|
57
|
+
"libpath": [],
|
|
58
|
+
"dependencies": [
|
|
59
|
+
"@stdlib/math-base-assert-is-nan",
|
|
60
|
+
"@stdlib/math-base-special-ln",
|
|
61
|
+
"@stdlib/constants-float64-ninf"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"task": "examples",
|
|
66
|
+
"wasm": false,
|
|
67
|
+
"src": [
|
|
68
|
+
"./src/main.c"
|
|
69
|
+
],
|
|
70
|
+
"include": [
|
|
71
|
+
"./include"
|
|
72
|
+
],
|
|
73
|
+
"libraries": [],
|
|
74
|
+
"libpath": [],
|
|
75
|
+
"dependencies": [
|
|
76
|
+
"@stdlib/math-base-assert-is-nan",
|
|
77
|
+
"@stdlib/math-base-special-ln",
|
|
78
|
+
"@stdlib/constants-float64-ninf"
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-pareto-type1-logpdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Natural logarithm of the probability density function (PDF) for a Pareto (Type I) distribution.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -14,9 +14,12 @@
|
|
|
14
14
|
}
|
|
15
15
|
],
|
|
16
16
|
"main": "./lib",
|
|
17
|
+
"gypfile": false,
|
|
17
18
|
"directories": {
|
|
18
19
|
"doc": "./docs",
|
|
20
|
+
"include": "./include",
|
|
19
21
|
"lib": "./lib",
|
|
22
|
+
"src": "./src",
|
|
20
23
|
"dist": "./dist"
|
|
21
24
|
},
|
|
22
25
|
"types": "./docs/types",
|
|
@@ -32,9 +35,11 @@
|
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@stdlib/constants-float64-ninf": "^0.2.2",
|
|
34
37
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
35
|
-
"@stdlib/math-base-
|
|
38
|
+
"@stdlib/math-base-napi-ternary": "^0.3.1",
|
|
39
|
+
"@stdlib/math-base-special-ln": "^0.2.4",
|
|
36
40
|
"@stdlib/utils-constant-function": "^0.2.2",
|
|
37
|
-
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
|
|
41
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
42
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {},
|
|
40
45
|
"engines": {
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,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/pareto-type1/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_pareto_type1_logpdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
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/pareto-type1/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/ln.h"
|
|
22
|
+
#include "stdlib/constants/float64/ninf.h"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Evaluates the natural logarithm of the probability density function (PDF) for a Pareto (Type I) distribution with shape parameter `alpha` and scale parameter `beta` at a value `x`.
|
|
26
|
+
*
|
|
27
|
+
* @param x input value
|
|
28
|
+
* @param alpha shape parameter
|
|
29
|
+
* @param beta scale parameter
|
|
30
|
+
* @return evaluated logPDF
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* double y = stdlib_base_dists_pareto_type1_logpdf( 4.0, 1.0, 1.0 );
|
|
34
|
+
* // returns ~-2.773
|
|
35
|
+
*/
|
|
36
|
+
double stdlib_base_dists_pareto_type1_logpdf( const double x, const double alpha, const double beta ) {
|
|
37
|
+
double denom;
|
|
38
|
+
double num;
|
|
39
|
+
if (
|
|
40
|
+
stdlib_base_is_nan( alpha ) ||
|
|
41
|
+
stdlib_base_is_nan( beta ) ||
|
|
42
|
+
stdlib_base_is_nan( x ) ||
|
|
43
|
+
alpha <= 0.0 ||
|
|
44
|
+
beta <= 0.0
|
|
45
|
+
) {
|
|
46
|
+
return 0.0 / 0.0; // NaN
|
|
47
|
+
}
|
|
48
|
+
if ( x >= beta ) {
|
|
49
|
+
num = stdlib_base_ln( alpha ) + ( alpha * stdlib_base_ln( beta ) );
|
|
50
|
+
denom = ( alpha + 1.0 ) * stdlib_base_ln( x );
|
|
51
|
+
return num - denom;
|
|
52
|
+
}
|
|
53
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
54
|
+
}
|