@stdlib/stats-base-dists-frechet-median 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 -9
- package/include/stdlib/stats/base/dists/frechet/median.h +38 -0
- package/lib/native.js +68 -0
- package/manifest.json +84 -0
- package/package.json +9 -4
- package/src/addon.c +23 -0
- package/src/main.c +47 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -156,7 +156,7 @@ var i;
|
|
|
156
156
|
for ( i = 0; i < 10; i++ ) {
|
|
157
157
|
alpha = ( randu()*20.0 ) + EPS;
|
|
158
158
|
s = ( randu()*20.0 ) + EPS;
|
|
159
|
-
m = ( randu()*
|
|
159
|
+
m = ( randu()*40.0 ) - 20.0;
|
|
160
160
|
y = median( alpha, s, m );
|
|
161
161
|
console.log( 'α: %d, s: %d, m: %d, Median(X;α,s,m): %d', alpha.toFixed( 4 ), s.toFixed( 4 ), m.toFixed( 4 ), y.toFixed( 4 ) );
|
|
162
162
|
}
|
|
@@ -166,13 +166,104 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
166
166
|
|
|
167
167
|
<!-- /.examples -->
|
|
168
168
|
|
|
169
|
-
<!--
|
|
169
|
+
<!-- C interface documentation. -->
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
* * *
|
|
172
|
+
|
|
173
|
+
<section class="c">
|
|
174
|
+
|
|
175
|
+
## C APIs
|
|
176
|
+
|
|
177
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
178
|
+
|
|
179
|
+
<section class="intro">
|
|
180
|
+
|
|
181
|
+
</section>
|
|
182
|
+
|
|
183
|
+
<!-- /.intro -->
|
|
184
|
+
|
|
185
|
+
<!-- C usage documentation. -->
|
|
186
|
+
|
|
187
|
+
<section class="usage">
|
|
188
|
+
|
|
189
|
+
### Usage
|
|
190
|
+
|
|
191
|
+
```c
|
|
192
|
+
#include "stdlib/stats/base/dists/frechet/median.h"
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
#### stdlib_base_dists_frechet_median( alpha, s, m )
|
|
196
|
+
|
|
197
|
+
Returns the median for a Fréchet distribution with shape `alpha`, scale `s`, and location `m`.
|
|
198
|
+
|
|
199
|
+
```c
|
|
200
|
+
double y = stdlib_base_dists_frechet_median( 5.0, 2.0, 0.0 );
|
|
201
|
+
// returns ~2.152
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The function accepts the following arguments:
|
|
205
|
+
|
|
206
|
+
- **alpha**: `[in] double` shape parameter.
|
|
207
|
+
- **s**: `[in] double` scale parameter.
|
|
208
|
+
- **m**: `[in] double` location parameter.
|
|
209
|
+
|
|
210
|
+
```c
|
|
211
|
+
double stdlib_base_dists_frechet_median( const double alpha, const double s, const double m );
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
</section>
|
|
215
|
+
|
|
216
|
+
<!-- /.usage -->
|
|
217
|
+
|
|
218
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
219
|
+
|
|
220
|
+
<section class="notes">
|
|
221
|
+
|
|
222
|
+
</section>
|
|
223
|
+
|
|
224
|
+
<!-- /.notes -->
|
|
225
|
+
|
|
226
|
+
<!-- C API usage examples. -->
|
|
227
|
+
|
|
228
|
+
<section class="examples">
|
|
229
|
+
|
|
230
|
+
### Examples
|
|
231
|
+
|
|
232
|
+
```c
|
|
233
|
+
#include "stdlib/stats/base/dists/frechet/median.h"
|
|
234
|
+
#include "stdlib/constants/float64/eps.h"
|
|
235
|
+
#include <stdlib.h>
|
|
236
|
+
#include <stdio.h>
|
|
237
|
+
|
|
238
|
+
static double random_uniform( const double min, const double max ) {
|
|
239
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
240
|
+
return min + ( v*(max-min) );
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
int main( void ) {
|
|
244
|
+
double alpha;
|
|
245
|
+
double s;
|
|
246
|
+
double m;
|
|
247
|
+
double y;
|
|
248
|
+
int i;
|
|
249
|
+
|
|
250
|
+
for ( i = 0; i < 10; i++ ) {
|
|
251
|
+
alpha = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
|
|
252
|
+
s = random_uniform( STDLIB_CONSTANT_FLOAT64_EPS, 20.0 );
|
|
253
|
+
m = random_uniform( -20.0, 20.0 );
|
|
254
|
+
y = stdlib_base_dists_frechet_median( alpha, s, m );
|
|
255
|
+
printf( "α: %.4lf, s: %.4lf, m: %.4lf, Median(X;α,s,m): %.4lf\n", alpha, s, m, y );
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
</section>
|
|
261
|
+
|
|
262
|
+
<!-- /.examples -->
|
|
172
263
|
|
|
173
264
|
</section>
|
|
174
265
|
|
|
175
|
-
<!-- /.
|
|
266
|
+
<!-- /.c -->
|
|
176
267
|
|
|
177
268
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
178
269
|
|
|
@@ -208,7 +299,7 @@ See [LICENSE][stdlib-license].
|
|
|
208
299
|
|
|
209
300
|
## Copyright
|
|
210
301
|
|
|
211
|
-
Copyright © 2016-
|
|
302
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
212
303
|
|
|
213
304
|
</section>
|
|
214
305
|
|
|
@@ -221,8 +312,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
221
312
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-frechet-median.svg
|
|
222
313
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-frechet-median
|
|
223
314
|
|
|
224
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-frechet-median/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
225
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-frechet-median/actions/workflows/test.yml?query=branch:v0.
|
|
315
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-frechet-median/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
316
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-frechet-median/actions/workflows/test.yml?query=branch:v0.3.0
|
|
226
317
|
|
|
227
318
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-frechet-median/main.svg
|
|
228
319
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-frechet-median?branch=main
|
|
@@ -234,8 +325,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
234
325
|
|
|
235
326
|
-->
|
|
236
327
|
|
|
237
|
-
[chat-image]: https://img.shields.io/
|
|
238
|
-
[chat-url]: https://
|
|
328
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
329
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
239
330
|
|
|
240
331
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
241
332
|
|
|
@@ -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_FRECHET_MEDIAN_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_FRECHET_MEDIAN_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 median for a Fréchet distribution with shape `alpha`, scale `s`, and location `m`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_frechet_median( const double alpha, const double s, const double m );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_FRECHET_MEDIAN_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
* Returns the median for a Fréchet distribution with shape `alpha`, scale `s`, and location `m`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {PositiveNumber} alpha - shape parameter
|
|
33
|
+
* @param {PositiveNumber} s - scale parameter
|
|
34
|
+
* @param {number} m - location parameter
|
|
35
|
+
* @returns {number} median
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var y = median( 5.0, 2.0, 0.0 );
|
|
39
|
+
* // returns ~2.152
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var y = median( 5.0, 2.0, -5.0 );
|
|
43
|
+
* // returns ~-2.848
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = median( 1.0, 1.0, 0.0 );
|
|
47
|
+
* // returns ~1.443
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var y = median( NaN, 1.0, 0.0 );
|
|
51
|
+
* // returns NaN
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var y = median( 1.0, NaN, 0.0 );
|
|
55
|
+
* // returns NaN
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* var y = median( 1.0, 1.0, NaN );
|
|
59
|
+
* // returns NaN
|
|
60
|
+
*/
|
|
61
|
+
function median( alpha, s, m ) {
|
|
62
|
+
return addon( alpha, s, m );
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// EXPORTS //
|
|
67
|
+
|
|
68
|
+
module.exports = median;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
"@stdlib/constants-float64-ln-two"
|
|
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-pow",
|
|
61
|
+
"@stdlib/constants-float64-ln-two",
|
|
62
|
+
"@stdlib/constants-float64-eps"
|
|
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-pow",
|
|
79
|
+
"@stdlib/constants-float64-ln-two",
|
|
80
|
+
"@stdlib/constants-float64-eps"
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-frechet-median",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Fréchet distribution median.",
|
|
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,9 +33,11 @@
|
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@stdlib/constants-float64-ln-two": "^0.2.
|
|
34
|
-
"@stdlib/math-base-assert-is-nan": "^0.2.
|
|
35
|
-
"@stdlib/math-base-
|
|
36
|
+
"@stdlib/constants-float64-ln-two": "^0.2.2",
|
|
37
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
38
|
+
"@stdlib/math-base-napi-ternary": "^0.3.1",
|
|
39
|
+
"@stdlib/math-base-special-pow": "^0.3.0",
|
|
40
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
36
41
|
},
|
|
37
42
|
"devDependencies": {},
|
|
38
43
|
"engines": {
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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/frechet/median.h"
|
|
20
|
+
#include "stdlib/math/base/napi/ternary.h"
|
|
21
|
+
|
|
22
|
+
// cppcheck-suppress shadowFunction
|
|
23
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_frechet_median )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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/frechet/median.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/pow.h"
|
|
22
|
+
#include "stdlib/constants/float64/ln_two.h"
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns the median for a Fréchet distribution with shape `alpha`, scale `s`, and location `m`.
|
|
26
|
+
*
|
|
27
|
+
* @param alpha shape parameter
|
|
28
|
+
* @param s scale parameter
|
|
29
|
+
* @param m location parameter
|
|
30
|
+
* @return median
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* double y = stdlib_base_dists_frechet_median( 5.0, 2.0, 0.0 );
|
|
34
|
+
* // returns ~2.152
|
|
35
|
+
*/
|
|
36
|
+
double stdlib_base_dists_frechet_median( const double alpha, const double s, const double m ) {
|
|
37
|
+
if (
|
|
38
|
+
stdlib_base_is_nan( alpha ) ||
|
|
39
|
+
stdlib_base_is_nan( s ) ||
|
|
40
|
+
stdlib_base_is_nan( m ) ||
|
|
41
|
+
alpha <= 0.0 ||
|
|
42
|
+
s <= 0.0
|
|
43
|
+
) {
|
|
44
|
+
return 0.0/0.0; // NaN
|
|
45
|
+
}
|
|
46
|
+
return m + ( s * stdlib_base_pow( STDLIB_CONSTANT_FLOAT64_LN2, -1.0/alpha ) );
|
|
47
|
+
}
|