@stdlib/stats-base-dists-kumaraswamy-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
@@ -160,22 +160,113 @@ y = mycdf( 0.3 );
160
160
  <!-- eslint no-undef: "error" -->
161
161
 
162
162
  ```javascript
163
- var randu = require( '@stdlib/random-base-randu' );
163
+ var uniform = require( '@stdlib/random-array-uniform' );
164
164
  var EPS = require( '@stdlib/constants-float64-eps' );
165
+ var logEachMap = require( '@stdlib/console-log-each-map' );
165
166
  var cdf = require( '@stdlib/stats-base-dists-kumaraswamy-cdf' );
166
167
 
167
- var a;
168
- var b;
169
- var x;
170
- var y;
171
- var i;
172
-
173
- for ( i = 0; i < 10; i++ ) {
174
- x = randu();
175
- a = ( randu()*5.0 ) + EPS;
176
- b = ( randu()*5.0 ) + EPS;
177
- y = cdf( x, a, b );
178
- console.log( 'x: %d, a: %d, b: %d, F(x;a,b): %d', x.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), y.toFixed( 4 ) );
168
+ var opts = {
169
+ 'dtype': 'float64'
170
+ };
171
+ var x = uniform( 10, 0.0, 1.0, opts );
172
+ var a = uniform( 10, EPS, 5.0, opts );
173
+ var b = uniform( 10, EPS, 5.0, opts );
174
+
175
+ logEachMap( 'x: %0.4f, a: %0.4f, b: %0.4f, F(x;a,b): %0.4f', x, a, b, cdf );
176
+ ```
177
+
178
+ </section>
179
+
180
+ <!-- /.examples -->
181
+
182
+ <!-- C interface documentation. -->
183
+
184
+ * * *
185
+
186
+ <section class="c">
187
+
188
+ ## C APIs
189
+
190
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
191
+
192
+ <section class="intro">
193
+
194
+ </section>
195
+
196
+ <!-- /.intro -->
197
+
198
+ <!-- C usage documentation. -->
199
+
200
+ <section class="usage">
201
+
202
+ ### Usage
203
+
204
+ ```c
205
+ #include "stdlib/stats/base/dists/kumaraswamy/cdf.h"
206
+ ```
207
+
208
+ #### stdlib_base_dists_kumaraswamy_cdf( x, a, b )
209
+
210
+ Evaluates the [cumulative distribution function][cdf] (CDF) for a [Kumaraswamy's double bounded][kumaraswamy-distribution] distribution with parameters `a` (first shape parameter) and `b` (second shape parameter).
211
+
212
+ ```c
213
+ double out = stdlib_base_dists_kumaraswamy_cdf( 0.5, 1.0, 1.0 );
214
+ // returns 0.5
215
+ ```
216
+
217
+ The function accepts the following arguments:
218
+
219
+ - **x**: `[in] double` input value.
220
+ - **a**: `[in] double` first shape parameter.
221
+ - **b**: `[in] double` second shape parameter.
222
+
223
+ ```c
224
+ double stdlib_base_dists_kumaraswamy_cdf( const double x, const double a, const double b );
225
+ ```
226
+
227
+ </section>
228
+
229
+ <!-- /.usage -->
230
+
231
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
232
+
233
+ <section class="notes">
234
+
235
+ </section>
236
+
237
+ <!-- /.notes -->
238
+
239
+ <!-- C API usage examples. -->
240
+
241
+ <section class="examples">
242
+
243
+ ### Examples
244
+
245
+ ```c
246
+ #include "stdlib/stats/base/dists/kumaraswamy/cdf.h"
247
+ #include "stdlib/constants/float64/eps.h"
248
+ #include <stdlib.h>
249
+ #include <stdio.h>
250
+
251
+ static double random_uniform( const double min, const double max ) {
252
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
253
+ return min + ( v*(max-min) );
254
+ }
255
+
256
+ int main( void ) {
257
+ double x;
258
+ double a;
259
+ double b;
260
+ double y;
261
+ int i;
262
+
263
+ for ( i = 0; i < 25; i++ ) {
264
+ x = random_uniform( 0.0, 1.0 );
265
+ a = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
266
+ b = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 5.0 );
267
+ y = stdlib_base_dists_kumaraswamy_cdf( x, a, b );
268
+ printf( "x: %lf, a: %lf, b: %lf, F(x;a,b): %lf\n", x, a, b, y );
269
+ }
179
270
  }
180
271
  ```
181
272
 
@@ -183,6 +274,10 @@ for ( i = 0; i < 10; i++ ) {
183
274
 
184
275
  <!-- /.examples -->
185
276
 
277
+ </section>
278
+
279
+ <!-- /.c -->
280
+
186
281
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
187
282
 
188
283
  <section class="related">
@@ -217,7 +312,7 @@ See [LICENSE][stdlib-license].
217
312
 
218
313
  ## Copyright
219
314
 
220
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
315
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
221
316
 
222
317
  </section>
223
318
 
@@ -230,8 +325,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
230
325
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-kumaraswamy-cdf.svg
231
326
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-kumaraswamy-cdf
232
327
 
233
- [test-image]: https://github.com/stdlib-js/stats-base-dists-kumaraswamy-cdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
234
- [test-url]: https://github.com/stdlib-js/stats-base-dists-kumaraswamy-cdf/actions/workflows/test.yml?query=branch:v0.2.2
328
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-kumaraswamy-cdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
329
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-kumaraswamy-cdf/actions/workflows/test.yml?query=branch:v0.3.0
235
330
 
236
331
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-kumaraswamy-cdf/main.svg
237
332
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-kumaraswamy-cdf?branch=main
@@ -243,8 +338,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
243
338
 
244
339
  -->
245
340
 
246
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
247
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
341
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
342
+ [chat-url]: https://stdlib.zulipchat.com
248
343
 
249
344
  [stdlib]: https://github.com/stdlib-js/stdlib
250
345
 
@@ -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_KUMARASWAMY_CDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_KUMARASWAMY_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 Kumaraswamy's double bounded distribution with parameters `a` (first shape parameter) and `b` (second shape parameter).
31
+ */
32
+ double stdlib_base_dists_kumaraswamy_cdf( const double x, const double a, const double b );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_KUMARASWAMY_CDF_H
package/lib/native.js ADDED
@@ -0,0 +1,88 @@
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 cumulative distribution function (CDF) for a Kumaraswamy's double bounded distribution with parameters `a` (first shape parameter) and `b` (second shape parameter).
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {PositiveNumber} a - first shape parameter
34
+ * @param {PositiveNumber} b - second shape parameter
35
+ * @returns {Probability} evaluated CDF
36
+ *
37
+ * @example
38
+ * var y = cdf( 0.5, 1.0, 1.0 );
39
+ * // returns ~0.5
40
+ *
41
+ * @example
42
+ * var y = cdf( 0.5, 2.0, 4.0 );
43
+ * // returns ~0.684
44
+ *
45
+ * @example
46
+ * var y = cdf( 0.2, 2.0, 2.0 );
47
+ * // returns ~0.078
48
+ *
49
+ * @example
50
+ * var y = cdf( 0.8, 4.0, 4.0 );
51
+ * // returns ~0.878
52
+ *
53
+ * @example
54
+ * var y = cdf( -0.5, 4.0, 2.0 );
55
+ * // returns 0.0
56
+ *
57
+ * @example
58
+ * var y = cdf( 1.5, 4.0, 2.0 );
59
+ * // returns 1.0
60
+ *
61
+ * @example
62
+ * var y = cdf( 2.0, -1.0, 0.5 );
63
+ * // returns NaN
64
+ *
65
+ * @example
66
+ * var y = cdf( 2.0, 0.5, -1.0 );
67
+ * // returns NaN
68
+ *
69
+ * @example
70
+ * var y = cdf( NaN, 1.0, 1.0 );
71
+ * // returns NaN
72
+ *
73
+ * @example
74
+ * var y = cdf( 0.0, NaN, 1.0 );
75
+ * // returns NaN
76
+ *
77
+ * @example
78
+ * var y = cdf( 0.0, 1.0, NaN );
79
+ * // returns NaN
80
+ */
81
+ function cdf( x, a, b ) {
82
+ return addon( x, a, b );
83
+ }
84
+
85
+
86
+ // EXPORTS //
87
+
88
+ module.exports = cdf;
package/manifest.json ADDED
@@ -0,0 +1,81 @@
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-pow"
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-pow",
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/math-base-special-pow",
77
+ "@stdlib/constants-float64-eps"
78
+ ]
79
+ }
80
+ ]
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-kumaraswamy-cdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Kumaraswamy's double bounded 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,9 +34,11 @@
31
34
  },
