@stdlib/stats-base-dists-rayleigh-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 +103 -14
- package/include/stdlib/stats/base/dists/rayleigh/mean.h +38 -0
- package/lib/native.js +58 -0
- package/manifest.json +80 -0
- package/package.json +8 -3
- package/src/addon.c +22 -0
- package/src/main.c +41 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -119,18 +119,103 @@ y = mean( -0.1 );
|
|
|
119
119
|
<!-- eslint no-undef: "error" -->
|
|
120
120
|
|
|
121
121
|
```javascript
|
|
122
|
-
var
|
|
123
|
-
var
|
|
122
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
123
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
124
124
|
var mean = require( '@stdlib/stats-base-dists-rayleigh-mean' );
|
|
125
125
|
|
|
126
|
-
var
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
var opts = {
|
|
127
|
+
'dtype': 'float64'
|
|
128
|
+
};
|
|
129
|
+
var sigma = uniform( 10, 0.0, 20.0, opts );
|
|
129
130
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
logEachMap( 'σ: %0.4f, E(X;σ): %0.4f', sigma, mean );
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
</section>
|
|
135
|
+
|
|
136
|
+
<!-- /.examples -->
|
|
137
|
+
|
|
138
|
+
<!-- C interface documentation. -->
|
|
139
|
+
|
|
140
|
+
* * *
|
|
141
|
+
|
|
142
|
+
<section class="c">
|
|
143
|
+
|
|
144
|
+
## C APIs
|
|
145
|
+
|
|
146
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
147
|
+
|
|
148
|
+
<section class="intro">
|
|
149
|
+
|
|
150
|
+
</section>
|
|
151
|
+
|
|
152
|
+
<!-- /.intro -->
|
|
153
|
+
|
|
154
|
+
<!-- C usage documentation. -->
|
|
155
|
+
|
|
156
|
+
<section class="usage">
|
|
157
|
+
|
|
158
|
+
### Usage
|
|
159
|
+
|
|
160
|
+
```c
|
|
161
|
+
#include "stdlib/stats/base/dists/rayleigh/mean.h"
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### stdlib_base_dists_rayleigh_mean( sigma )
|
|
165
|
+
|
|
166
|
+
Returns the mean of a Rayleigh distribution.
|
|
167
|
+
|
|
168
|
+
```c
|
|
169
|
+
double out = stdlib_base_dists_rayleigh_mean( 9.0 );
|
|
170
|
+
// returns ~11.253
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The function accepts the following arguments:
|
|
174
|
+
|
|
175
|
+
- **sigma**: `[in] double` scale parameter.
|
|
176
|
+
|
|
177
|
+
```c
|
|
178
|
+
double stdlib_base_dists_rayleigh_mean( const double sigma );
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
</section>
|
|
182
|
+
|
|
183
|
+
<!-- /.usage -->
|
|
184
|
+
|
|
185
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
186
|
+
|
|
187
|
+
<section class="notes">
|
|
188
|
+
|
|
189
|
+
</section>
|
|
190
|
+
|
|
191
|
+
<!-- /.notes -->
|
|
192
|
+
|
|
193
|
+
<!-- C API usage examples. -->
|
|
194
|
+
|
|
195
|
+
<section class="examples">
|
|
196
|
+
|
|
197
|
+
### Examples
|
|
198
|
+
|
|
199
|
+
```c
|
|
200
|
+
#include "stdlib/stats/base/dists/rayleigh/mean.h"
|
|
201
|
+
#include <stdlib.h>
|
|
202
|
+
#include <stdio.h>
|
|
203
|
+
|
|
204
|
+
static double random_uniform( const double min, const double max ) {
|
|
205
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
206
|
+
return min + ( v * ( max - min ) );
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
int main( void ) {
|
|
210
|
+
double sigma;
|
|
211
|
+
double y;
|
|
212
|
+
int i;
|
|
213
|
+
|
|
214
|
+
for ( i = 0; i < 25; i++ ) {
|
|
215
|
+
sigma = random_uniform( 0.0, 20.0 );
|
|
216
|
+
y = stdlib_base_dists_rayleigh_mean( sigma );
|
|
217
|
+
printf( "σ: %lf, E(X;σ): %lf\n", sigma, y );
|
|
218
|
+
}
|
|
134
219
|
}
|
|
135
220
|
```
|
|
136
221
|
|
|
@@ -138,6 +223,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
138
223
|
|
|
139
224
|
<!-- /.examples -->
|
|
140
225
|
|
|
226
|
+
</section>
|
|
227
|
+
|
|
228
|
+
<!-- /.c -->
|
|
229
|
+
|
|
141
230
|
<!-- 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. -->
|
|
142
231
|
|
|
143
232
|
<section class="references">
|
|
@@ -180,7 +269,7 @@ See [LICENSE][stdlib-license].
|
|
|
180
269
|
|
|
181
270
|
## Copyright
|
|
182
271
|
|
|
183
|
-
Copyright © 2016-
|
|
272
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
184
273
|
|
|
185
274
|
</section>
|
|
186
275
|
|
|
@@ -193,8 +282,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
193
282
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-rayleigh-mean.svg
|
|
194
283
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-rayleigh-mean
|
|
195
284
|
|
|
196
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-rayleigh-mean/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
197
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-rayleigh-mean/actions/workflows/test.yml?query=branch:v0.
|
|
285
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-rayleigh-mean/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
286
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-rayleigh-mean/actions/workflows/test.yml?query=branch:v0.3.0
|
|
198
287
|
|
|
199
288
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-rayleigh-mean/main.svg
|
|
200
289
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-rayleigh-mean?branch=main
|
|
@@ -206,8 +295,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
206
295
|
|
|
207
296
|
-->
|
|
208
297
|
|
|
209
|
-
[chat-image]: https://img.shields.io/
|
|
210
|
-
[chat-url]: https://
|
|
298
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
299
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
211
300
|
|
|
212
301
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
213
302
|
|
|
@@ -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_RAYLEIGH_MEAN_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_RAYLEIGH_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 Rayleigh distribution.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_rayleigh_mean( const double sigma );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_RAYLEIGH_MEAN_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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 Rayleigh distribution.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {NonNegativeNumber} sigma - scale parameter
|
|
33
|
+
* @returns {NonNegativeNumber} mean
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* var m = mean( 9.0 );
|
|
37
|
+
* // returns ~11.2798
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* var m = mean( 2.0 );
|
|
41
|
+
* // returns ~2.507
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* var m = mean( -0.2 );
|
|
45
|
+
* // returns NaN
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* var m = mean( NaN );
|
|
49
|
+
* // returns NaN
|
|
50
|
+
*/
|
|
51
|
+
function mean( sigma ) {
|
|
52
|
+
return addon( sigma );
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// EXPORTS //
|
|
57
|
+
|
|
58
|
+
module.exports = mean;
|
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-unary",
|
|
42
|
+
"@stdlib/math-base-assert-is-nan",
|
|
43
|
+
"@stdlib/constants-float64-sqrt-half-pi"
|
|
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-sqrt-half-pi",
|
|
60
|
+
"@stdlib/constants-float64-eps"
|
|
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-sqrt-half-pi"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-rayleigh-mean",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Rayleigh 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",
|
|
@@ -30,8 +33,10 @@
|
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@stdlib/constants-float64-sqrt-half-pi": "^0.2.
|
|
34
|
-
"@stdlib/math-base-assert-is-nan": "^0.2.
|
|
36
|
+
"@stdlib/constants-float64-sqrt-half-pi": "^0.2.2",
|
|
37
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
38
|
+
"@stdlib/math-base-napi-unary": "^0.2.4",
|
|
39
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {},
|
|
37
42
|
"engines": {
|
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/stats/base/dists/rayleigh/mean.h"
|
|
20
|
+
#include "stdlib/math/base/napi/unary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_dists_rayleigh_mean )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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/rayleigh/mean.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/constants/float64/sqrt_half_pi.h"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns the mean of a Rayleigh distribution.
|
|
25
|
+
*
|
|
26
|
+
* @param sigma scale parameter
|
|
27
|
+
* @return mean
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* double y = stdlib_base_dists_rayleigh_mean( 9.0 );
|
|
31
|
+
* // returns ~11.253
|
|
32
|
+
*/
|
|
33
|
+
double stdlib_base_dists_rayleigh_mean( const double sigma ) {
|
|
34
|
+
if (
|
|
35
|
+
stdlib_base_is_nan( sigma ) ||
|
|
36
|
+
sigma < 0.0
|
|
37
|
+
) {
|
|
38
|
+
return 0.0 / 0.0; // NaN
|
|
39
|
+
}
|
|
40
|
+
return sigma * STDLIB_CONSTANT_FLOAT64_SQRT_HALF_PI;
|
|
41
|
+
}
|