@stdlib/stats-base-dists-beta-logpdf 0.2.2 → 0.3.1
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 +122 -18
- package/dist/index.d.ts +2 -2
- package/docs/types/index.d.ts +2 -2
- package/include/stdlib/stats/base/dists/beta/logpdf.h +38 -0
- package/lib/native.js +88 -0
- package/manifest.json +93 -0
- package/package.json +14 -9
- package/src/addon.c +22 -0
- package/src/main.c +76 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -165,22 +165,114 @@ y = mylogPDF( 0.3 );
|
|
|
165
165
|
<!-- eslint no-undef: "error" -->
|
|
166
166
|
|
|
167
167
|
```javascript
|
|
168
|
-
var
|
|
168
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
169
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
169
170
|
var EPS = require( '@stdlib/constants-float64-eps' );
|
|
170
171
|
var logpdf = require( '@stdlib/stats-base-dists-beta-logpdf' );
|
|
171
172
|
|
|
172
|
-
var
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
var
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
173
|
+
var opts = {
|
|
174
|
+
'dtype': 'float64'
|
|
175
|
+
};
|
|
176
|
+
var alpha = uniform( 10, EPS, 5.0, opts );
|
|
177
|
+
var beta = uniform( 10, EPS, 5.0, opts );
|
|
178
|
+
var x = uniform( 10, 0.0, 1.0, opts );
|
|
179
|
+
|
|
180
|
+
logEachMap( 'x: %0.4f, α: %0.4f, β: %0.4f, ln(f(x;α,β)): %0.4f', x, alpha, beta, logpdf );
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
<!-- /.examples -->
|
|
186
|
+
|
|
187
|
+
<!-- C interface documentation. -->
|
|
188
|
+
|
|
189
|
+
* * *
|
|
190
|
+
|
|
191
|
+
<section class="c">
|
|
192
|
+
|
|
193
|
+
## C APIs
|
|
194
|
+
|
|
195
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
196
|
+
|
|
197
|
+
<section class="intro">
|
|
198
|
+
|
|
199
|
+
</section>
|
|
200
|
+
|
|
201
|
+
<!-- /.intro -->
|
|
202
|
+
|
|
203
|
+
<!-- C usage documentation. -->
|
|
204
|
+
|
|
205
|
+
<section class="usage">
|
|
206
|
+
|
|
207
|
+
### Usage
|
|
208
|
+
|
|
209
|
+
```c
|
|
210
|
+
#include "stdlib/stats/base/dists/beta/logpdf.h"
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### stdlib_base_dists_beta_logpdf( x, alpha, beta )
|
|
214
|
+
|
|
215
|
+
Evaluates the natural logarithm of the probability density function (logPDF) for a beta distribution with first shape parameter `alpha` and second shape parameter `beta`.
|
|
216
|
+
|
|
217
|
+
```c
|
|
218
|
+
double y = stdlib_base_dists_beta_logpdf( 0.5, 1.0, 1.0 );
|
|
219
|
+
// returns 0.0
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The function accepts the following arguments:
|
|
223
|
+
|
|
224
|
+
- **x**: `[in] double` input value.
|
|
225
|
+
- **alpha**: `[in] double` first shape parameter.
|
|
226
|
+
- **beta**: `[in] double` second shape parameter.
|
|
227
|
+
|
|
228
|
+
```c
|
|
229
|
+
double stdlib_base_dists_beta_logpdf( const double x, double alpha, const double beta );
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
</section>
|
|
233
|
+
|
|
234
|
+
<!-- /.usage -->
|
|
235
|
+
|
|
236
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section`
|
|
237
|
+
element and another before the `/section` close. -->
|
|
238
|
+
|
|
239
|
+
<section class="notes">
|
|
240
|
+
|
|
241
|
+
</section>
|
|
242
|
+
|
|
243
|
+
<!-- /.notes -->
|
|
244
|
+
|
|
245
|
+
<!-- C API usage examples. -->
|
|
246
|
+
|
|
247
|
+
<section class="examples">
|
|
248
|
+
|
|
249
|
+
### Examples
|
|
250
|
+
|
|
251
|
+
```c
|
|
252
|
+
#include "stdlib/stats/base/dists/beta/logpdf.h"
|
|
253
|
+
#include "stdlib/constants/float64/eps.h"
|
|
254
|
+
#include <stdlib.h>
|
|
255
|
+
#include <stdio.h>
|
|
256
|
+
|
|
257
|
+
static double random_uniform( const double min, const double max ) {
|
|
258
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
259
|
+
return min + ( v*(max-min) );
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
int main( void ) {
|
|
263
|
+
double alpha;
|
|
264
|
+
double beta;
|
|
265
|
+
double x;
|
|
266
|
+
double y;
|
|
267
|
+
int i;
|
|
268
|
+
|
|
269
|
+
for ( i = 0; i < 10; i++ ) {
|
|
270
|
+
x = random_uniform( 0.0, 1.0 );
|
|
271
|
+
alpha = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
|
|
272
|
+
beta = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
|
|
273
|
+
y = stdlib_base_dists_beta_logpdf( x, alpha, beta );
|
|
274
|
+
printf( "x: %lf, α: %lf, β: %lf, ln(f(x;α,β)): %lf\n", x, alpha, beta, y );
|
|
275
|
+
}
|
|
184
276
|
}
|
|
185
277
|
```
|
|
186
278
|
|
|
@@ -188,6 +280,18 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
188
280
|
|
|
189
281
|
<!-- /.examples -->
|
|
190
282
|
|
|
283
|
+
</section>
|
|
284
|
+
|
|
285
|
+
<!-- /.c -->
|
|
286
|
+
|
|
287
|
+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
288
|
+
|
|
289
|
+
<section class="references">
|
|
290
|
+
|
|
291
|
+
</section>
|
|
292
|
+
|
|
293
|
+
<!-- /.references -->
|
|
294
|
+
|
|
191
295
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
192
296
|
|
|
193
297
|
<section class="related">
|
|
@@ -222,7 +326,7 @@ See [LICENSE][stdlib-license].
|
|
|
222
326
|
|
|
223
327
|
## Copyright
|
|
224
328
|
|
|
225
|
-
Copyright © 2016-
|
|
329
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
226
330
|
|
|
227
331
|
</section>
|
|
228
332
|
|
|
@@ -235,8 +339,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
235
339
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-beta-logpdf.svg
|
|
236
340
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-beta-logpdf
|
|
237
341
|
|
|
238
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-beta-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
239
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-beta-logpdf/actions/workflows/test.yml?query=branch:v0.
|
|
342
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-beta-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.1
|
|
343
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-beta-logpdf/actions/workflows/test.yml?query=branch:v0.3.1
|
|
240
344
|
|
|
241
345
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-beta-logpdf/main.svg
|
|
242
346
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-beta-logpdf?branch=main
|
|
@@ -248,8 +352,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
248
352
|
|
|
249
353
|
-->
|
|
250
354
|
|
|
251
|
-
[chat-image]: https://img.shields.io/
|
|
252
|
-
[chat-url]: https://
|
|
355
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
356
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
253
357
|
|
|
254
358
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
255
359
|
|
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_BETA_LOGPDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_BETA_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 beta distribution with first shape parameter `alpha` and second shape parameter `beta`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_beta_logpdf( const double x, const double alpha, const double beta );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_BETA_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 (logPDF) for a beta distribution with first shape parameter `alpha` and second shape parameter `beta` at a value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {PositiveNumber} alpha - first shape parameter
|
|
34
|
+
* @param {PositiveNumber} beta - second shape parameter
|
|
35
|
+
* @returns {number} evaluated logPDF
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var y = logpdf( 0.5, 1.0, 1.0 );
|
|
39
|
+
* // returns 0.0
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var y = logpdf( 0.5, 2.0, 4.0 );
|
|
43
|
+
* // returns ~0.223
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = logpdf( 0.2, 2.0, 2.0 );
|
|
47
|
+
* // returns ~-0.041
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var y = logpdf( 0.8, 4.0, 4.0 );
|
|
51
|
+
* // returns ~-0.556
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var y = logpdf( -0.5, 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,93 @@
|
|
|
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-betaln",
|
|
44
|
+
"@stdlib/math-base-special-log1p",
|
|
45
|
+
"@stdlib/math-base-special-ln",
|
|
46
|
+
"@stdlib/constants-float64-pinf",
|
|
47
|
+
"@stdlib/constants-float64-ninf"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"task": "benchmark",
|
|
52
|
+
"wasm": false,
|
|
53
|
+
"src": [
|
|
54
|
+
"./src/main.c"
|
|
55
|
+
],
|
|
56
|
+
"include": [
|
|
57
|
+
"./include"
|
|
58
|
+
],
|
|
59
|
+
"libraries": [],
|
|
60
|
+
"libpath": [],
|
|
61
|
+
"dependencies": [
|
|
62
|
+
"@stdlib/math-base-assert-is-nan",
|
|
63
|
+
"@stdlib/math-base-special-betaln",
|
|
64
|
+
"@stdlib/math-base-special-log1p",
|
|
65
|
+
"@stdlib/math-base-special-ln",
|
|
66
|
+
"@stdlib/constants-float64-pinf",
|
|
67
|
+
"@stdlib/constants-float64-ninf",
|
|
68
|
+
"@stdlib/constants-float64-eps"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"task": "examples",
|
|
73
|
+
"wasm": false,
|
|
74
|
+
"src": [
|
|
75
|
+
"./src/main.c"
|
|
76
|
+
],
|
|
77
|
+
"include": [
|
|
78
|
+
"./include"
|
|
79
|
+
],
|
|
80
|
+
"libraries": [],
|
|
81
|
+
"libpath": [],
|
|
82
|
+
"dependencies": [
|
|
83
|
+
"@stdlib/math-base-assert-is-nan",
|
|
84
|
+
"@stdlib/math-base-special-betaln",
|
|
85
|
+
"@stdlib/math-base-special-log1p",
|
|
86
|
+
"@stdlib/math-base-special-ln",
|
|
87
|
+
"@stdlib/constants-float64-pinf",
|
|
88
|
+
"@stdlib/constants-float64-ninf",
|
|
89
|
+
"@stdlib/constants-float64-eps"
|
|
90
|
+
]
|
|
91
|
+
}
|
|
92
|
+
]
|
|
93
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-beta-logpdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Beta 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",
|
|
@@ -30,14 +33,16 @@
|
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@stdlib/constants-float64-ninf": "^0.2.
|
|
34
|
-
"@stdlib/constants-float64-pinf": "^0.2.
|
|
35
|
-
"@stdlib/math-base-assert-is-nan": "^0.2.
|
|
36
|
-
"@stdlib/math-base-
|
|
37
|
-
"@stdlib/math-base-special-
|
|
38
|
-
"@stdlib/math-base-special-
|
|
39
|
-
"@stdlib/
|
|
40
|
-
"@stdlib/utils-
|
|
36
|
+
"@stdlib/constants-float64-ninf": "^0.2.3",
|
|
37
|
+
"@stdlib/constants-float64-pinf": "^0.2.3",
|
|
38
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.3",
|
|
39
|
+
"@stdlib/math-base-napi-ternary": "^0.3.2",
|
|
40
|
+
"@stdlib/math-base-special-betaln": "^0.3.0",
|
|
41
|
+
"@stdlib/math-base-special-ln": "^0.2.5",
|
|
42
|
+
"@stdlib/math-base-special-log1p": "^0.2.4",
|
|
43
|
+
"@stdlib/utils-constant-function": "^0.2.3",
|
|
44
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3",
|
|
45
|
+
"@stdlib/utils-library-manifest": "^0.2.4"
|
|
41
46
|
},
|
|
42
47
|
"devDependencies": {},
|
|
43
48
|
"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/beta/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/ternary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_beta_logpdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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/beta/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/betaln.h"
|
|
22
|
+
#include "stdlib/math/base/special/log1p.h"
|
|
23
|
+
#include "stdlib/math/base/special/ln.h"
|
|
24
|
+
#include "stdlib/constants/float64/pinf.h"
|
|
25
|
+
#include "stdlib/constants/float64/ninf.h"
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Evaluates the natural logarithm of the probability density function (logPDF) for a beta distribution with first shape parameter `alpha` and second shape parameter `beta`.
|
|
29
|
+
*
|
|
30
|
+
* @param x input value
|
|
31
|
+
* @param alpha first shape parameter
|
|
32
|
+
* @param beta second shape parameter
|
|
33
|
+
* @return evaluated logPDF
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* double y = stdlib_base_dists_beta_logpdf( 0.5, 1.0, 1.0 );
|
|
37
|
+
* // returns 0.0
|
|
38
|
+
*/
|
|
39
|
+
double stdlib_base_dists_beta_logpdf( const double x, const double alpha, const double beta ) {
|
|
40
|
+
double out;
|
|
41
|
+
if (
|
|
42
|
+
stdlib_base_is_nan( x ) ||
|
|
43
|
+
stdlib_base_is_nan( alpha ) ||
|
|
44
|
+
stdlib_base_is_nan( beta ) ||
|
|
45
|
+
alpha <= 0.0 ||
|
|
46
|
+
beta <= 0.0
|
|
47
|
+
) {
|
|
48
|
+
return 0.0 / 0.0;
|
|
49
|
+
}
|
|
50
|
+
if ( x < 0.0 || x > 1.0 ) {
|
|
51
|
+
// Support of the Beta distribution: [0,1]
|
|
52
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
53
|
+
}
|
|
54
|
+
if ( x == 0.0 ) {
|
|
55
|
+
if ( alpha < 1.0 ) {
|
|
56
|
+
return STDLIB_CONSTANT_FLOAT64_PINF;
|
|
57
|
+
}
|
|
58
|
+
if ( alpha > 1.0 ) {
|
|
59
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
60
|
+
}
|
|
61
|
+
return stdlib_base_ln( beta );
|
|
62
|
+
}
|
|
63
|
+
if ( x == 1.0 ) {
|
|
64
|
+
if ( beta < 1.0 ) {
|
|
65
|
+
return STDLIB_CONSTANT_FLOAT64_PINF;
|
|
66
|
+
}
|
|
67
|
+
if ( beta > 1.0 ) {
|
|
68
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
69
|
+
}
|
|
70
|
+
return stdlib_base_ln( alpha );
|
|
71
|
+
}
|
|
72
|
+
out = ( alpha-1.0 ) * stdlib_base_ln( x );
|
|
73
|
+
out += ( beta-1.0 ) * stdlib_base_log1p( -x );
|
|
74
|
+
out -= stdlib_base_betaln( alpha, beta );
|
|
75
|
+
return out;
|
|
76
|
+
}
|