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