@stdlib/stats-base-dists-rayleigh-cdf 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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -123,7 +123,7 @@ Returns a function for evaluating the [cumulative distribution function][cdf] of
123
123
 
124
124
  ```javascript
125
125
  var myCDF = cdf.factory( 0.5 );
126
- y = myCDF( 1.0 );
126
+ var y = myCDF( 1.0 );
127
127
  // returns ~0.865
128
128
 
129
129
  y = myCDF( 0.5 );
@@ -141,19 +141,107 @@ y = myCDF( 0.5 );
141
141
  <!-- eslint no-undef: "error" -->
142
142
 
143
143
  ```javascript
144
- var randu = require( '@stdlib/random-base-randu' );
144
+ var uniform = require( '@stdlib/random-array-uniform' );
145
+ var logEachMap = require( '@stdlib/console-log-each-map' );
145
146
  var cdf = require( '@stdlib/stats-base-dists-rayleigh-cdf' );
146
147
 
147
- var sigma;
148
- var x;
149
- var y;
150
- var i;
148
+ var opts = {
149
+ 'dtype': 'float64'
150
+ };
151
+ var x = uniform( 10, 0.0, 10.0, opts );
152
+ var sigma = uniform( 10, 0.0, 10.0, opts );
151
153
 
152
- for ( i = 0; i < 10; i++ ) {
153
- x = randu() * 10.0;
154
- sigma = randu() * 10.0;
155
- y = cdf( x, sigma );
156
- console.log( 'x: %d, σ: %d, F(x;σ): %d', x.toFixed( 4 ), sigma.toFixed( 4 ), y.toFixed( 4 ) );
154
+ logEachMap( 'x: %0.4f, σ: %0.4f, F(x;σ): %0.4f', x, sigma, cdf );
155
+ ```
156
+
157
+ </section>
158
+
159
+ <!-- /.examples -->
160
+
161
+ <!-- C interface documentation. -->
162
+
163
+ * * *
164
+
165
+ <section class="c">
166
+
167
+ ## C APIs
168
+
169
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
170
+
171
+ <section class="intro">
172
+
173
+ </section>
174
+
175
+ <!-- /.intro -->
176
+
177
+ <!-- C usage documentation. -->
178
+
179
+ <section class="usage">
180
+
181
+ ### Usage
182
+
183
+ ```c
184
+ #include "stdlib/stats/base/dists/rayleigh/cdf.h"
185
+ ```
186
+
187
+ #### stdlib_base_dists_rayleigh_cdf( x, sigma )
188
+
189
+ Evaluates the cumulative distribution function (CDF) for a Rayleigh distribution.
190
+
191
+ ```c
192
+ double out = stdlib_base_dists_rayleigh_cdf( 2.0, 3.0 );
193
+ // returns ~0.199
194
+ ```
195
+
196
+ The function accepts the following arguments:
197
+
198
+ - **x**: `[in] double` input value.
199
+ - **sigma**: `[in] double` scale parameter.
200
+
201
+ ```c
202
+ double stdlib_base_dists_rayleigh_cdf( const double x, const double sigma );
203
+ ```
204
+
205
+ </section>
206
+
207
+ <!-- /.usage -->
208
+
209
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
210
+
211
+ <section class="notes">
212
+
213
+ </section>
214
+
215
+ <!-- /.notes -->
216
+
217
+ <!-- C API usage examples. -->
218
+
219
+ <section class="examples">
220
+
221
+ ### Examples
222
+
223
+ ```c
224
+ #include "stdlib/stats/base/dists/rayleigh/cdf.h"
225
+ #include <stdlib.h>
226
+ #include <stdio.h>
227
+
228
+ static double random_uniform( const double min, const double max ) {
229
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
230
+ return min + ( v*(max-min) );
231
+ }
232
+
233
+ int main( void ) {
234
+ double sigma;
235
+ double x;
236
+ double y;
237
+ int i;
238
+
239
+ for ( i = 0; i < 25; i++ ) {
240
+ x = random_uniform( 0.0, 10.0 );
241
+ sigma = random_uniform( 0.0, 10.0 );
242
+ y = stdlib_base_dists_rayleigh_cdf( x, sigma );
243
+ printf( "x: %lf, σ: %lf, F(x;σ): %lf\n", x, sigma, y );
244
+ }
157
245
  }
158
246
  ```
159
247
 
@@ -161,6 +249,10 @@ for ( i = 0; i < 10; i++ ) {
161
249
 
162
250
  <!-- /.examples -->
163
251
 
252
+ </section>
253
+
254
+ <!-- /.c -->
255
+
164
256
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
165
257
 
166
258
  <section class="related">
@@ -195,7 +287,7 @@ See [LICENSE][stdlib-license].
195
287
 
196
288
  ## Copyright
197
289
 
198
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
290
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
199
291
 
200
292
  </section>
201
293
 
@@ -208,8 +300,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
208
300
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-rayleigh-cdf.svg
209
301
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-rayleigh-cdf
210
302
 
211
- [test-image]: https://github.com/stdlib-js/stats-base-dists-rayleigh-cdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
212
- [test-url]: https://github.com/stdlib-js/stats-base-dists-rayleigh-cdf/actions/workflows/test.yml?query=branch:v0.2.2
303
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-rayleigh-cdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
304
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-rayleigh-cdf/actions/workflows/test.yml?query=branch:v0.3.0
213
305
 
214
306
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-rayleigh-cdf/main.svg
215
307
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-rayleigh-cdf?branch=main
@@ -221,8 +313,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
221
313
 
222
314
  -->
223
315
 
224
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
225
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
316
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
317
+ [chat-url]: https://stdlib.zulipchat.com
226
318
 
227
319
  [stdlib]: https://github.com/stdlib-js/stdlib
228
320
 
@@ -94,11 +94,11 @@ interface CDF {
94
94
  *
95
95
  * @example
96
96
  * var y = cdf( 2.0, 0.0, 1.0 );
97
- * // returns ~0.977
97
+ * // returns 1.0
98
98
  *
99
99
  * var myCDF = cdf.factory( 10.0, 2.0 );
100
100
  * y = myCDF( 10.0 );
101
- * // returns 0.5
101
+ * // returns ~0.393
102
102
  */
103
103
  declare var cdf: CDF;
104
104
 
@@ -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_CDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_RAYLEIGH_CDF_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 cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma` at a value `x`.
31
+ */
32
+ double stdlib_base_dists_rayleigh_cdf( const double x, const double sigma );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_RAYLEIGH_CDF_H
package/lib/native.js ADDED
@@ -0,0 +1,68 @@
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
+ * Evaluates the cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma` at a value `x`.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {NonNegativeNumber} sigma - scale parameter
34
+ * @returns {Probability} evaluated CDF
35
+ *
36
+ * @example
37
+ * var y = cdf( 2.0, 3.0 );
38
+ * // returns ~0.199
39
+ *
40
+ * @example
41
+ * var y = cdf( 1.0, 2.0 );
42
+ * // returns ~0.118
43
+ *
44
+ * @example
45
+ * var y = cdf( -1.0, 4.0 );
46
+ * // returns 0.0
47
+ *
48
+ * @example
49
+ * var y = cdf( NaN, 1.0 );
50
+ * // returns NaN
51
+ *
52
+ * @example
53
+ * var y = cdf( 0.0, NaN );
54
+ * // returns NaN
55
+ *
56
+ * @example
57
+ * // Negative scale parameter:
58
+ * var y = cdf( 2.0, -1.0 );
59
+ * // returns NaN
60
+ */
61
+ function cdf( x, sigma ) {
62
+ return addon( x, sigma );
63
+ }
64
+
65
+
66
+ // EXPORTS //
67
+
68
+ module.exports = cdf;
package/manifest.json ADDED
@@ -0,0 +1,83 @@
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/math-base-special-exp",
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-nan",
60
+ "@stdlib/math-base-special-exp",
61
+ "@stdlib/constants-float64-eps",
62
+ "@stdlib/math-base-special-pow"
63
+ ]
64
+ },
65
+ {
66
+ "task": "examples",
67
+ "wasm": false,
68
+ "src": [
69
+ "./src/main.c"
70
+ ],
71
+ "include": [
72
+ "./include"
73
+ ],
74
+ "libraries": [],
75
+ "libpath": [],
76
+ "dependencies": [
77
+ "@stdlib/math-base-assert-is-nan",
78
+ "@stdlib/math-base-special-exp",
79
+ "@stdlib/math-base-special-pow"
80
+ ]
81
+ }
82
+ ]
83
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-rayleigh-cdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Rayleigh distribution cumulative distribution function (CDF).",
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,11 +34,13 @@
31
34
  },
32
35
  "dependencies": {
33
36
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
34
- "@stdlib/math-base-special-exp": "^0.2.3",
37
+ "@stdlib/math-base-napi-binary": "^0.3.1",
38
+ "@stdlib/math-base-special-exp": "^0.2.4",
35
39
  "@stdlib/math-base-special-pow": "^0.3.0",
36
- "@stdlib/stats-base-dists-degenerate-cdf": "^0.2.2",
40
+ "@stdlib/stats-base-dists-degenerate-cdf": "^0.3.0",
37
41
  "@stdlib/utils-constant-function": "^0.2.2",
38
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
42
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
43
+ "@stdlib/utils-library-manifest": "^0.2.3"
39
44
  },
40
45
  "devDependencies": {},
41
46
  "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/cdf.h"
20
+ #include "stdlib/math/base/napi/binary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_rayleigh_cdf )
package/src/main.c ADDED
@@ -0,0 +1,52 @@
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/cdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/exp.h"
22
+ #include "stdlib/math/base/special/pow.h"
23
+
24
+ /**
25
+ * Evaluates the cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma` at a value `x`.
26
+ *
27
+ * @param x input value
28
+ * @param sigma scale parameter
29
+ * @return evaluated CDF
30
+ *
31
+ * @example
32
+ * double y = stdlib_base_dists_rayleigh_cdf( 2.0, 3.0 );
33
+ * // returns ~0.199
34
+ */
35
+ double stdlib_base_dists_rayleigh_cdf( const double x, const double sigma ) {
36
+ double s2;
37
+ if (
38
+ stdlib_base_is_nan( x ) ||
39
+ stdlib_base_is_nan( sigma ) ||
40
+ sigma < 0.0
41
+ ) {
42
+ return 0.0/0.0; // NaN
43
+ }
44
+ if ( sigma == 0.0 ) {
45
+ return ( x < 0.0 ) ? 0.0 : 1.0;
46
+ }
47
+ if ( x < 0.0 ) {
48
+ return 0.0;
49
+ }
50
+ s2 = stdlib_base_pow( sigma, 2.0 );
51
+ return 1.0 - stdlib_base_exp( -stdlib_base_pow( x, 2.0 ) / ( 2.0 * s2 ) );
52
+ }