@stdlib/stats-base-dists-exponential-mgf 0.2.1 → 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 +107 -15
- package/include/stdlib/stats/base/dists/exponential/mgf.h +38 -0
- package/lib/native.js +67 -0
- package/manifest.json +80 -0
- package/package.json +10 -5
- package/src/addon.c +22 -0
- package/src/main.c +45 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -139,19 +139,107 @@ var y = mymgf( 3.0 );
|
|
|
139
139
|
<!-- eslint no-undef: "error" -->
|
|
140
140
|
|
|
141
141
|
```javascript
|
|
142
|
-
var
|
|
142
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
143
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
143
144
|
var mgf = require( '@stdlib/stats-base-dists-exponential-mgf' );
|
|
144
145
|
|
|
145
|
-
var
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
var
|
|
146
|
+
var opts = {
|
|
147
|
+
'dtype': 'float64'
|
|
148
|
+
};
|
|
149
|
+
var t = uniform( 10, 0.0, 10.0, opts );
|
|
150
|
+
var lambda = uniform( 10, 0.0, 10.0, opts );
|
|
149
151
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
logEachMap( 'x: %0.4f, λ: %0.4f, M_X(t;λ): %0.4f', t, lambda, mgf );
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
</section>
|
|
156
|
+
|
|
157
|
+
<!-- /.examples -->
|
|
158
|
+
|
|
159
|
+
<!-- C interface documentation. -->
|
|
160
|
+
|
|
161
|
+
* * *
|
|
162
|
+
|
|
163
|
+
<section class="c">
|
|
164
|
+
|
|
165
|
+
## C APIs
|
|
166
|
+
|
|
167
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
168
|
+
|
|
169
|
+
<section class="intro">
|
|
170
|
+
|
|
171
|
+
</section>
|
|
172
|
+
|
|
173
|
+
<!-- /.intro -->
|
|
174
|
+
|
|
175
|
+
<!-- C usage documentation. -->
|
|
176
|
+
|
|
177
|
+
<section class="usage">
|
|
178
|
+
|
|
179
|
+
### Usage
|
|
180
|
+
|
|
181
|
+
```c
|
|
182
|
+
#include "stdlib/stats/base/dists/exponential/mgf.h"
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### stdlib_base_dists_exponential_mgf( t, lambda )
|
|
186
|
+
|
|
187
|
+
Evaluates the moment-generating function ([MGF][mgf]) for an [exponential][exponential-distribution] distribution.
|
|
188
|
+
|
|
189
|
+
```c
|
|
190
|
+
double out = stdlib_base_dists_exponential_mgf( 2.0, 3.0 );
|
|
191
|
+
// returns 3.0
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The function accepts the following arguments:
|
|
195
|
+
|
|
196
|
+
- **t**: `[in] double` input value.
|
|
197
|
+
- **lambda**: `[in] double` rate parameter.
|
|
198
|
+
|
|
199
|
+
```c
|
|
200
|
+
double stdlib_base_dists_exponential_mgf( const double t, const double lambda );
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
</section>
|
|
204
|
+
|
|
205
|
+
<!-- /.usage -->
|
|
206
|
+
|
|
207
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
208
|
+
|
|
209
|
+
<section class="notes">
|
|
210
|
+
|
|
211
|
+
</section>
|
|
212
|
+
|
|
213
|
+
<!-- /.notes -->
|
|
214
|
+
|
|
215
|
+
<!-- C API usage examples. -->
|
|
216
|
+
|
|
217
|
+
<section class="examples">
|
|
218
|
+
|
|
219
|
+
### Examples
|
|
220
|
+
|
|
221
|
+
```c
|
|
222
|
+
#include "stdlib/stats/base/dists/exponential/mgf.h"
|
|
223
|
+
#include <stdlib.h>
|
|
224
|
+
#include <stdio.h>
|
|
225
|
+
|
|
226
|
+
static double random_uniform( const double min, const double max ) {
|
|
227
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
228
|
+
return min + ( v*(max-min) );
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
int main( void ) {
|
|
232
|
+
double lambda;
|
|
233
|
+
double t;
|
|
234
|
+
double y;
|
|
235
|
+
int i;
|
|
236
|
+
|
|
237
|
+
for ( i = 0; i < 25; i++ ) {
|
|
238
|
+
t = random_uniform( -1.0, 1.0 );
|
|
239
|
+
lambda = random_uniform( 1.1, 10.0 );
|
|
240
|
+
y = stdlib_base_dists_exponential_mgf( t, lambda );
|
|
241
|
+
printf( "t: %lf, λ: %lf, M_X(t;λ): %lf\n", t, lambda, y );
|
|
242
|
+
}
|
|
155
243
|
}
|
|
156
244
|
```
|
|
157
245
|
|
|
@@ -159,6 +247,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
159
247
|
|
|
160
248
|
<!-- /.examples -->
|
|
161
249
|
|
|
250
|
+
</section>
|
|
251
|
+
|
|
252
|
+
<!-- /.c -->
|
|
253
|
+
|
|
162
254
|
<!-- 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. -->
|
|
163
255
|
|
|
164
256
|
<section class="references">
|
|
@@ -201,7 +293,7 @@ See [LICENSE][stdlib-license].
|
|
|
201
293
|
|
|
202
294
|
## Copyright
|
|
203
295
|
|
|
204
|
-
Copyright © 2016-
|
|
296
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
205
297
|
|
|
206
298
|
</section>
|
|
207
299
|
|
|
@@ -214,8 +306,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
214
306
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-exponential-mgf.svg
|
|
215
307
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-exponential-mgf
|
|
216
308
|
|
|
217
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-exponential-mgf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
218
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-exponential-mgf/actions/workflows/test.yml?query=branch:v0.
|
|
309
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-exponential-mgf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
310
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-exponential-mgf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
219
311
|
|
|
220
312
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-exponential-mgf/main.svg
|
|
221
313
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-exponential-mgf?branch=main
|
|
@@ -227,8 +319,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
227
319
|
|
|
228
320
|
-->
|
|
229
321
|
|
|
230
|
-
[chat-image]: https://img.shields.io/
|
|
231
|
-
[chat-url]: https://
|
|
322
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
323
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
232
324
|
|
|
233
325
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
234
326
|
|
|
@@ -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_EXPONENTIAL_MGF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_EXPONENTIAL_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) of an exponential distribution with rate parameter `lambda` at a value `t`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_exponential_mgf( const double t, const double lambda );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_EXPONENTIAL_MGF_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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 moment-generating function (MGF) for an exponential distribution with rate parameter `lambda` at a value `t`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} t - input value
|
|
33
|
+
* @param {PositiveNumber} lambda - rate parameter
|
|
34
|
+
* @returns {number} evaluated MGF
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var v = mgf( 2.0, 3.0 );
|
|
38
|
+
* // returns 3.0
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var v = mgf( 0.4, 1.2 );
|
|
42
|
+
* // returns 1.5
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var v = mgf( 0.8, 1.6 );
|
|
46
|
+
* // returns 2.0
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var v = mgf( 4.0, 3.0 );
|
|
50
|
+
* // returns NaN
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* var v = mgf( NaN, 3.0 );
|
|
54
|
+
* // returns NaN
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* var v = mgf( 2.0, NaN );
|
|
58
|
+
* // returns NaN
|
|
59
|
+
*/
|
|
60
|
+
function mgf( t, lambda ) {
|
|
61
|
+
return addon( t, lambda );
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// EXPORTS //
|
|
66
|
+
|
|
67
|
+
module.exports = mgf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
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-binary",
|
|
42
|
+
"@stdlib/math-base-assert-is-nan",
|
|
43
|
+
"@stdlib/constants-float64-pinf"
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"task": "benchmark",
|
|
48
|
+
"wasm": false,
|
|
49
|
+
"src": [
|
|
50
|
+
"./src/main.c"
|
|
51
|
+
],
|
|
52
|
+
"include": [
|
|
53
|
+
"./include"
|
|
54
|
+
],
|
|
55
|
+
"libraries": [],
|
|
56
|
+
"libpath": [],
|
|
57
|
+
"dependencies": [
|
|
58
|
+
"@stdlib/math-base-assert-is-nan",
|
|
59
|
+
"@stdlib/constants-float64-eps",
|
|
60
|
+
"@stdlib/constants-float64-pinf"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"task": "examples",
|
|
65
|
+
"wasm": false,
|
|
66
|
+
"src": [
|
|
67
|
+
"./src/main.c"
|
|
68
|
+
],
|
|
69
|
+
"include": [
|
|
70
|
+
"./include"
|
|
71
|
+
],
|
|
72
|
+
"libraries": [],
|
|
73
|
+
"libpath": [],
|
|
74
|
+
"dependencies": [
|
|
75
|
+
"@stdlib/math-base-assert-is-nan",
|
|
76
|
+
"@stdlib/constants-float64-pinf"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-exponential-mgf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Exponential 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",
|
|
@@ -30,10 +33,12 @@
|
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@stdlib/constants-float64-pinf": "^0.2.
|
|
34
|
-
"@stdlib/math-base-assert-is-nan": "^0.2.
|
|
35
|
-
"@stdlib/
|
|
36
|
-
"@stdlib/utils-
|
|
36
|
+
"@stdlib/constants-float64-pinf": "^0.2.2",
|
|
37
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
38
|
+
"@stdlib/math-base-napi-binary": "^0.3.1",
|
|
39
|
+
"@stdlib/utils-constant-function": "^0.2.2",
|
|
40
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
41
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
37
42
|
},
|
|
38
43
|
"devDependencies": {},
|
|
39
44
|
"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/exponential/mgf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/binary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_exponential_mgf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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/exponential/mgf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/constants/float64/pinf.h"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Evaluates the moment-generating function (MGF) of an exponential distribution with rate parameter `lambda` at a value `t`.
|
|
25
|
+
*
|
|
26
|
+
* @param t input value
|
|
27
|
+
* @param lambda rate parameter (must be positive)
|
|
28
|
+
* @return evaluated MGF
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* double v = mgf( 2.0, 3.0 );
|
|
32
|
+
* // returns 3.0
|
|
33
|
+
*/
|
|
34
|
+
double stdlib_base_dists_exponential_mgf( const double t, const double lambda ) {
|
|
35
|
+
if (
|
|
36
|
+
stdlib_base_is_nan( t ) ||
|
|
37
|
+
stdlib_base_is_nan( lambda ) ||
|
|
38
|
+
lambda <= 0.0 ||
|
|
39
|
+
lambda == STDLIB_CONSTANT_FLOAT64_PINF ||
|
|
40
|
+
t >= lambda
|
|
41
|
+
) {
|
|
42
|
+
return 0.0/0.0; // NaN
|
|
43
|
+
}
|
|
44
|
+
return lambda / ( lambda - t );
|
|
45
|
+
}
|