@stdlib/stats-base-dists-uniform-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 +103 -5
- package/include/stdlib/stats/base/dists/uniform/mgf.h +38 -0
- package/lib/native.js +76 -0
- package/manifest.json +79 -0
- package/package.json +8 -3
- package/src/addon.c +22 -0
- package/src/main.c +49 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -170,6 +170,104 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
170
170
|
|
|
171
171
|
<!-- /.examples -->
|
|
172
172
|
|
|
173
|
+
<!-- C interface documentation. -->
|
|
174
|
+
|
|
175
|
+
* * *
|
|
176
|
+
|
|
177
|
+
<section class="c">
|
|
178
|
+
|
|
179
|
+
## C APIs
|
|
180
|
+
|
|
181
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
182
|
+
|
|
183
|
+
<section class="intro">
|
|
184
|
+
|
|
185
|
+
</section>
|
|
186
|
+
|
|
187
|
+
<!-- /.intro -->
|
|
188
|
+
|
|
189
|
+
<!-- C usage documentation. -->
|
|
190
|
+
|
|
191
|
+
<section class="usage">
|
|
192
|
+
|
|
193
|
+
### Usage
|
|
194
|
+
|
|
195
|
+
```c
|
|
196
|
+
#include "stdlib/stats/base/dists/uniform/mgf.h"
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
#### stdlib_base_dists_uniform_mgf( t, a, b )
|
|
200
|
+
|
|
201
|
+
Evaluates the [moment-generating function][mgf] (MGF) for a [continuous uniform][uniform-distribution] distribution with parameters `a` (minimum support) and `b` (maximum support).
|
|
202
|
+
|
|
203
|
+
```c
|
|
204
|
+
double out = stdlib_base_dists_uniform_mgf( 2.0, 0.0, 4.0 );
|
|
205
|
+
// returns ~372.495
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
The function accepts the following arguments:
|
|
209
|
+
|
|
210
|
+
- **x**: `[in] double` input value.
|
|
211
|
+
- **a**: `[in] double` minimum support.
|
|
212
|
+
- **b**: `[in] double` maximum support.
|
|
213
|
+
|
|
214
|
+
```c
|
|
215
|
+
double stdlib_base_dists_uniform_mgf( const double t, const double a, const double b );
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
</section>
|
|
219
|
+
|
|
220
|
+
<!-- /.usage -->
|
|
221
|
+
|
|
222
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
223
|
+
|
|
224
|
+
<section class="notes">
|
|
225
|
+
|
|
226
|
+
</section>
|
|
227
|
+
|
|
228
|
+
<!-- /.notes -->
|
|
229
|
+
|
|
230
|
+
<!-- C API usage examples. -->
|
|
231
|
+
|
|
232
|
+
<section class="examples">
|
|
233
|
+
|
|
234
|
+
### Examples
|
|
235
|
+
|
|
236
|
+
```c
|
|
237
|
+
#include "stdlib/stats/base/dists/uniform/mgf.h"
|
|
238
|
+
#include <stdlib.h>
|
|
239
|
+
#include <stdio.h>
|
|
240
|
+
|
|
241
|
+
static double random_uniform( const double min, const double max ) {
|
|
242
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
243
|
+
return min + ( v*(max-min) );
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
int main( void ) {
|
|
247
|
+
double a;
|
|
248
|
+
double b;
|
|
249
|
+
double t;
|
|
250
|
+
double y;
|
|
251
|
+
int i;
|
|
252
|
+
|
|
253
|
+
for ( i = 0; i < 25; i++ ) {
|
|
254
|
+
t = random_uniform( -10.0, 10.0 );
|
|
255
|
+
a = random_uniform( -20.0, 0.0 );
|
|
256
|
+
b = random_uniform( a, a+40.0 );
|
|
257
|
+
y = stdlib_base_dists_uniform_mgf( t, a, b );
|
|
258
|
+
printf( "t: %lf, a: %lf, b: %lf, M_X(t;a,b): %lf\n", t, a, b, y );
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
</section>
|
|
264
|
+
|
|
265
|
+
<!-- /.examples -->
|
|
266
|
+
|
|
267
|
+
</section>
|
|
268
|
+
|
|
269
|
+
<!-- /.c -->
|
|
270
|
+
|
|
173
271
|
<!-- 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. -->
|
|
174
272
|
|
|
175
273
|
<section class="references">
|
|
@@ -212,7 +310,7 @@ See [LICENSE][stdlib-license].
|
|
|
212
310
|
|
|
213
311
|
## Copyright
|
|
214
312
|
|
|
215
|
-
Copyright © 2016-
|
|
313
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
216
314
|
|
|
217
315
|
</section>
|
|
218
316
|
|
|
@@ -225,8 +323,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
225
323
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-uniform-mgf.svg
|
|
226
324
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-uniform-mgf
|
|
227
325
|
|
|
228
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-uniform-mgf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
229
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-uniform-mgf/actions/workflows/test.yml?query=branch:v0.
|
|
326
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-uniform-mgf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
327
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-uniform-mgf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
230
328
|
|
|
231
329
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-uniform-mgf/main.svg
|
|
232
330
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-uniform-mgf?branch=main
|
|
@@ -238,8 +336,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
238
336
|
|
|
239
337
|
-->
|
|
240
338
|
|
|
241
|
-
[chat-image]: https://img.shields.io/
|
|
242
|
-
[chat-url]: https://
|
|
339
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
340
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
243
341
|
|
|
244
342
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
245
343
|
|
|
@@ -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_UNIFORM_MGF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_UNIFORM_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 a uniform distribution with minimum support `a` and maximum support `b` at a value `t`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_uniform_mgf( const double t, const double a, const double b );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_UNIFORM_MGF_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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) of a uniform distribution with minimum support `a` and maximum support `b` at a value `t`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} t - input value
|
|
33
|
+
* @param {number} a - minimum support
|
|
34
|
+
* @param {number} b - maximum support
|
|
35
|
+
* @returns {number} evaluated MGF
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var y = mgf( 2.0, 0.0, 4.0 );
|
|
39
|
+
* // returns ~372.495
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var y = mgf( -0.2, 0.0, 4.0 );
|
|
43
|
+
* // returns ~0.688
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = mgf( 2.0, 0.0, 1.0 );
|
|
47
|
+
* // returns ~3.195
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var y = mgf( 0.5, 3.0, 2.0 );
|
|
51
|
+
* // returns NaN
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var y = mgf( 0.5, 3.0, 3.0 );
|
|
55
|
+
* // returns NaN
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* var y = mgf( NaN, 0.0, 1.0 );
|
|
59
|
+
* // returns NaN
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* var y = mgf( 0.0, NaN, 1.0 );
|
|
63
|
+
* // returns NaN
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* var y = mgf( 0.0, 0.0, NaN );
|
|
67
|
+
* // returns NaN
|
|
68
|
+
*/
|
|
69
|
+
function mgf( t, a, b ) {
|
|
70
|
+
return addon( t, a, b );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
// EXPORTS //
|
|
75
|
+
|
|
76
|
+
module.exports = mgf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
]
|
|
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/math-base-special-exp"
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"task": "examples",
|
|
64
|
+
"wasm": false,
|
|
65
|
+
"src": [
|
|
66
|
+
"./src/main.c"
|
|
67
|
+
],
|
|
68
|
+
"include": [
|
|
69
|
+
"./include"
|
|
70
|
+
],
|
|
71
|
+
"libraries": [],
|
|
72
|
+
"libpath": [],
|
|
73
|
+
"dependencies": [
|
|
74
|
+
"@stdlib/math-base-assert-is-nan",
|
|
75
|
+
"@stdlib/math-base-special-exp"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-uniform-mgf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Uniform 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,9 +34,11 @@
|
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
34
|
-
"@stdlib/math-base-
|
|
37
|
+
"@stdlib/math-base-napi-ternary": "^0.3.1",
|
|
38
|
+
"@stdlib/math-base-special-exp": "^0.2.4",
|
|
35
39
|
"@stdlib/utils-constant-function": "^0.2.2",
|
|
36
|
-
"@stdlib/utils-define-nonenumerable-read-only-property": "^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/uniform/mgf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/ternary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_uniform_mgf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
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/uniform/mgf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/exp.h"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Evaluates the moment-generating function (MGF) of a uniform distribution with minimum support `a` and maximum support `b` at a value `t`.
|
|
25
|
+
*
|
|
26
|
+
* @param t input value
|
|
27
|
+
* @param a minimum support
|
|
28
|
+
* @param b maximum support
|
|
29
|
+
* @return evaluated MGF
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* double y = stdlib_base_dists_uniform_mgf( 2.0, 0.0, 4.0 );
|
|
33
|
+
* // returns ~372.495
|
|
34
|
+
*/
|
|
35
|
+
double stdlib_base_dists_uniform_mgf( const double t, const double a, const double b ) {
|
|
36
|
+
if (
|
|
37
|
+
stdlib_base_is_nan( t ) ||
|
|
38
|
+
stdlib_base_is_nan( a ) ||
|
|
39
|
+
stdlib_base_is_nan( b ) ||
|
|
40
|
+
a >= b
|
|
41
|
+
) {
|
|
42
|
+
return 0.0/0.0; // NaN
|
|
43
|
+
}
|
|
44
|
+
if ( t == 0.0 ) {
|
|
45
|
+
return 1.0;
|
|
46
|
+
}
|
|
47
|
+
// Case: t not equal to zero
|
|
48
|
+
return ( stdlib_base_exp( t * b ) - stdlib_base_exp( t * a ) ) / ( t * ( b - a ) );
|
|
49
|
+
}
|