@stdlib/stats-base-dists-triangular-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 +122 -11
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/docs/types/index.d.ts +2 -2
- package/include/stdlib/stats/base/dists/triangular/logpdf.h +38 -0
- package/lib/main.js +1 -1
- package/lib/native.js +81 -0
- package/manifest.json +90 -0
- package/package.json +8 -3
- package/src/addon.c +22 -0
- package/src/main.c +62 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ y = logpdf( 1.0, 0.0, -1.0, 0.5 );
|
|
|
121
121
|
|
|
122
122
|
#### logpdf.factory( a, b, c )
|
|
123
123
|
|
|
124
|
-
Returns a function for evaluating the natural logarithm of the [probability density function][pdf] (PDF) of a [triangular][triangular-distribution] distribution with parameters `a` (lower limit), `b` (upper limit) and `c` (mode).
|
|
124
|
+
Returns a function for evaluating the natural logarithm of the [probability density function][pdf] (PDF) of a [triangular][triangular-distribution] distribution with parameters `a` (lower limit), `b` (upper limit), and `c` (mode).
|
|
125
125
|
|
|
126
126
|
```javascript
|
|
127
127
|
var mylogpdf = logpdf.factory( 0.0, 10.0, 5.0 );
|
|
@@ -153,7 +153,7 @@ y = mylogpdf( 12.0 );
|
|
|
153
153
|
<!-- eslint no-undef: "error" -->
|
|
154
154
|
|
|
155
155
|
```javascript
|
|
156
|
-
var
|
|
156
|
+
var uniform = require( '@stdlib/random-base-uniform' );
|
|
157
157
|
var logpdf = require( '@stdlib/stats-base-dists-triangular-logpdf' );
|
|
158
158
|
|
|
159
159
|
var a;
|
|
@@ -164,10 +164,10 @@ var y;
|
|
|
164
164
|
var i;
|
|
165
165
|
|
|
166
166
|
for ( i = 0; i < 25; i++ ) {
|
|
167
|
-
x =
|
|
168
|
-
a =
|
|
169
|
-
b = a +
|
|
170
|
-
c = a
|
|
167
|
+
x = uniform( 0.0, 30.0 );
|
|
168
|
+
a = uniform( 0.0, 10.0 );
|
|
169
|
+
b = uniform( a, a + 40.0 );
|
|
170
|
+
c = uniform( a, b );
|
|
171
171
|
y = logpdf( x, a, b, c );
|
|
172
172
|
console.log( 'x: %d, a: %d, b: %d, c: %d, ln(f(x;a,b,c)): %d', x.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), c.toFixed( 4 ), y.toFixed( 4 ) );
|
|
173
173
|
}
|
|
@@ -177,6 +177,117 @@ for ( i = 0; i < 25; i++ ) {
|
|
|
177
177
|
|
|
178
178
|
<!-- /.examples -->
|
|
179
179
|
|
|
180
|
+
<!-- C interface documentation. -->
|
|
181
|
+
|
|
182
|
+
* * *
|
|
183
|
+
|
|
184
|
+
<section class="c">
|
|
185
|
+
|
|
186
|
+
## C APIs
|
|
187
|
+
|
|
188
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
189
|
+
|
|
190
|
+
<section class="intro">
|
|
191
|
+
|
|
192
|
+
</section>
|
|
193
|
+
|
|
194
|
+
<!-- /.intro -->
|
|
195
|
+
|
|
196
|
+
<!-- C usage documentation. -->
|
|
197
|
+
|
|
198
|
+
<section class="usage">
|
|
199
|
+
|
|
200
|
+
### Usage
|
|
201
|
+
|
|
202
|
+
```c
|
|
203
|
+
#include "stdlib/stats/base/dists/triangular/logpdf.h"
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### stdlib_base_dists_triangular_logpdf( x, a, b, c )
|
|
207
|
+
|
|
208
|
+
Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for a [triangular][triangular-distribution] distribution with parameters `a` (lower limit), `b` (upper limit), and `c` (mode).
|
|
209
|
+
|
|
210
|
+
```c
|
|
211
|
+
double y = stdlib_base_dists_triangular_logpdf( 0.5, -1.0, 1.0, 0.0 );
|
|
212
|
+
// returns ~-0.693
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The function accepts the following arguments:
|
|
216
|
+
|
|
217
|
+
- **x**: `[in] double` input value.
|
|
218
|
+
- **a**: `[in] double` lower limit.
|
|
219
|
+
- **b**: `[in] double` upper limit.
|
|
220
|
+
- **c**: `[in] double` mode.
|
|
221
|
+
|
|
222
|
+
```c
|
|
223
|
+
double stdlib_base_dists_triangular_logpdf( const double x, const double a, const double b, const double c );
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
</section>
|
|
227
|
+
|
|
228
|
+
<!-- /.usage -->
|
|
229
|
+
|
|
230
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
231
|
+
|
|
232
|
+
<section class="notes">
|
|
233
|
+
|
|
234
|
+
</section>
|
|
235
|
+
|
|
236
|
+
<!-- /.notes -->
|
|
237
|
+
|
|
238
|
+
<!-- C API usage examples. -->
|
|
239
|
+
|
|
240
|
+
<section class="examples">
|
|
241
|
+
|
|
242
|
+
### Examples
|
|
243
|
+
|
|
244
|
+
```c
|
|
245
|
+
#include "stdlib/stats/base/dists/triangular/logpdf.h"
|
|
246
|
+
#include "stdlib/constants/float64/eps.h"
|
|
247
|
+
#include <stdlib.h>
|
|
248
|
+
#include <stdio.h>
|
|
249
|
+
#include <math.h>
|
|
250
|
+
|
|
251
|
+
static double random_uniform( const double min, const double max ) {
|
|
252
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
253
|
+
return min + ( v*(max-min) );
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
int main( void ) {
|
|
257
|
+
double a;
|
|
258
|
+
double b;
|
|
259
|
+
double c;
|
|
260
|
+
double x;
|
|
261
|
+
double y;
|
|
262
|
+
int i;
|
|
263
|
+
|
|
264
|
+
for ( i = 0; i < 25; i++ ) {
|
|
265
|
+
x = random_uniform( 0.0, 30.0 );
|
|
266
|
+
a = random_uniform( 0.0, 10.0 );
|
|
267
|
+
b = random_uniform( a + STDLIB_CONSTANT_FLOAT64_EPS, 40.0 );
|
|
268
|
+
c = random_uniform( a, b );
|
|
269
|
+
y = stdlib_base_dists_triangular_logpdf( x, a, b, c );
|
|
270
|
+
printf( "x: %lf, a: %lf, b: %lf, c: %lf, ln(f(x;a,b,c)): %lf\n", x, a, b, c, y );
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
</section>
|
|
276
|
+
|
|
277
|
+
<!-- /.examples -->
|
|
278
|
+
|
|
279
|
+
</section>
|
|
280
|
+
|
|
281
|
+
<!-- /.c -->
|
|
282
|
+
|
|
283
|
+
<!-- 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. -->
|
|
284
|
+
|
|
285
|
+
<section class="references">
|
|
286
|
+
|
|
287
|
+
</section>
|
|
288
|
+
|
|
289
|
+
<!-- /.references -->
|
|
290
|
+
|
|
180
291
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
181
292
|
|
|
182
293
|
<section class="related">
|
|
@@ -211,7 +322,7 @@ See [LICENSE][stdlib-license].
|
|
|
211
322
|
|
|
212
323
|
## Copyright
|
|
213
324
|
|
|
214
|
-
Copyright © 2016-
|
|
325
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
215
326
|
|
|
216
327
|
</section>
|
|
217
328
|
|
|
@@ -224,8 +335,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
224
335
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-triangular-logpdf.svg
|
|
225
336
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-triangular-logpdf
|
|
226
337
|
|
|
227
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-triangular-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
228
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-triangular-logpdf/actions/workflows/test.yml?query=branch:v0.
|
|
338
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-triangular-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
339
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-triangular-logpdf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
229
340
|
|
|
230
341
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-triangular-logpdf/main.svg
|
|
231
342
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-triangular-logpdf?branch=main
|
|
@@ -237,8 +348,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
237
348
|
|
|
238
349
|
-->
|
|
239
350
|
|
|
240
|
-
[chat-image]: https://img.shields.io/
|
|
241
|
-
[chat-url]: https://
|
|
351
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
352
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
242
353
|
|
|
243
354
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
244
355
|
|
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 isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the probability density function (PDF) for a triangular distribution with lower limit `a
|
|
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 isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the probability density function (PDF) for a triangular distribution with lower limit `a`, upper limit `b`, and mode `c` at a value `x`.\n*\n* @param {number} x - input value\n* @param {number} a - lower limit\n* @param {number} b - upper limit\n* @param {number} c - mode\n* @returns {number} evaluated logPDF\n*\n* @example\n* var y = logpdf( 0.5, -1.0, 1.0, 0.0 );\n* // returns ~-0.693\n*\n* @example\n* var y = logpdf( 0.5, -1.0, 1.0, 0.5 );\n* // returns 0.0\n*\n* @example\n* var y = logpdf( -10.0, -20.0, 0.0, -2.0 );\n* // returns ~-2.89\n*\n* @example\n* var y = logpdf( -2.0, -1.0, 1.0, 0.0 );\n* // returns -Infinity\n*\n* @example\n* var y = logpdf( NaN, 0.0, 1.0, 0.5 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, NaN, 1.0, 0.5 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, 0.0, NaN, 0.5 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 2.0, 1.0, 0.0, NaN );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 2.0, 1.0, 0.0, 1.5 );\n* // returns NaN\n*/\nfunction logpdf( x, a, b, c ) {\n\tvar denom1;\n\tvar denom2;\n\tvar denom3;\n\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( a ) ||\n\t\tisnan( b ) ||\n\t\tisnan( c ) ||\n\t\ta > c ||\n\t\tc > b\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( x < a ) {\n\t\treturn NINF;\n\t}\n\tdenom1 = ln( b - a ) + ln( c - a );\n\tdenom2 = ln( b - a );\n\tdenom3 = ln( b - a ) + ln( b - c );\n\n\t// Case: x >= a\n\tif ( x < c ) {\n\t\treturn LN2 + ln( x - a ) - denom1;\n\t}\n\tif ( x === c ) {\n\t\treturn LN2 - denom2;\n\t}\n\t// Case: x > c\n\tif ( x <= b ) {\n\t\treturn LN2 + ln( b - x ) - denom3;\n\t}\n\t// Case: x > b\n\treturn NINF;\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 isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the natural logarithm of the probability density function (PDF) for a triangular distribution with lower limit `a` and upper limit `b` and mode `c`.\n*\n* @param {number} a - lower limit\n* @param {number} b - upper limit\n* @param {number} c - mode\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 0.0, 10.0, 5.0 );\n* var y = logpdf( 2.0 );\n* // returns ~-2.526\n*\n* y = logpdf( 12.0 );\n* // returns -Infinity\n*/\nfunction factory( a, b, c ) {\n\tvar denom1;\n\tvar denom2;\n\tvar denom3;\n\n\tif (\n\t\tisnan( a ) ||\n\t\tisnan( b ) ||\n\t\tisnan( c ) ||\n\t\ta > c ||\n\t\tc > b\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\n\tdenom1 = ln( b - a ) + ln( c - a );\n\tdenom2 = ln( b - a );\n\tdenom3 = ln( b - a ) + ln( b - c );\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the natural logarithm of the probability density function (PDF) for a triangular distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logPDF\n\t*\n\t* @example\n\t* var y = logpdf( 12.0 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x < a ) {\n\t\t\treturn NINF;\n\t\t}\n\t\t// Case: x >= a\n\t\tif ( x < c ) {\n\t\t\treturn LN2 + ln( x - a ) - denom1;\n\t\t}\n\t\tif ( x === c ) {\n\t\t\treturn LN2 - denom2;\n\t\t}\n\t\t// Case: x > c\n\t\tif ( x <= b ) {\n\t\t\treturn LN2 + ln( b - x ) - denom3;\n\t\t}\n\t\t// Case: x > b\n\t\treturn NINF;\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* Triangular distribution logarithm of probability density function (PDF).\n*\n* @module @stdlib/stats-base-dists-triangular-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-triangular-logpdf' );\n*\n* var y = logpdf( 0.5, -1.0, 1.0, 0.0 );\n* // returns ~-0.693\n*\n* y = logpdf( 0.5, -1.0, 1.0, 0.5 );\n* // returns 0.0\n*\n* y = logpdf( -10.0, -20.0, 0.0, -2.0 );\n* // returns ~-2.89\n*\n* var mylogpdf = logpdf.factory( 0.0, 10.0, 5.0 );\n* y = mylogpdf( 2.0 );\n* // returns ~-2.526\n*\n* y = mylogpdf( 12.0 );\n* // returns -Infinity\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,EAAQ,QAAS,iCAAkC,EACnDC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EACjDC,EAAM,QAAS,kCAAmC,EAkDtD,SAASC,EAAQC,EAAGC,EAAGC,EAAGC,EAAI,CAC7B,IAAIC,EACAC,EACAC,EAEJ,OACCX,EAAOK,CAAE,GACTL,EAAOM,CAAE,GACTN,EAAOO,CAAE,GACTP,EAAOQ,CAAE,GACTF,EAAIE,GACJA,EAAID,EAEG,IAEHF,EAAIC,EACDJ,GAERO,EAASR,EAAIM,EAAID,CAAE,EAAIL,EAAIO,EAAIF,CAAE,EACjCI,EAAST,EAAIM,EAAID,CAAE,EACnBK,EAASV,EAAIM,EAAID,CAAE,EAAIL,EAAIM,EAAIC,CAAE,EAG5BH,EAAIG,EACDL,EAAMF,EAAII,EAAIC,CAAE,EAAIG,EAEvBJ,IAAMG,EACHL,EAAMO,EAGTL,GAAKE,EACFJ,EAAMF,EAAIM,EAAIF,CAAE,EAAIM,EAGrBT,EACR,CAKAH,EAAO,QAAUK,ICnHjB,IAAAQ,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAQ,QAAS,iCAAkC,EACnDC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EACjDC,EAAM,QAAS,kCAAmC,EAqBtD,SAASC,EAASC,EAAGC,EAAGC,EAAI,CAC3B,IAAIC,EACAC,EACAC,EAEJ,GACCV,EAAOK,CAAE,GACTL,EAAOM,CAAE,GACTN,EAAOO,CAAE,GACTF,EAAIE,GACJA,EAAID,EAEJ,OAAOP,EAAkB,GAAI,EAG9B,OAAAS,EAASP,EAAIK,EAAID,CAAE,EAAIJ,EAAIM,EAAIF,CAAE,EACjCI,EAASR,EAAIK,EAAID,CAAE,EACnBK,EAAST,EAAIK,EAAID,CAAE,EAAIJ,EAAIK,EAAIC,CAAE,EAC1BI,EAaP,SAASA,EAAQC,EAAI,CACpB,OAAKZ,EAAOY,CAAE,EACN,IAEHA,EAAIP,EACDH,EAGHU,EAAIL,EACDJ,EAAMF,EAAIW,EAAIP,CAAE,EAAIG,EAEvBI,IAAML,EACHJ,EAAMM,EAGTG,GAAKN,EACFH,EAAMF,EAAIK,EAAIM,CAAE,EAAIF,EAGrBR,CACR,CACD,CAKAJ,EAAO,QAAUM,ICzDjB,IAAIS,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
|
|
6
6
|
"names": ["require_main", "__commonJSMin", "exports", "module", "isnan", "ln", "NINF", "LN2", "logpdf", "x", "a", "b", "c", "denom1", "denom2", "denom3", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "isnan", "ln", "NINF", "LN2", "factory", "a", "b", "c", "denom1", "denom2", "denom3", "logpdf", "x", "setReadOnly", "main", "factory"]
|
|
7
7
|
}
|
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_TRIANGULAR_LOGPDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_TRIANGULAR_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 triangular distribution with lower limit `a`, upper limit `b`, and mode `c` at a value `x`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_triangular_logpdf( const double x, const double a, const double b, const double c );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_TRIANGULAR_LOGPDF_H
|
package/lib/main.js
CHANGED
|
@@ -29,7 +29,7 @@ var LN2 = require( '@stdlib/constants-float64-ln-two' );
|
|
|
29
29
|
// MAIN //
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* Evaluates the natural logarithm of the probability density function (PDF) for a triangular distribution with lower limit `a
|
|
32
|
+
* Evaluates the natural logarithm of the probability density function (PDF) for a triangular distribution with lower limit `a`, upper limit `b`, and mode `c` at a value `x`.
|
|
33
33
|
*
|
|
34
34
|
* @param {number} x - input value
|
|
35
35
|
* @param {number} a - lower limit
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
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 triangular distribution with lower limit `a`, upper limit `b`, and mode `c` at a value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {number} a - lower limit
|
|
34
|
+
* @param {number} b - upper limit
|
|
35
|
+
* @param {number} c - mode
|
|
36
|
+
* @returns {number} evaluated logPDF
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* var y = logpdf( 0.5, -1.0, 1.0, 0.0 );
|
|
40
|
+
* // returns ~-0.693
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* var y = logpdf( 0.5, -1.0, 1.0, 0.5 );
|
|
44
|
+
* // returns 0.0
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* var y = logpdf( -10.0, -20.0, 0.0, -2.0 );
|
|
48
|
+
* // returns ~-2.89
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* var y = logpdf( -2.0, -1.0, 1.0, 0.0 );
|
|
52
|
+
* // returns -Infinity
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* var y = logpdf( NaN, 0.0, 1.0, 0.5 );
|
|
56
|
+
* // returns NaN
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* var y = logpdf( 0.0, NaN, 1.0, 0.5 );
|
|
60
|
+
* // returns NaN
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* var y = logpdf( 0.0, 0.0, NaN, 0.5 );
|
|
64
|
+
* // returns NaN
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* var y = logpdf( 2.0, 1.0, 0.0, NaN );
|
|
68
|
+
* // returns NaN
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* var y = logpdf( 2.0, 1.0, 0.0, 1.5 );
|
|
72
|
+
* // returns NaN
|
|
73
|
+
*/
|
|
74
|
+
function logpdf( x, a, b, c ) {
|
|
75
|
+
return addon( x, a, b, c );
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
// EXPORTS //
|
|
80
|
+
|
|
81
|
+
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-quaternary",
|
|
42
|
+
"@stdlib/math-base-assert-is-nan",
|
|
43
|
+
"@stdlib/constants-float64-ninf",
|
|
44
|
+
"@stdlib/math-base-special-ln",
|
|
45
|
+
"@stdlib/constants-float64-ln-two",
|
|
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/constants-float64-eps",
|
|
63
|
+
"@stdlib/constants-float64-ninf",
|
|
64
|
+
"@stdlib/math-base-special-ln",
|
|
65
|
+
"@stdlib/constants-float64-ln-two",
|
|
66
|
+
"@stdlib/constants-float64-ninf"
|
|
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/constants-float64-eps",
|
|
83
|
+
"@stdlib/constants-float64-ninf",
|
|
84
|
+
"@stdlib/math-base-special-ln",
|
|
85
|
+
"@stdlib/constants-float64-ln-two",
|
|
86
|
+
"@stdlib/constants-float64-ninf"
|
|
87
|
+
]
|
|
88
|
+
}
|
|
89
|
+
]
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-triangular-logpdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Triangular 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": "^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-
|
|
39
|
+
"@stdlib/math-base-napi-quaternary": "^0.2.3",
|
|
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/triangular/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/quaternary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DDDD_D( stdlib_base_dists_triangular_logpdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
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/triangular/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/constants/float64/ninf.h"
|
|
22
|
+
#include "stdlib/constants/float64/ln_two.h"
|
|
23
|
+
#include "stdlib/math/base/special/ln.h"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Evaluates the natural logarithm of the probability density function (PDF) for a triangular distribution with lower limit `a`, upper limit `b`, and mode `c` at a value `x`.
|
|
27
|
+
*
|
|
28
|
+
* @param x input value
|
|
29
|
+
* @param a lower limit
|
|
30
|
+
* @param b upper limit
|
|
31
|
+
* @param c mode
|
|
32
|
+
* @return evaluated logPDF
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* double y = stdlib_base_dists_triangular_logpdf( 0.5, -1.0, 1.0, 0.0 );
|
|
36
|
+
* // returns ~-0.693
|
|
37
|
+
*/
|
|
38
|
+
double stdlib_base_dists_triangular_logpdf( const double x, const double a, const double b, const double c ) {
|
|
39
|
+
if (
|
|
40
|
+
stdlib_base_is_nan( x ) ||
|
|
41
|
+
stdlib_base_is_nan( a ) ||
|
|
42
|
+
stdlib_base_is_nan( b ) ||
|
|
43
|
+
stdlib_base_is_nan( c ) ||
|
|
44
|
+
a > c ||
|
|
45
|
+
c > b
|
|
46
|
+
) {
|
|
47
|
+
return 0.0/0.0; // NaN
|
|
48
|
+
}
|
|
49
|
+
if ( x < a ) {
|
|
50
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
51
|
+
}
|
|
52
|
+
if ( x < c ) {
|
|
53
|
+
return STDLIB_CONSTANT_FLOAT64_LN2 + stdlib_base_ln( x - a ) - stdlib_base_ln( c - a ) - stdlib_base_ln( b - a );
|
|
54
|
+
}
|
|
55
|
+
if ( x == c ) {
|
|
56
|
+
return STDLIB_CONSTANT_FLOAT64_LN2 - stdlib_base_ln( b - a );
|
|
57
|
+
}
|
|
58
|
+
if( x <= b ){
|
|
59
|
+
return STDLIB_CONSTANT_FLOAT64_LN2 + stdlib_base_ln( b - x ) - stdlib_base_ln( b - c ) - stdlib_base_ln( b - a );
|
|
60
|
+
}
|
|
61
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
62
|
+
}
|