@stdlib/stats-base-dists-erlang-mgf 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 +104 -5
- package/include/stdlib/stats/base/dists/erlang/mgf.h +38 -0
- package/lib/native.js +84 -0
- package/manifest.json +85 -0
- package/package.json +8 -3
- package/src/addon.c +22 -0
- package/src/main.c +47 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -182,6 +182,105 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
182
182
|
|
|
183
183
|
<!-- /.examples -->
|
|
184
184
|
|
|
185
|
+
<!-- C interface documentation. -->
|
|
186
|
+
|
|
187
|
+
* * *
|
|
188
|
+
|
|
189
|
+
<section class="c">
|
|
190
|
+
|
|
191
|
+
## C APIs
|
|
192
|
+
|
|
193
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
194
|
+
|
|
195
|
+
<section class="intro">
|
|
196
|
+
|
|
197
|
+
</section>
|
|
198
|
+
|
|
199
|
+
<!-- /.intro -->
|
|
200
|
+
|
|
201
|
+
<!-- C usage documentation. -->
|
|
202
|
+
|
|
203
|
+
<section class="usage">
|
|
204
|
+
|
|
205
|
+
### Usage
|
|
206
|
+
|
|
207
|
+
```c
|
|
208
|
+
#include "stdlib/stats/base/dists/erlang/mgf.h"
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
#### stdlib_base_dists_erlang_mgf( t, k, lambda )
|
|
212
|
+
|
|
213
|
+
Evaluates the [moment-generating function][mgf] (MGF) for an [Erlang][erlang-distribution] distribution with parameters `k` (shape parameter) and `lambda` (rate parameter).
|
|
214
|
+
|
|
215
|
+
```c
|
|
216
|
+
double y = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 );
|
|
217
|
+
// returns ~1.429
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
The function accepts the following arguments:
|
|
221
|
+
|
|
222
|
+
- **t**: `[in] double` input value.
|
|
223
|
+
- **k**: `[in] double` shape parameter.
|
|
224
|
+
- **lambda**: `[in] double` rate parameter.
|
|
225
|
+
|
|
226
|
+
```c
|
|
227
|
+
double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda );
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
</section>
|
|
231
|
+
|
|
232
|
+
<!-- /.usage -->
|
|
233
|
+
|
|
234
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` 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/erlang/mgf.h"
|
|
250
|
+
#include "stdlib/math/base/special/round.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 lambda;
|
|
261
|
+
double k;
|
|
262
|
+
double t;
|
|
263
|
+
double y;
|
|
264
|
+
int i;
|
|
265
|
+
|
|
266
|
+
for ( i = 0; i < 25; i++ ) {
|
|
267
|
+
k = stdlib_base_round( random_uniform( 0.0, 10.0 ) );
|
|
268
|
+
lambda = random_uniform( 0.0, 10.0 );
|
|
269
|
+
t = random_uniform( 0.0, lambda );
|
|
270
|
+
y = stdlib_base_dists_erlang_mgf( t, k, lambda );
|
|
271
|
+
printf( "t: %lf, k: %lf, λ: %lf, M_X(t;k,λ): %lf\n", t, k, lambda, y );
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
</section>
|
|
277
|
+
|
|
278
|
+
<!-- /.examples -->
|
|
279
|
+
|
|
280
|
+
</section>
|
|
281
|
+
|
|
282
|
+
<!-- /.c -->
|
|
283
|
+
|
|
185
284
|
<!-- 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. -->
|
|
186
285
|
|
|
187
286
|
<section class="references">
|
|
@@ -224,7 +323,7 @@ See [LICENSE][stdlib-license].
|
|
|
224
323
|
|
|
225
324
|
## Copyright
|
|
226
325
|
|
|
227
|
-
Copyright © 2016-
|
|
326
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
228
327
|
|
|
229
328
|
</section>
|
|
230
329
|
|
|
@@ -237,8 +336,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
237
336
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-erlang-mgf.svg
|
|
238
337
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-erlang-mgf
|
|
239
338
|
|
|
240
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-erlang-mgf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
241
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-erlang-mgf/actions/workflows/test.yml?query=branch:v0.
|
|
339
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-erlang-mgf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
340
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-erlang-mgf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
242
341
|
|
|
243
342
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-erlang-mgf/main.svg
|
|
244
343
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-erlang-mgf?branch=main
|
|
@@ -250,8 +349,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
250
349
|
|
|
251
350
|
-->
|
|
252
351
|
|
|
253
|
-
[chat-image]: https://img.shields.io/
|
|
254
|
-
[chat-url]: https://
|
|
352
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
353
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
255
354
|
|
|
256
355
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
257
356
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2026 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_ERLANG_MGF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_ERLANG_MGF_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 moment-generating function (MGF) for an Erlang distribution with shape parameter `k` and rate parameter `lambda`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_ERLANG_MGF_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2026 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 moment-generating function (MGF) for an Erlang distribution with shape parameter `k` and rate parameter `lambda` at a value `t`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} t - input value
|
|
33
|
+
* @param {NonNegativeInteger} k - shape parameter
|
|
34
|
+
* @param {PositiveNumber} lambda - rate parameter
|
|
35
|
+
* @returns {number} evaluated MGF
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var y = mgf( 0.3, 1, 1.0 );
|
|
39
|
+
* // returns ~1.429
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var y = mgf( 2.0, 2, 3.0 );
|
|
43
|
+
* // returns ~9.0
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = mgf( -1.0, 2, 2.0 );
|
|
47
|
+
* // returns ~0.444
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var y = mgf( NaN, 1, 1.0 );
|
|
51
|
+
* // returns NaN
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var y = mgf( 0.0, NaN, 1.0 );
|
|
55
|
+
* // returns NaN
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* var y = mgf( 0.0, 1, NaN );
|
|
59
|
+
* // returns NaN
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* var y = mgf( 0.2, -2, 0.5 );
|
|
63
|
+
* // returns NaN
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* var y = mgf( 0.2, 0.5, 0.5 );
|
|
67
|
+
* // returns NaN
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* var y = mgf( 0.2, 1, 0.0 );
|
|
71
|
+
* // returns NaN
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* var y = mgf( 0.2, 1, -5.0 );
|
|
75
|
+
* // returns NaN
|
|
76
|
+
*/
|
|
77
|
+
function mgf( t, k, lambda ) {
|
|
78
|
+
return addon( t, k, lambda );
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
// EXPORTS //
|
|
83
|
+
|
|
84
|
+
module.exports = mgf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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-nonnegative-integer",
|
|
43
|
+
"@stdlib/math-base-assert-is-nan",
|
|
44
|
+
"@stdlib/math-base-special-pow"
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"task": "benchmark",
|
|
49
|
+
"wasm": false,
|
|
50
|
+
"src": [
|
|
51
|
+
"./src/main.c"
|
|
52
|
+
],
|
|
53
|
+
"include": [
|
|
54
|
+
"./include"
|
|
55
|
+
],
|
|
56
|
+
"libraries": [],
|
|
57
|
+
"libpath": [],
|
|
58
|
+
"dependencies": [
|
|
59
|
+
"@stdlib/math-base-assert-is-nonnegative-integer",
|
|
60
|
+
"@stdlib/math-base-assert-is-nan",
|
|
61
|
+
"@stdlib/math-base-special-pow",
|
|
62
|
+
"@stdlib/math-base-special-round",
|
|
63
|
+
"@stdlib/constants-float64-eps"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"task": "examples",
|
|
68
|
+
"wasm": false,
|
|
69
|
+
"src": [
|
|
70
|
+
"./src/main.c"
|
|
71
|
+
],
|
|
72
|
+
"include": [
|
|
73
|
+
"./include"
|
|
74
|
+
],
|
|
75
|
+
"libraries": [],
|
|
76
|
+
"libpath": [],
|
|
77
|
+
"dependencies": [
|
|
78
|
+
"@stdlib/math-base-assert-is-nonnegative-integer",
|
|
79
|
+
"@stdlib/math-base-assert-is-nan",
|
|
80
|
+
"@stdlib/math-base-special-pow",
|
|
81
|
+
"@stdlib/math-base-special-round"
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-erlang-mgf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Erlang distribution moment-generating function (MGF).",
|
|
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",
|
|
@@ -31,10 +34,12 @@
|
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
34
|
-
"@stdlib/math-base-assert-is-nonnegative-integer": "^0.2.
|
|
37
|
+
"@stdlib/math-base-assert-is-nonnegative-integer": "^0.2.2",
|
|
38
|
+
"@stdlib/math-base-napi-ternary": "^0.3.1",
|
|
35
39
|
"@stdlib/math-base-special-pow": "^0.3.0",
|
|
36
40
|
"@stdlib/utils-constant-function": "^0.2.2",
|
|
37
|
-
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
|
|
41
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
42
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {},
|
|
40
45
|
"engines": {
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2026 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/erlang/mgf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/ternary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_erlang_mgf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2026 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/erlang/mgf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nonnegative_integer.h"
|
|
21
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
22
|
+
#include "stdlib/math/base/special/pow.h"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Evaluates the moment-generating function (MGF) for an Erlang distribution with shape parameter `k` and rate parameter `lambda`.
|
|
26
|
+
*
|
|
27
|
+
* @param t input value
|
|
28
|
+
* @param k shape parameter
|
|
29
|
+
* @param lambda rate parameter (must be positive)
|
|
30
|
+
* @return evaluated MGF
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* double v = stdlib_base_dists_erlang_mgf( 0.3, 1, 1.0 );
|
|
34
|
+
* // returns ~1.429
|
|
35
|
+
*/
|
|
36
|
+
double stdlib_base_dists_erlang_mgf( const double t, const double k, const double lambda ) {
|
|
37
|
+
if (
|
|
38
|
+
stdlib_base_is_nan( t ) ||
|
|
39
|
+
!stdlib_base_is_nonnegative_integer( k ) ||
|
|
40
|
+
stdlib_base_is_nan( lambda ) ||
|
|
41
|
+
lambda <= 0.0 ||
|
|
42
|
+
t >= lambda
|
|
43
|
+
) {
|
|
44
|
+
return 0.0 / 0.0; // NaN
|
|
45
|
+
}
|
|
46
|
+
return stdlib_base_pow( 1.0 - ( t / lambda ), -k );
|
|
47
|
+
}
|