@stdlib/stats-base-dists-uniform-mean 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 +100 -5
- package/include/stdlib/stats/base/dists/uniform/mean.h +38 -0
- package/lib/native.js +63 -0
- package/manifest.json +76 -0
- package/package.json +9 -2
- package/src/addon.c +22 -0
- package/src/main.c +46 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -152,6 +152,101 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
152
152
|
|
|
153
153
|
<!-- /.examples -->
|
|
154
154
|
|
|
155
|
+
<!-- C interface documentation. -->
|
|
156
|
+
|
|
157
|
+
* * *
|
|
158
|
+
|
|
159
|
+
<section class="c">
|
|
160
|
+
|
|
161
|
+
## C APIs
|
|
162
|
+
|
|
163
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
164
|
+
|
|
165
|
+
<section class="intro">
|
|
166
|
+
|
|
167
|
+
</section>
|
|
168
|
+
|
|
169
|
+
<!-- /.intro -->
|
|
170
|
+
|
|
171
|
+
<!-- C usage documentation. -->
|
|
172
|
+
|
|
173
|
+
<section class="usage">
|
|
174
|
+
|
|
175
|
+
### Usage
|
|
176
|
+
|
|
177
|
+
```c
|
|
178
|
+
#include "stdlib/stats/base/dists/uniform/mean.h"
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### stdlib_base_dists_uniform_mean( a, b )
|
|
182
|
+
|
|
183
|
+
Returns the [expected value][expected-value] of a [uniform][uniform-distribution] distribution with parameters `a` (minimum support) and `b` (maximum support).
|
|
184
|
+
|
|
185
|
+
```c
|
|
186
|
+
double out = stdlib_base_dists_uniform_mean( 0.0, 1.0 );
|
|
187
|
+
// returns 0.5
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The function accepts the following arguments:
|
|
191
|
+
|
|
192
|
+
- **a**: `[in] double` minimum support.
|
|
193
|
+
- **b**: `[in] double` maximum support.
|
|
194
|
+
|
|
195
|
+
```c
|
|
196
|
+
double stdlib_base_dists_uniform_mean( const double a, const double b );
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
</section>
|
|
200
|
+
|
|
201
|
+
<!-- /.usage -->
|
|
202
|
+
|
|
203
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
204
|
+
|
|
205
|
+
<section class="notes">
|
|
206
|
+
|
|
207
|
+
</section>
|
|
208
|
+
|
|
209
|
+
<!-- /.notes -->
|
|
210
|
+
|
|
211
|
+
<!-- C API usage examples. -->
|
|
212
|
+
|
|
213
|
+
<section class="examples">
|
|
214
|
+
|
|
215
|
+
### Examples
|
|
216
|
+
|
|
217
|
+
```c
|
|
218
|
+
#include "stdlib/stats/base/dists/uniform/mean.h"
|
|
219
|
+
#include <stdlib.h>
|
|
220
|
+
#include <stdio.h>
|
|
221
|
+
|
|
222
|
+
static double random_uniform( const double min, const double max ) {
|
|
223
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
224
|
+
return min + ( v*(max-min) );
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
int main( void ) {
|
|
228
|
+
double a;
|
|
229
|
+
double b;
|
|
230
|
+
double y;
|
|
231
|
+
int i;
|
|
232
|
+
|
|
233
|
+
for ( i = 0; i < 25; i++ ) {
|
|
234
|
+
a = random_uniform( 0.0, 10.0 );
|
|
235
|
+
b = random_uniform( a, 20.0 ); // ensure b > a
|
|
236
|
+
y = stdlib_base_dists_uniform_mean( a, b );
|
|
237
|
+
printf( "a: %lf, b: %lf, E(X;a,b): %lf\n", a, b, y );
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
</section>
|
|
243
|
+
|
|
244
|
+
<!-- /.examples -->
|
|
245
|
+
|
|
246
|
+
</section>
|
|
247
|
+
|
|
248
|
+
<!-- /.c -->
|
|
249
|
+
|
|
155
250
|
<!-- 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. -->
|
|
156
251
|
|
|
157
252
|
<section class="references">
|
|
@@ -194,7 +289,7 @@ See [LICENSE][stdlib-license].
|
|
|
194
289
|
|
|
195
290
|
## Copyright
|
|
196
291
|
|
|
197
|
-
Copyright © 2016-
|
|
292
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
198
293
|
|
|
199
294
|
</section>
|
|
200
295
|
|
|
@@ -207,8 +302,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
207
302
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-uniform-mean.svg
|
|
208
303
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-uniform-mean
|
|
209
304
|
|
|
210
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-uniform-mean/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
211
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-uniform-mean/actions/workflows/test.yml?query=branch:v0.
|
|
305
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-uniform-mean/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
306
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-uniform-mean/actions/workflows/test.yml?query=branch:v0.3.0
|
|
212
307
|
|
|
213
308
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-uniform-mean/main.svg
|
|
214
309
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-uniform-mean?branch=main
|
|
@@ -220,8 +315,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
220
315
|
|
|
221
316
|
-->
|
|
222
317
|
|
|
223
|
-
[chat-image]: https://img.shields.io/
|
|
224
|
-
[chat-url]: https://
|
|
318
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
319
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
225
320
|
|
|
226
321
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
227
322
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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_MEAN_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_UNIFORM_MEAN_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
|
+
* Returns the mean of a uniform distribution with minimum support `a` and maximum support `b`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_uniform_mean( const double a, const double b );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_UNIFORM_MEAN_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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
|
+
* Returns the mean of a uniform distribution.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} a - minimum support
|
|
33
|
+
* @param {number} b - maximum support
|
|
34
|
+
* @returns {number} mean
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var v = mean( 0.0, 1.0 );
|
|
38
|
+
* // returns 0.5
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var v = mean( 2.0, 8.0 );
|
|
42
|
+
* // returns 5.0
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var v = mean( NaN, 1.0 );
|
|
46
|
+
* // returns NaN
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var v = mean( 0.0, NaN );
|
|
50
|
+
* // returns NaN
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* var v = mean( 3.0, 2.0 );
|
|
54
|
+
* // returns NaN
|
|
55
|
+
*/
|
|
56
|
+
function mean( a, b ) {
|
|
57
|
+
return addon( a, b );
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// EXPORTS //
|
|
62
|
+
|
|
63
|
+
module.exports = mean;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"task": "benchmark",
|
|
47
|
+
"wasm": false,
|
|
48
|
+
"src": [
|
|
49
|
+
"./src/main.c"
|
|
50
|
+
],
|
|
51
|
+
"include": [
|
|
52
|
+
"./include"
|
|
53
|
+
],
|
|
54
|
+
"libraries": [],
|
|
55
|
+
"libpath": [],
|
|
56
|
+
"dependencies": [
|
|
57
|
+
"@stdlib/math-base-assert-is-nan"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"task": "examples",
|
|
62
|
+
"wasm": false,
|
|
63
|
+
"src": [
|
|
64
|
+
"./src/main.c"
|
|
65
|
+
],
|
|
66
|
+
"include": [
|
|
67
|
+
"./include"
|
|
68
|
+
],
|
|
69
|
+
"libraries": [],
|
|
70
|
+
"libpath": [],
|
|
71
|
+
"dependencies": [
|
|
72
|
+
"@stdlib/math-base-assert-is-nan"
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-uniform-mean",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Uniform distribution expected value.",
|
|
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",
|
|
@@ -29,7 +32,11 @@
|
|
|
29
32
|
"bugs": {
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
|
-
"dependencies": {
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
37
|
+
"@stdlib/math-base-napi-binary": "^0.3.0",
|
|
38
|
+
"@stdlib/utils-library-manifest": "^0.2.2"
|
|
39
|
+
},
|
|
33
40
|
"devDependencies": {},
|
|
34
41
|
"engines": {
|
|
35
42
|
"node": ">=0.10.0",
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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/math/base/napi/binary.h"
|
|
20
|
+
#include "stdlib/stats/base/dists/uniform/mean.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_uniform_mean )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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/mean.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns the mean of a uniform distribution.
|
|
24
|
+
*
|
|
25
|
+
* @param a minimum support
|
|
26
|
+
* @param b maximum support
|
|
27
|
+
* @return mean
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* double y = stdlib_base_dists_uniform_mean( 0.0, 1.0 );
|
|
31
|
+
* // returns 0.5
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* double y = stdlib_base_dists_uniform_mean( 2.0, 8.0 );
|
|
35
|
+
* // returns 5.0
|
|
36
|
+
*/
|
|
37
|
+
double stdlib_base_dists_uniform_mean( const double a, const double b ) {
|
|
38
|
+
if (
|
|
39
|
+
stdlib_base_is_nan( a ) ||
|
|
40
|
+
stdlib_base_is_nan( b ) ||
|
|
41
|
+
a >= b
|
|
42
|
+
) {
|
|
43
|
+
return 0.0 / 0.0; // NaN
|
|
44
|
+
}
|
|
45
|
+
return ( a + b ) / 2.0;
|
|
46
|
+
}
|