@stdlib/stats-base-dists-beta-mode 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 +1 -1
- package/README.md +106 -16
- package/include/stdlib/stats/base/dists/beta/mode.h +38 -0
- package/lib/native.js +71 -0
- package/manifest.json +71 -0
- package/package.json +8 -2
- package/src/addon.c +22 -0
- package/src/main.c +37 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -142,20 +142,106 @@ v = mode( 1.0, -1.0 );
|
|
|
142
142
|
<!-- eslint no-undef: "error" -->
|
|
143
143
|
|
|
144
144
|
```javascript
|
|
145
|
-
var
|
|
146
|
-
var
|
|
145
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
146
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
147
147
|
var mode = require( '@stdlib/stats-base-dists-beta-mode' );
|
|
148
148
|
|
|
149
|
-
var
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
var
|
|
149
|
+
var opts = {
|
|
150
|
+
'dtype': 'float64'
|
|
151
|
+
};
|
|
152
|
+
var alpha = uniform( 10, 1.0, 10.0, opts );
|
|
153
|
+
var beta = uniform( 10, 1.0, 10.0, opts );
|
|
153
154
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
logEachMap( 'α: %0.4f, β: %0.4f, mode(X;α,β): %0.4f', alpha, beta, mode );
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
</section>
|
|
159
|
+
|
|
160
|
+
<!-- /.examples -->
|
|
161
|
+
|
|
162
|
+
<!-- C interface documentation. -->
|
|
163
|
+
|
|
164
|
+
* * *
|
|
165
|
+
|
|
166
|
+
<section class="c">
|
|
167
|
+
|
|
168
|
+
## C APIs
|
|
169
|
+
|
|
170
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
171
|
+
|
|
172
|
+
<section class="intro">
|
|
173
|
+
|
|
174
|
+
</section>
|
|
175
|
+
|
|
176
|
+
<!-- /.intro -->
|
|
177
|
+
|
|
178
|
+
<!-- C usage documentation. -->
|
|
179
|
+
|
|
180
|
+
<section class="usage">
|
|
181
|
+
|
|
182
|
+
### Usage
|
|
183
|
+
|
|
184
|
+
```c
|
|
185
|
+
#include "stdlib/stats/base/dists/beta/mode.h"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
#### stdlib_base_dists_beta_mode( alpha, beta )
|
|
189
|
+
|
|
190
|
+
Returns the [mode][mode] of a [beta][beta-distribution] distribution with parameters `alpha` (first shape parameter) and `beta` (second shape parameter).
|
|
191
|
+
|
|
192
|
+
```c
|
|
193
|
+
double out = stdlib_base_dists_beta_mode( 4.0, 12.0 );
|
|
194
|
+
// returns ~0.214
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
The function accepts the following arguments:
|
|
198
|
+
|
|
199
|
+
- **alpha**: `[in] double` first shape parameter.
|
|
200
|
+
- **beta**: `[in] double` second shape parameter.
|
|
201
|
+
|
|
202
|
+
```c
|
|
203
|
+
double stdlib_base_dists_beta_mode( const double alpha, const double beta );
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
</section>
|
|
207
|
+
|
|
208
|
+
<!-- /.usage -->
|
|
209
|
+
|
|
210
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
211
|
+
|
|
212
|
+
<section class="notes">
|
|
213
|
+
|
|
214
|
+
</section>
|
|
215
|
+
|
|
216
|
+
<!-- /.notes -->
|
|
217
|
+
|
|
218
|
+
<!-- C API usage examples. -->
|
|
219
|
+
|
|
220
|
+
<section class="examples">
|
|
221
|
+
|
|
222
|
+
### Examples
|
|
223
|
+
|
|
224
|
+
```c
|
|
225
|
+
#include "stdlib/stats/base/dists/beta/mode.h"
|
|
226
|
+
#include <stdlib.h>
|
|
227
|
+
#include <stdio.h>
|
|
228
|
+
|
|
229
|
+
static double random_uniform( const double min, const double max ) {
|
|
230
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
231
|
+
return min + ( v*(max-min) );
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
int main( void ) {
|
|
235
|
+
double alpha;
|
|
236
|
+
double beta;
|
|
237
|
+
double y;
|
|
238
|
+
int i;
|
|
239
|
+
for ( i = 0; i < 25; i++ ) {
|
|
240
|
+
alpha = random_uniform( 1.0, 11.0 );
|
|
241
|
+
beta = random_uniform( 1.0, 11.0 );
|
|
242
|
+
y = stdlib_base_dists_beta_mode( alpha, beta );
|
|
243
|
+
printf( "α: %lf, β: %lf, mode(X;α,β): %lf\n", alpha, beta, y );
|
|
244
|
+
}
|
|
159
245
|
}
|
|
160
246
|
```
|
|
161
247
|
|
|
@@ -163,6 +249,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
163
249
|
|
|
164
250
|
<!-- /.examples -->
|
|
165
251
|
|
|
252
|
+
</section>
|
|
253
|
+
|
|
254
|
+
<!-- /.c -->
|
|
255
|
+
|
|
166
256
|
<!-- 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. -->
|
|
167
257
|
|
|
168
258
|
<section class="references">
|
|
@@ -205,7 +295,7 @@ See [LICENSE][stdlib-license].
|
|
|
205
295
|
|
|
206
296
|
## Copyright
|
|
207
297
|
|
|
208
|
-
Copyright © 2016-
|
|
298
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
209
299
|
|
|
210
300
|
</section>
|
|
211
301
|
|
|
@@ -218,8 +308,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
218
308
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-beta-mode.svg
|
|
219
309
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-beta-mode
|
|
220
310
|
|
|
221
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-beta-mode/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
222
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-beta-mode/actions/workflows/test.yml?query=branch:v0.
|
|
311
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-beta-mode/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
312
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-beta-mode/actions/workflows/test.yml?query=branch:v0.3.0
|
|
223
313
|
|
|
224
314
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-beta-mode/main.svg
|
|
225
315
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-beta-mode?branch=main
|
|
@@ -231,8 +321,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
231
321
|
|
|
232
322
|
-->
|
|
233
323
|
|
|
234
|
-
[chat-image]: https://img.shields.io/
|
|
235
|
-
[chat-url]: https://
|
|
324
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
325
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
236
326
|
|
|
237
327
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
238
328
|
|
|
@@ -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_BETA_MODE_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_BETA_MODE_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 mode of a beta distribution.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_beta_mode( const double alpha, const double beta );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_BETA_MODE_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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 mode of a beta distribution.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {PositiveNumber} alpha - first shape parameter
|
|
33
|
+
* @param {PositiveNumber} beta - second shape parameter
|
|
34
|
+
* @returns {PositiveNumber} mode
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var v = mode( 4.0, 12.0 );
|
|
38
|
+
* // returns ~0.214
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var v = mode( 8.0, 2.0 );
|
|
42
|
+
* // returns ~0.875
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var v = mode( 1.0, 1.0 );
|
|
46
|
+
* // returns NaN
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var v = mode( 2.0, 0.8 );
|
|
50
|
+
* // returns NaN
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* var v = mode( -0.1, 2.0 );
|
|
54
|
+
* // returns NaN
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* var v = mode( 2.0, NaN );
|
|
58
|
+
* // returns NaN
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* var v = mode( NaN, 2.0 );
|
|
62
|
+
* // returns NaN
|
|
63
|
+
*/
|
|
64
|
+
function mode( alpha, beta ) {
|
|
65
|
+
return addon( alpha, beta );
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// EXPORTS //
|
|
70
|
+
|
|
71
|
+
module.exports = mode;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"task": "benchmark",
|
|
46
|
+
"wasm": false,
|
|
47
|
+
"src": [
|
|
48
|
+
"./src/main.c"
|
|
49
|
+
],
|
|
50
|
+
"include": [
|
|
51
|
+
"./include"
|
|
52
|
+
],
|
|
53
|
+
"libraries": [],
|
|
54
|
+
"libpath": [],
|
|
55
|
+
"dependencies": []
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"task": "examples",
|
|
59
|
+
"wasm": false,
|
|
60
|
+
"src": [
|
|
61
|
+
"./src/main.c"
|
|
62
|
+
],
|
|
63
|
+
"include": [
|
|
64
|
+
"./include"
|
|
65
|
+
],
|
|
66
|
+
"libraries": [],
|
|
67
|
+
"libpath": [],
|
|
68
|
+
"dependencies": []
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-beta-mode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Beta distribution mode.",
|
|
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",
|
|
@@ -29,7 +32,10 @@
|
|
|
29
32
|
"bugs": {
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
|
-
"dependencies": {
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@stdlib/math-base-napi-binary": "^0.3.0",
|
|
37
|
+
"@stdlib/utils-library-manifest": "^0.2.2"
|
|
38
|
+
},
|
|
33
39
|
"devDependencies": {},
|
|
34
40
|
"engines": {
|
|
35
41
|
"node": ">=0.10.0",
|
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/beta/mode.h"
|
|
20
|
+
#include "stdlib/math/base/napi/binary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_beta_mode )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
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/beta/mode.h"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the mode of a beta distribution.
|
|
23
|
+
*
|
|
24
|
+
* @param alpha first shape parameter
|
|
25
|
+
* @param beta second shape parameter
|
|
26
|
+
* @return mode
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* double y = stdlib_base_dists_beta_mode( 4.0, 12.0 );
|
|
30
|
+
* // returns ~0.214
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_beta_mode( const double alpha, const double beta ) {
|
|
33
|
+
if ( alpha <= 1.0 || beta <= 1.0 ) {
|
|
34
|
+
return 0.0/0.0; // NaN
|
|
35
|
+
}
|
|
36
|
+
return ( alpha-1.0 ) / ( alpha+beta-2.0 );
|
|
37
|
+
}
|