@stdlib/stats-base-dists-gumbel-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 +97 -19
- 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/gumbel/logpdf.h +38 -0
- package/lib/index.js +2 -2
- package/lib/native.js +73 -0
- package/manifest.json +86 -0
- package/package.json +7 -2
- package/src/addon.c +23 -0
- package/src/main.c +52 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ Returns a `function` for evaluating the logarithm of the [PDF][pdf] (PDF) for a
|
|
|
117
117
|
```javascript
|
|
118
118
|
var mylogpdf = logpdf.factory( 10.0, 2.0 );
|
|
119
119
|
|
|
120
|
-
y = mylogpdf( 10.0 );
|
|
120
|
+
var y = mylogpdf( 10.0 );
|
|
121
121
|
// returns ~-1.693
|
|
122
122
|
|
|
123
123
|
y = mylogpdf( 12.0 );
|
|
@@ -145,21 +145,95 @@ y = mylogpdf( 12.0 );
|
|
|
145
145
|
<!-- eslint no-undef: "error" -->
|
|
146
146
|
|
|
147
147
|
```javascript
|
|
148
|
-
var
|
|
148
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
149
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
149
150
|
var logpdf = require( '@stdlib/stats-base-dists-gumbel-logpdf' );
|
|
150
151
|
|
|
151
|
-
var
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
var
|
|
155
|
-
var
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
var opts = {
|
|
153
|
+
'dtype': 'float64'
|
|
154
|
+
};
|
|
155
|
+
var beta = uniform( 100, 0.0, 10.0, opts );
|
|
156
|
+
var mu = uniform( 100, 0.0, 10.0, opts );
|
|
157
|
+
var x = uniform( 100, 0.0, 10.0, opts );
|
|
158
|
+
|
|
159
|
+
logEachMap( 'x: %0.4f, µ: %0.4f, β: %0.4f, ln(f(x;µ,β)): %0.4f', x, mu, beta, logpdf );
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
</section>
|
|
163
|
+
|
|
164
|
+
<!-- /.examples -->
|
|
165
|
+
|
|
166
|
+
<!-- C usage documentation. -->
|
|
167
|
+
|
|
168
|
+
<section class="usage">
|
|
169
|
+
|
|
170
|
+
### Usage
|
|
171
|
+
|
|
172
|
+
```c
|
|
173
|
+
#include "stdlib/stats/base/dists/gumbel/logpdf.h"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### stdlib_base_dists_gumbel_logcdf( x, mu, beta )
|
|
177
|
+
|
|
178
|
+
Evaluates the logarithm of the [probability density function][pdf] (PDF) for a [Gumbel][gumbel-distribution] distribution with parameters `mu` (location parameter) and `beta > 0` (scale parameter).
|
|
179
|
+
|
|
180
|
+
```c
|
|
181
|
+
double out = stdlib_base_dists_gumbel_logpdf( 0.0, 0.0, 2.0 );
|
|
182
|
+
// returns ~-1.693
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
The function accepts the following arguments:
|
|
186
|
+
|
|
187
|
+
- **x**: `[in] double` input value.
|
|
188
|
+
- **mu**: `[in] double` location parameter.
|
|
189
|
+
- **beta**: `[in] double` scale parameter.
|
|
190
|
+
|
|
191
|
+
```c
|
|
192
|
+
double stdlib_base_dists_gumbel_logpdf( const double x, const double mu, const double beta );
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
</section>
|
|
196
|
+
|
|
197
|
+
<!-- /.usage -->
|
|
198
|
+
|
|
199
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
200
|
+
|
|
201
|
+
<section class="notes">
|
|
202
|
+
|
|
203
|
+
</section>
|
|
204
|
+
|
|
205
|
+
<!-- /.notes -->
|
|
206
|
+
|
|
207
|
+
<!-- C API usage examples. -->
|
|
208
|
+
|
|
209
|
+
<section class="examples">
|
|
210
|
+
|
|
211
|
+
### Examples
|
|
212
|
+
|
|
213
|
+
```c
|
|
214
|
+
#include "stdlib/stats/base/dists/gumbel/logpdf.h"
|
|
215
|
+
#include <stdlib.h>
|
|
216
|
+
#include <stdio.h>
|
|
217
|
+
|
|
218
|
+
static double random_uniform( const double min, const double max ) {
|
|
219
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
220
|
+
return min + ( v*(max-min) );
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
int main( void ) {
|
|
224
|
+
double beta;
|
|
225
|
+
double mu;
|
|
226
|
+
double x;
|
|
227
|
+
double y;
|
|
228
|
+
int i;
|
|
229
|
+
|
|
230
|
+
for ( i = 0; i < 25; i++ ) {
|
|
231
|
+
x = random_uniform( 0.0, 10.0 );
|
|
232
|
+
mu = random_uniform( 0.0, 10.0 );
|
|
233
|
+
beta = random_uniform( 0.0, 10.0 );
|
|
234
|
+
y = stdlib_base_dists_gumbel_logpdf( x, mu, beta );
|
|
235
|
+
printf( "x: %lf, µ: %lf, β: %lf, ln(f(x;µ,β)): %lf\n", x, mu, beta, y );
|
|
236
|
+
}
|
|
163
237
|
}
|
|
164
238
|
```
|
|
165
239
|
|
|
@@ -167,6 +241,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
167
241
|
|
|
168
242
|
<!-- /.examples -->
|
|
169
243
|
|
|
244
|
+
</section>
|
|
245
|
+
|
|
246
|
+
<!-- /.c -->
|
|
247
|
+
|
|
170
248
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
171
249
|
|
|
172
250
|
<section class="related">
|
|
@@ -201,7 +279,7 @@ See [LICENSE][stdlib-license].
|
|
|
201
279
|
|
|
202
280
|
## Copyright
|
|
203
281
|
|
|
204
|
-
Copyright © 2016-
|
|
282
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
205
283
|
|
|
206
284
|
</section>
|
|
207
285
|
|
|
@@ -214,8 +292,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
214
292
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-gumbel-logpdf.svg
|
|
215
293
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-gumbel-logpdf
|
|
216
294
|
|
|
217
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-gumbel-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
218
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-gumbel-logpdf/actions/workflows/test.yml?query=branch:v0.
|
|
295
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-gumbel-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
296
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-gumbel-logpdf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
219
297
|
|
|
220
298
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-gumbel-logpdf/main.svg
|
|
221
299
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-gumbel-logpdf?branch=main
|
|
@@ -227,8 +305,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
227
305
|
|
|
228
306
|
-->
|
|
229
307
|
|
|
230
|
-
[chat-image]: https://img.shields.io/
|
|
231
|
-
[chat-url]: https://
|
|
308
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
309
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
232
310
|
|
|
233
311
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
234
312
|
|
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 exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the probability density function (PDF) for a Gumbel distribution with location parameter `mu` and scale parameter `beta` at a value `x`.\n*\n* @param {number} x - input value\n* @param {number} mu - location parameter\n* @param {PositiveNumber} beta - scale parameter\n* @returns {number} evaluated logarithm of PDF\n*\n* @example\n* var y = logpdf( 0.0, 0.0, 2.0 );\n* // returns ~-1.693\n*\n* @example\n* var y = logpdf( 0.0, 0.0, 1.0 );\n* // returns ~-1.0\n*\n* @example\n* var y = logpdf( 1.0, 3.0, 2.0 );\n* // returns ~-2.411\n*\n* @example\n* var y = logpdf( NaN, 0.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, 0.0, NaN );\n* // returns NaN\n*\n* @example\n* // Negative scale parameter:\n* var y = logpdf( 2.0, 0.0, -1.0 );\n* // returns NaN\n*/\nfunction logpdf( x, mu, beta ) {\n\tvar z;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( mu ) ||\n\t\tisnan( beta ) ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( x === NINF ) {\n\t\treturn 0.0;\n\t}\n\tz = ( x - mu ) / beta;\n\treturn -z - exp( -z ) - ln( beta );\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 exp = require( '@stdlib/math-base-special-exp' );\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 logarithm of the probability density function (PDF) for a Gumbel distribution with location parameter `mu` and scale parameter `beta`.\n*\n* @param {number} mu - location parameter\n* @param {PositiveNumber} beta - scale parameter\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 0.0, 2.0 );\n* var y = logpdf( 0.0 );\n* // returns ~-1.693\n*/\nfunction factory( mu, beta ) {\n\tvar lbeta;\n\tif (\n\t\tisnan( mu ) ||\n\t\tisnan( beta ) ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\tlbeta = ln( beta );\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the logarithm of the probability density function (PDF) for a Gumbel 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( 2.3 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tvar z;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x === NINF ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\tz = ( x - mu ) / beta;\n\t\treturn -z - exp( -z ) - lbeta;\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* Gumbel distribution logarithm of probability density function (PDF).\n*\n* @module @stdlib/stats-base-dists-gumbel-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-gumbel-logpdf' );\n*\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.
|
|
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 exp = require( '@stdlib/math-base-special-exp' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the probability density function (PDF) for a Gumbel distribution with location parameter `mu` and scale parameter `beta` at a value `x`.\n*\n* @param {number} x - input value\n* @param {number} mu - location parameter\n* @param {PositiveNumber} beta - scale parameter\n* @returns {number} evaluated logarithm of PDF\n*\n* @example\n* var y = logpdf( 0.0, 0.0, 2.0 );\n* // returns ~-1.693\n*\n* @example\n* var y = logpdf( 0.0, 0.0, 1.0 );\n* // returns ~-1.0\n*\n* @example\n* var y = logpdf( 1.0, 3.0, 2.0 );\n* // returns ~-2.411\n*\n* @example\n* var y = logpdf( NaN, 0.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 0.0, 0.0, NaN );\n* // returns NaN\n*\n* @example\n* // Negative scale parameter:\n* var y = logpdf( 2.0, 0.0, -1.0 );\n* // returns NaN\n*/\nfunction logpdf( x, mu, beta ) {\n\tvar z;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( mu ) ||\n\t\tisnan( beta ) ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( x === NINF ) {\n\t\treturn 0.0;\n\t}\n\tz = ( x - mu ) / beta;\n\treturn -z - exp( -z ) - ln( beta );\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 exp = require( '@stdlib/math-base-special-exp' );\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 logarithm of the probability density function (PDF) for a Gumbel distribution with location parameter `mu` and scale parameter `beta`.\n*\n* @param {number} mu - location parameter\n* @param {PositiveNumber} beta - scale parameter\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 0.0, 2.0 );\n* var y = logpdf( 0.0 );\n* // returns ~-1.693\n*/\nfunction factory( mu, beta ) {\n\tvar lbeta;\n\tif (\n\t\tisnan( mu ) ||\n\t\tisnan( beta ) ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\tlbeta = ln( beta );\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the logarithm of the probability density function (PDF) for a Gumbel 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( 2.3 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tvar z;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x === NINF ) {\n\t\t\treturn 0.0;\n\t\t}\n\t\tz = ( x - mu ) / beta;\n\t\treturn -z - exp( -z ) - lbeta;\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* Gumbel distribution logarithm of probability density function (PDF).\n*\n* @module @stdlib/stats-base-dists-gumbel-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-gumbel-logpdf' );\n*\n* var y = logpdf( 2.0, 0.0, 1.0 );\n* // returns ~-2.135\n*\n* var mylogpdf = logpdf.factory( 10.0, 2.0 );\n* y = mylogpdf( 10.0 );\n* // returns ~-1.693\n*\n* y = mylogpdf( 12.0 );\n* // returns ~-2.061\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,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EA0CrD,SAASC,EAAQC,EAAGC,EAAIC,EAAO,CAC9B,IAAIC,EACJ,OACCR,EAAOK,CAAE,GACTL,EAAOM,CAAG,GACVN,EAAOO,CAAK,GACZA,GAAQ,EAED,IAEHF,IAAMF,EACH,GAERK,GAAMH,EAAIC,GAAOC,EACV,CAACC,EAAIP,EAAK,CAACO,CAAE,EAAIN,EAAIK,CAAK,EAClC,CAKAR,EAAO,QAAUK,ICvFjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EAiBrD,SAASC,EAASC,EAAIC,EAAO,CAC5B,IAAIC,EACJ,GACCP,EAAOK,CAAG,GACVL,EAAOM,CAAK,GACZA,GAAQ,EAER,OAAOP,EAAkB,GAAI,EAE9B,OAAAQ,EAAQL,EAAII,CAAK,EACVE,EAaP,SAASA,EAAQC,EAAI,CACpB,IAAIC,EACJ,OAAKV,EAAOS,CAAE,EACN,IAEHA,IAAMN,EACH,GAERO,GAAMD,EAAIJ,GAAOC,EACV,CAACI,EAAIT,EAAK,CAACS,CAAE,EAAIH,EACzB,CACD,CAKAT,EAAO,QAAUM,ICzCjB,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", "isnan", "exp", "ln", "NINF", "logpdf", "x", "mu", "beta", "z", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "isnan", "exp", "ln", "NINF", "factory", "mu", "beta", "lbeta", "logpdf", "x", "z", "setReadOnly", "main", "factory"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -98,18 +98,18 @@ interface LogPDF {
|
|
|
98
98
|
*
|
|
99
99
|
* @example
|
|
100
100
|
* var y = logpdf( 2.0, 0.0, 1.0 );
|
|
101
|
-
* // returns ~-2.
|
|
101
|
+
* // returns ~-2.135
|
|
102
102
|
*
|
|
103
103
|
* var mylogpdf = logpdf.factory( 10.0, 2.0 );
|
|
104
104
|
* y = mylogpdf( 10.0 );
|
|
105
105
|
* // returns ~-1.693
|
|
106
106
|
*
|
|
107
107
|
* y = mylogpdf( 12.0 );
|
|
108
|
-
* // returns ~-2.
|
|
108
|
+
* // returns ~-2.061
|
|
109
109
|
*/
|
|
110
|
-
declare var
|
|
110
|
+
declare var logpdf: LogPDF;
|
|
111
111
|
|
|
112
112
|
|
|
113
113
|
// EXPORTS //
|
|
114
114
|
|
|
115
|
-
export =
|
|
115
|
+
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_GUMBEL_LOGPDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_GUMBEL_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 logarithm of the probability density function (PDF) for a Gumbel distribution with location parameter `mu` and scale parameter `beta` at a value `x`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_gumbel_logpdf( const double x, const double mu, const double beta );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_GUMBEL_LOGPDF_H
|
package/lib/index.js
CHANGED
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
* var logpdf = require( '@stdlib/stats-base-dists-gumbel-logpdf' );
|
|
28
28
|
*
|
|
29
29
|
* var y = logpdf( 2.0, 0.0, 1.0 );
|
|
30
|
-
* // returns ~-2.
|
|
30
|
+
* // returns ~-2.135
|
|
31
31
|
*
|
|
32
32
|
* var mylogpdf = logpdf.factory( 10.0, 2.0 );
|
|
33
33
|
* y = mylogpdf( 10.0 );
|
|
34
34
|
* // returns ~-1.693
|
|
35
35
|
*
|
|
36
36
|
* y = mylogpdf( 12.0 );
|
|
37
|
-
* // returns ~-2.
|
|
37
|
+
* // returns ~-2.061
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
40
|
// MODULES //
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
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 logarithm of the probability density function (PDF) for a Gumbel distribution with location parameter `mu` and scale parameter `beta` at a value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {number} mu - location parameter
|
|
34
|
+
* @param {PositiveNumber} beta - scale parameter
|
|
35
|
+
* @returns {number} evaluated logarithm of PDF
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var y = logpdf( 0.0, 0.0, 2.0 );
|
|
39
|
+
* // returns ~-1.693
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var y = logpdf( 0.0, 0.0, 1.0 );
|
|
43
|
+
* // returns ~-1.0
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = logpdf( 1.0, 3.0, 2.0 );
|
|
47
|
+
* // returns ~-2.411
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var y = logpdf( NaN, 0.0, 1.0 );
|
|
51
|
+
* // returns NaN
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var y = logpdf( 0.0, NaN, 1.0 );
|
|
55
|
+
* // returns NaN
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* var y = logpdf( 0.0, 0.0, NaN );
|
|
59
|
+
* // returns NaN
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Negative scale parameter:
|
|
63
|
+
* var y = logpdf( 2.0, 0.0, -1.0 );
|
|
64
|
+
* // returns NaN
|
|
65
|
+
*/
|
|
66
|
+
function logpdf( x, mu, beta ) {
|
|
67
|
+
return addon( x, mu, beta );
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
// EXPORTS //
|
|
72
|
+
|
|
73
|
+
module.exports = logpdf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
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-exp",
|
|
44
|
+
"@stdlib/math-base-special-ln",
|
|
45
|
+
"@stdlib/constants-float64-ninf"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"task": "benchmark",
|
|
50
|
+
"wasm": false,
|
|
51
|
+
"src": [
|
|
52
|
+
"./src/main.c"
|
|
53
|
+
],
|
|
54
|
+
"include": [
|
|
55
|
+
"./include"
|
|
56
|
+
],
|
|
57
|
+
"libraries": [],
|
|
58
|
+
"libpath": [],
|
|
59
|
+
"dependencies": [
|
|
60
|
+
"@stdlib/constants-float64-eps",
|
|
61
|
+
"@stdlib/math-base-assert-is-nan",
|
|
62
|
+
"@stdlib/math-base-special-exp",
|
|
63
|
+
"@stdlib/math-base-special-ln",
|
|
64
|
+
"@stdlib/constants-float64-ninf"
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"task": "examples",
|
|
69
|
+
"wasm": false,
|
|
70
|
+
"src": [
|
|
71
|
+
"./src/main.c"
|
|
72
|
+
],
|
|
73
|
+
"include": [
|
|
74
|
+
"./include"
|
|
75
|
+
],
|
|
76
|
+
"libraries": [],
|
|
77
|
+
"libpath": [],
|
|
78
|
+
"dependencies": [
|
|
79
|
+
"@stdlib/math-base-assert-is-nan",
|
|
80
|
+
"@stdlib/math-base-special-exp",
|
|
81
|
+
"@stdlib/math-base-special-ln",
|
|
82
|
+
"@stdlib/constants-float64-ninf"
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-gumbel-logpdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Gumbel 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,10 +35,12 @@
|
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@stdlib/constants-float64-ninf": "^0.2.2",
|
|
34
37
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
38
|
+
"@stdlib/math-base-napi-ternary": "^0.3.1",
|
|
35
39
|
"@stdlib/math-base-special-exp": "^0.2.4",
|
|
36
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,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/gumbel/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_gumbel_logpdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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/gumbel/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/exp.h"
|
|
22
|
+
#include "stdlib/math/base/special/ln.h"
|
|
23
|
+
#include "stdlib/constants/float64/ninf.h"
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Evaluates the logarithm of the probability density function (PDF) for a Gumbel distribution with location parameter `mu` and scale parameter `beta` at a value `x`.
|
|
27
|
+
*
|
|
28
|
+
* @param x input value
|
|
29
|
+
* @param mu location parameter
|
|
30
|
+
* @param beta scale parameter
|
|
31
|
+
* @return evaluated logarithm of PDF
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* double y = stdlib_base_dists_gumbel_logpdf( 0.0, 0.0, 2.0 );
|
|
35
|
+
* // returns ~-1.693
|
|
36
|
+
*/
|
|
37
|
+
double stdlib_base_dists_gumbel_logpdf( const double x, const double mu, const double beta ) {
|
|
38
|
+
double z;
|
|
39
|
+
if (
|
|
40
|
+
stdlib_base_is_nan( x ) ||
|
|
41
|
+
stdlib_base_is_nan( mu ) ||
|
|
42
|
+
stdlib_base_is_nan( beta ) ||
|
|
43
|
+
beta <= 0.0
|
|
44
|
+
) {
|
|
45
|
+
return 0.0/0.0; // NaN
|
|
46
|
+
}
|
|
47
|
+
if ( x == STDLIB_CONSTANT_FLOAT64_NINF ) {
|
|
48
|
+
return 0.0;
|
|
49
|
+
}
|
|
50
|
+
z = ( x - mu ) / beta;
|
|
51
|
+
return -z -stdlib_base_exp( -z ) -stdlib_base_ln( beta );
|
|
52
|
+
}
|