32
35
  "dependencies": {
33
36
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
37
+ "@stdlib/math-base-napi-ternary": "^0.3.1",
34
38
  "@stdlib/math-base-special-pow": "^0.3.0",
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/kumaraswamy/cdf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_kumaraswamy_cdf )
package/src/main.c ADDED
@@ -0,0 +1,52 @@
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/kumaraswamy/cdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/pow.h"
22
+
23
+ /**
24
+ * Evaluates the cumulative distribution function (CDF) for a Kumaraswamy's double bounded distribution with first shape parameter `a` and second shape parameter `b` at a value `x`.
25
+ *
26
+ * @param x input value
27
+ * @param a first shape parameter
28
+ * @param b second shape parameter
29
+ * @return evaluated CDF
30
+ *
31
+ * @example
32
+ * double y = stdlib_base_kumaraswamy_cdf( 0.5, 1.0, 1.0 );
33
+ * // returns ~0.5
34
+ */
35
+ double stdlib_base_dists_kumaraswamy_cdf( const double x, const double a, const double b ) {
36
+ if (
37
+ stdlib_base_is_nan( x ) ||
38
+ stdlib_base_is_nan( a ) ||
39
+ stdlib_base_is_nan( b ) ||
40
+ a <= 0.0 ||
41
+ b <= 0.0
42
+ ) {
43
+ return 0.0/0.0; // NaN
44
+ }
45
+ if ( x <= 0.0 ) {
46
+ return 0.0;
47
+ }
48
+ if ( x >= 1.0 ) {
49
+ return 1.0;
50
+ }
51
+ return 1.0 - stdlib_base_pow( 1.0 - stdlib_base_pow( x, a ), b );
52
+ }