@stdlib/stats-base-dists-betaprime-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 +114 -18
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/docs/types/index.d.ts +4 -4
- package/include/stdlib/stats/base/dists/betaprime/logpdf.h +38 -0
- package/lib/index.js +2 -2
- package/lib/native.js +84 -0
- package/manifest.json +90 -0
- package/package.json +8 -3
- package/src/addon.c +22 -0
- package/src/main.c +56 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -162,22 +162,114 @@ y = mylogPDF( 0.3 );
|
|
|
162
162
|
<!-- eslint no-undef: "error" -->
|
|
163
163
|
|
|
164
164
|
```javascript
|
|
165
|
-
var
|
|
165
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
166
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
166
167
|
var EPS = require( '@stdlib/constants-float64-eps' );
|
|
167
168
|
var logpdf = require( '@stdlib/stats-base-dists-betaprime-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, EPS, 5.0, opts );
|
|
174
|
+
var beta = uniform( 10, EPS, 5.0, opts );
|
|
175
|
+
var x = uniform( 10, 0.0, 1.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/betaprime/logpdf.h"
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### stdlib_base_dists_betaprime_logpdf( x, alpha, beta )
|
|
211
|
+
|
|
212
|
+
Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for a [beta prime][betaprime-distribution] distribution with parameters `alpha` (first shape parameter) and `beta` (second shape parameter).
|
|
213
|
+
|
|
214
|
+
```c
|
|
215
|
+
double y = stdlib_base_dists_betaprime_logpdf( 0.5, 0.5, 1.0 );
|
|
216
|
+
// returns ~-0.955
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The function accepts the following arguments:
|
|
220
|
+
|
|
221
|
+
- **x**: `[in] double` input value.
|
|
222
|
+
- **alpha**: `[in] double` first shape parameter.
|
|
223
|
+
- **beta**: `[in] double` second shape parameter.
|
|
224
|
+
|
|
225
|
+
```c
|
|
226
|
+
double stdlib_base_dists_betaprime_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`
|
|
234
|
+
element and another before the `/section` close. -->
|
|
235
|
+
|
|
236
|
+
<section class="notes">
|
|
237
|
+
|
|
238
|
+
</section>
|
|
239
|
+
|
|
240
|
+
<!-- /.notes -->
|
|
241
|
+
|
|
242
|
+
<!-- C API usage examples. -->
|
|
243
|
+
|
|
244
|
+
<section class="examples">
|
|
245
|
+
|
|
246
|
+
### Examples
|
|
247
|
+
|
|
248
|
+
```c
|
|
249
|
+
#include "stdlib/stats/base/dists/betaprime/logpdf.h"
|
|
250
|
+
#include "stdlib/constants/float64/eps.h"
|
|
251
|
+
#include <stdlib.h>
|
|
252
|
+
#include <stdio.h>
|
|
253
|
+
|
|
254
|
+
static double random_uniform( const double min, const double max ) {
|
|
255
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
256
|
+
return min + ( v*(max-min) );
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
int main( void ) {
|
|
260
|
+
double alpha;
|
|
261
|
+
double beta;
|
|
262
|
+
double x;
|
|
263
|
+
double y;
|
|
264
|
+
int i;
|
|
265
|
+
|
|
266
|
+
for ( i = 0; i < 10; i++ ) {
|
|
267
|
+
x = random_uniform( 0.0, 1.0 );
|
|
268
|
+
alpha = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
|
|
269
|
+
beta = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
|
|
270
|
+
y = stdlib_base_dists_betaprime_logpdf( x, alpha, beta );
|
|
271
|
+
printf( "x: %lf, α: %lf, β: %lf, ln(f(x;α,β)): %lf\n", x, alpha, beta, y );
|
|
272
|
+
}
|
|
181
273
|
}
|
|
182
274
|
```
|
|
183
275
|
|
|
@@ -185,6 +277,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
185
277
|
|
|
186
278
|
<!-- /.examples -->
|
|
187
279
|
|
|
280
|
+
</section>
|
|
281
|
+
|
|
282
|
+
<!-- /.c -->
|
|
283
|
+
|
|
188
284
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
189
285
|
|
|
190
286
|
<section class="related">
|
|
@@ -219,7 +315,7 @@ See [LICENSE][stdlib-license].
|
|
|
219
315
|
|
|
220
316
|
## Copyright
|
|
221
317
|
|
|
222
|
-
Copyright © 2016-
|
|
318
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
223
319
|
|
|
224
320
|
</section>
|
|
225
321
|
|
|
@@ -232,8 +328,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
232
328
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-betaprime-logpdf.svg
|
|
233
329
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-betaprime-logpdf
|
|
234
330
|
|
|
235
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-betaprime-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
236
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-betaprime-logpdf/actions/workflows/test.yml?query=branch:v0.
|
|
331
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-betaprime-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
332
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-betaprime-logpdf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
237
333
|
|
|
238
334
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-betaprime-logpdf/main.svg
|
|
239
335
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-betaprime-logpdf?branch=main
|
|
@@ -245,8 +341,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
245
341
|
|
|
246
342
|
-->
|
|
247
343
|
|
|
248
|
-
[chat-image]: https://img.shields.io/
|
|
249
|
-
[chat-url]: https://
|
|
344
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
345
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
250
346
|
|
|
251
347
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
252
348
|
|
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/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../lib/main.js", "../lib/factory.js", "../lib/index.js"],
|
|
4
|
-
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar betaln = require( '@stdlib/math-base-special-betaln' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the probability density function (logPDF) for a beta prime distribution with first shape parameter `alpha` and second shape parameter `beta` at a value `x`.\n*\n* @param {number} x - input value\n* @param {PositiveNumber} alpha - first shape parameter\n* @param {PositiveNumber} beta - second shape parameter\n* @returns {number} evaluated logPDF\n*\n* @example\n* var y = logpdf( 0.5, 1.0, 1.0 );\n* // returns ~-0.811\n*\n* @example\n* var y = logpdf( 0.5, 2.0, 4.0 );\n* // returns ~-0.13\n*\n* @example\n* var y = logpdf( 0.2, 2.0, 2.0 );\n* // returns ~-0.547\n*\n* @example\n* var y = logpdf( 0.8, 4.0, 4.0 );\n* // returns ~-0.43\n*\n* @example\n* var y = logpdf( -0.5, 4.0, 2.0 );\n* // returns -Infinity\n*\n* @example\n* var y = logpdf( 0.5, -1.0, 0.5 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.5, 0.5, -1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( NaN, 1.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.5, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.5, 1.0, NaN );\n* // returns NaN\n*/\nfunction logpdf( x, alpha, beta ) {\n\tvar out;\n\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( alpha ) ||\n\t\tisnan( beta ) ||\n\t\talpha <= 0.0 ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( x <= 0.0 ) {\n\t\t// Support of the BetaPrime distribution: (0,\u221E)\n\t\treturn NINF;\n\t}\n\tout = ( alpha-1.0 ) * ln( x );\n\tout -= ( alpha+beta ) * log1p( x );\n\tout -= betaln( alpha, beta );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = logpdf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar betaln = require( '@stdlib/math-base-special-betaln' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the natural logarithm of the probability density function (logPDF) for a beta prime distribution with first shape parameter `alpha` and second shape parameter `beta`.\n*\n* @param {PositiveNumber} alpha - first shape parameter\n* @param {PositiveNumber} beta - second shape parameter\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 0.5, 0.5 );\n*\n* var y = logpdf( 0.8 );\n* // returns ~-1.62\n*\n* y = logpdf( 0.3 );\n* // returns ~-0.805\n*/\nfunction factory( alpha, beta ) {\n\tvar betalnAB;\n\tif (\n\t\tisnan( alpha ) ||\n\t\tisnan( beta ) ||\n\t\talpha <= 0.0 ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\tbetalnAB = betaln( alpha, beta );\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the natural logarithm of the probability density function (PDF) for a beta prime distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated natural logarithm of the PDF\n\t*\n\t* @example\n\t* var y = logpdf( 0.3 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tvar out;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x <= 0.0 ) {\n\t\t\t// Support of the BetaPrime distribution: (0,\u221E)\n\t\t\treturn NINF;\n\t\t}\n\t\tout = ( alpha-1.0 ) * ln( x );\n\t\tout -= ( alpha+beta ) * log1p( x );\n\t\tout -= betalnAB;\n\t\treturn out;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Evaluate the natural logarithm of the probability density function (logPDF) for a beta prime distribution.\n*\n* @module @stdlib/stats-base-dists-betaprime-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-betaprime-logpdf' );\n*\n* var y = logpdf( 0.5, 1.0, 1.0 );\n* // returns ~-0.811\n*\n* y = logpdf( 0.5, 2.0, 4.0 );\n* // returns ~-0.13\n*\n* @example\n* var factory = require( '@stdlib/stats-base-dists-betaprime-logpdf' ).factory;\n*\n* var logpdf = factory( 0.5, 0.5 );\n*\n* var y = logpdf( 0.8 );\n* // returns ~-
|
|
4
|
+
"sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar betaln = require( '@stdlib/math-base-special-betaln' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the probability density function (logPDF) for a beta prime distribution with first shape parameter `alpha` and second shape parameter `beta` at a value `x`.\n*\n* @param {number} x - input value\n* @param {PositiveNumber} alpha - first shape parameter\n* @param {PositiveNumber} beta - second shape parameter\n* @returns {number} evaluated logPDF\n*\n* @example\n* var y = logpdf( 0.5, 1.0, 1.0 );\n* // returns ~-0.811\n*\n* @example\n* var y = logpdf( 0.5, 2.0, 4.0 );\n* // returns ~-0.13\n*\n* @example\n* var y = logpdf( 0.2, 2.0, 2.0 );\n* // returns ~-0.547\n*\n* @example\n* var y = logpdf( 0.8, 4.0, 4.0 );\n* // returns ~-0.43\n*\n* @example\n* var y = logpdf( -0.5, 4.0, 2.0 );\n* // returns -Infinity\n*\n* @example\n* var y = logpdf( 0.5, -1.0, 0.5 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.5, 0.5, -1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( NaN, 1.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.5, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.5, 1.0, NaN );\n* // returns NaN\n*/\nfunction logpdf( x, alpha, beta ) {\n\tvar out;\n\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( alpha ) ||\n\t\tisnan( beta ) ||\n\t\talpha <= 0.0 ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( x <= 0.0 ) {\n\t\t// Support of the BetaPrime distribution: (0,\u221E)\n\t\treturn NINF;\n\t}\n\tout = ( alpha-1.0 ) * ln( x );\n\tout -= ( alpha+beta ) * log1p( x );\n\tout -= betaln( alpha, beta );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = logpdf;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar betaln = require( '@stdlib/math-base-special-betaln' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the natural logarithm of the probability density function (logPDF) for a beta prime distribution with first shape parameter `alpha` and second shape parameter `beta`.\n*\n* @param {PositiveNumber} alpha - first shape parameter\n* @param {PositiveNumber} beta - second shape parameter\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 0.5, 0.5 );\n*\n* var y = logpdf( 0.8 );\n* // returns ~-1.62\n*\n* y = logpdf( 0.3 );\n* // returns ~-0.805\n*/\nfunction factory( alpha, beta ) {\n\tvar betalnAB;\n\tif (\n\t\tisnan( alpha ) ||\n\t\tisnan( beta ) ||\n\t\talpha <= 0.0 ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\tbetalnAB = betaln( alpha, beta );\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the natural logarithm of the probability density function (PDF) for a beta prime distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated natural logarithm of the PDF\n\t*\n\t* @example\n\t* var y = logpdf( 0.3 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tvar out;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x <= 0.0 ) {\n\t\t\t// Support of the BetaPrime distribution: (0,\u221E)\n\t\t\treturn NINF;\n\t\t}\n\t\tout = ( alpha-1.0 ) * ln( x );\n\t\tout -= ( alpha+beta ) * log1p( x );\n\t\tout -= betalnAB;\n\t\treturn out;\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Evaluate the natural logarithm of the probability density function (logPDF) for a beta prime distribution.\n*\n* @module @stdlib/stats-base-dists-betaprime-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-betaprime-logpdf' );\n*\n* var y = logpdf( 0.5, 1.0, 1.0 );\n* // returns ~-0.811\n*\n* y = logpdf( 0.5, 2.0, 4.0 );\n* // returns ~-0.13\n*\n* @example\n* var factory = require( '@stdlib/stats-base-dists-betaprime-logpdf' ).factory;\n*\n* var logpdf = factory( 0.5, 0.5 );\n*\n* var y = logpdf( 0.8 );\n* // returns ~-1.621\n*\n* y = logpdf( 0.3 );\n* // returns ~-0.805\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
|
|
5
5
|
"mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAS,QAAS,kCAAmC,EACrDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EAqDrD,SAASC,EAAQC,EAAGC,EAAOC,EAAO,CACjC,IAAIC,EAEJ,OACCR,EAAOK,CAAE,GACTL,EAAOM,CAAM,GACbN,EAAOO,CAAK,GACZD,GAAS,GACTC,GAAQ,EAED,IAEHF,GAAK,EAEFF,GAERK,GAAQF,EAAM,GAAQJ,EAAIG,CAAE,EAC5BG,IAASF,EAAMC,GAASN,EAAOI,CAAE,EACjCG,GAAOT,EAAQO,EAAOC,CAAK,EACpBC,EACR,CAKAV,EAAO,QAAUM,ICxGjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAS,QAAS,kCAAmC,EACrDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EAqBrD,SAASC,EAASC,EAAOC,EAAO,CAC/B,IAAIC,EACJ,GACCP,EAAOK,CAAM,GACbL,EAAOM,CAAK,GACZD,GAAS,GACTC,GAAQ,EAER,OAAOR,EAAkB,GAAI,EAE9B,OAAAS,EAAWR,EAAQM,EAAOC,CAAK,EACxBE,EAaP,SAASA,EAAQC,EAAI,CACpB,IAAIC,EACJ,OAAKV,EAAOS,CAAE,EACN,IAEHA,GAAK,EAEFN,GAERO,GAAQL,EAAM,GAAQH,EAAIO,CAAE,EAC5BC,IAASL,EAAMC,GAASL,EAAOQ,CAAE,EACjCC,GAAOH,EACAG,EACR,CACD,CAKAb,EAAO,QAAUO,IC3CjB,IAAIO,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
|
|
6
6
|
"names": ["require_main", "__commonJSMin", "exports", "module", "betaln", "isnan", "log1p", "ln", "NINF", "logpdf", "x", "alpha", "beta", "out", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "betaln", "isnan", "log1p", "ln", "NINF", "factory", "alpha", "beta", "betalnAB", "logpdf", "x", "out", "setReadOnly", "main", "factory"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -121,14 +121,14 @@ interface LogPDF {
|
|
|
121
121
|
* var mylogpdf = logpdf.factory( 0.5, 0.5 );
|
|
122
122
|
*
|
|
123
123
|
* var y = mylogpdf( 0.8 );
|
|
124
|
-
* // returns ~-
|
|
124
|
+
* // returns ~-1.62
|
|
125
125
|
*
|
|
126
126
|
* y = mylogpdf( 0.3 );
|
|
127
|
-
* // returns ~-0.
|
|
127
|
+
* // returns ~-0.805
|
|
128
128
|
*/
|
|
129
|
-
declare var
|
|
129
|
+
declare var logpdf: LogPDF;
|
|
130
130
|
|
|
131
131
|
|
|
132
132
|
// EXPORTS //
|
|
133
133
|
|
|
134
|
-
export =
|
|
134
|
+
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_BETAPRIME_LOGPDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_BETAPRIME_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 beta prime distribution with first shape parameter `alpha` and second shape parameter `beta`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_betaprime_logpdf( const double x, const double alpha, const double beta );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_BETAPRIME_LOGPDF_H
|
package/lib/index.js
CHANGED
package/lib/native.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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 prime 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.811
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var y = logpdf( 0.5, 2.0, 4.0 );
|
|
43
|
+
* // returns ~-0.13
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = logpdf( 0.2, 2.0, 2.0 );
|
|
47
|
+
* // returns ~-0.547
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var y = logpdf( 0.8, 4.0, 4.0 );
|
|
51
|
+
* // returns ~-0.43
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var y = logpdf( -0.5, 4.0, 2.0 );
|
|
55
|
+
* // returns -Infinity
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* var y = logpdf( 0.5, -1.0, 0.5 );
|
|
59
|
+
* // returns NaN
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* var y = logpdf( 0.5, 0.5, -1.0 );
|
|
63
|
+
* // returns NaN
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* var y = logpdf( NaN, 1.0, 1.0 );
|
|
67
|
+
* // returns NaN
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* var y = logpdf( 0.5, NaN, 1.0 );
|
|
71
|
+
* // returns NaN
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* var y = logpdf( 0.5, 1.0, NaN );
|
|
75
|
+
* // returns NaN
|
|
76
|
+
*/
|
|
77
|
+
function logpdf( x, alpha, beta ) {
|
|
78
|
+
return addon( x, alpha, beta );
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
// EXPORTS //
|
|
83
|
+
|
|
84
|
+
module.exports = logpdf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
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-ninf"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"task": "benchmark",
|
|
51
|
+
"wasm": false,
|
|
52
|
+
"src": [
|
|
53
|
+
"./src/main.c"
|
|
54
|
+
],
|
|
55
|
+
"include": [
|
|
56
|
+
"./include"
|
|
57
|
+
],
|
|
58
|
+
"libraries": [],
|
|
59
|
+
"libpath": [],
|
|
60
|
+
"dependencies": [
|
|
61
|
+
"@stdlib/math-base-assert-is-nan",
|
|
62
|
+
"@stdlib/math-base-special-betaln",
|
|
63
|
+
"@stdlib/math-base-special-log1p",
|
|
64
|
+
"@stdlib/math-base-special-ln",
|
|
65
|
+
"@stdlib/constants-float64-ninf",
|
|
66
|
+
"@stdlib/constants-float64-eps"
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"task": "examples",
|
|
71
|
+
"wasm": false,
|
|
72
|
+
"src": [
|
|
73
|
+
"./src/main.c"
|
|
74
|
+
],
|
|
75
|
+
"include": [
|
|
76
|
+
"./include"
|
|
77
|
+
],
|
|
78
|
+
"libraries": [],
|
|
79
|
+
"libpath": [],
|
|
80
|
+
"dependencies": [
|
|
81
|
+
"@stdlib/math-base-assert-is-nan",
|
|
82
|
+
"@stdlib/math-base-special-betaln",
|
|
83
|
+
"@stdlib/math-base-special-log1p",
|
|
84
|
+
"@stdlib/math-base-special-ln",
|
|
85
|
+
"@stdlib/constants-float64-ninf",
|
|
86
|
+
"@stdlib/constants-float64-eps"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-betaprime-logpdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Beta prime 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",
|
|
@@ -32,11 +35,13 @@
|
|
|
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-betaln": "^0.2.2",
|
|
36
40
|
"@stdlib/math-base-special-ln": "^0.2.4",
|
|
37
41
|
"@stdlib/math-base-special-log1p": "^0.2.3",
|
|
38
42
|
"@stdlib/utils-constant-function": "^0.2.2",
|
|
39
|
-
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
|
|
43
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
44
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {},
|
|
42
47
|
"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/betaprime/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/ternary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_betaprime_logpdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
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/math/base/assert/is_nan.h"
|
|
20
|
+
#include "stdlib/math/base/special/betaln.h"
|
|
21
|
+
#include "stdlib/math/base/special/log1p.h"
|
|
22
|
+
#include "stdlib/math/base/special/ln.h"
|
|
23
|
+
#include "stdlib/constants/float64/ninf.h"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Evaluates the natural logarithm of the probability density function (PDF) for a beta prime distribution with first shape parameter `alpha` and second shape parameter `beta`.
|
|
27
|
+
*
|
|
28
|
+
* @param x input value
|
|
29
|
+
* @param alpha first shape parameter
|
|
30
|
+
* @param beta second shape parameter
|
|
31
|
+
* @return evaluated logPDF
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* double y = stdlib_base_dists_beta_logpdf( 0.5, 1.0, 1.0 );
|
|
35
|
+
* // returns ~-0.811
|
|
36
|
+
*/
|
|
37
|
+
double stdlib_base_dists_betaprime_logpdf( const double x, const double alpha, const double beta ) {
|
|
38
|
+
double out;
|
|
39
|
+
if (
|
|
40
|
+
stdlib_base_is_nan( x ) ||
|
|
41
|
+
stdlib_base_is_nan( alpha ) ||
|
|
42
|
+
stdlib_base_is_nan( beta ) ||
|
|
43
|
+
alpha <= 0.0 ||
|
|
44
|
+
beta <= 0.0
|
|
45
|
+
) {
|
|
46
|
+
return 0.0 / 0.0;
|
|
47
|
+
}
|
|
48
|
+
if ( x <= 0.0 ) {
|
|
49
|
+
// Support of the BetaPrime distribution: (0,∞)
|
|
50
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
51
|
+
}
|
|
52
|
+
out = ( alpha-1.0 ) * stdlib_base_ln( x );
|
|
53
|
+
out -= ( alpha+beta ) * stdlib_base_log1p( x );
|
|
54
|
+
out -= stdlib_base_betaln( alpha, beta );
|
|
55
|
+
return out;
|
|
56
|
+
}
|