@stdlib/stats-base-dists-arcsine-pdf 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
@@ -134,21 +134,109 @@ y = myPDF( 5.0 );
134
134
  <!-- eslint no-undef: "error" -->
135
135
 
136
136
  ```javascript
137
- var randu = require( '@stdlib/random-base-randu' );
137
+ var uniform = require( '@stdlib/random-array-uniform' );
138
+ var logEachMap = require( '@stdlib/console-log-each-map' );
138
139
  var pdf = require( '@stdlib/stats-base-dists-arcsine-pdf' );
139
140
 
140
- var a;
141
- var b;
142
- var x;
143
- var y;
144
- var i;
145
-
146
- for ( i = 0; i < 25; i++ ) {
147
- x = ( randu()*20.0 )- 10.0;
148
- a = ( randu()*20.0 )- 20.0;
149
- b = a + ( randu()*40.0 );
150
- y = pdf( x, a, b );
151
- 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 ) );
141
+ var opts = {
142
+ 'dtype': 'float64'
143
+ };
144
+ var x = uniform( 25, -10.0, 10.0, opts );
145
+ var a = uniform( x.length, -20.0, 0.0, opts );
146
+ var b = uniform( x.length, 0.0, 40.0, opts );
147
+
148
+ logEachMap( 'x: %0.4f, a: %0.4f, b: %0.4f, f(x;a,b): %0.4f', x, a, b, pdf );
149
+ ```
150
+
151
+ </section>
152
+
153
+ <!-- C interface documentation. -->
154
+
155
+ * * *
156
+
157
+ <section class="c">
158
+
159
+ ## C APIs
160
+
161
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
162
+
163
+ <section class="intro">
164
+
165
+ </section>
166
+
167
+ <!-- /.intro -->
168
+
169
+ <!-- C usage documentation. -->
170
+
171
+ <section class="usage">
172
+
173
+ ### Usage
174
+
175
+ ```c
176
+ #include "stdlib/stats/base/dists/arcsine/pdf.h"
177
+ ```
178
+
179
+ #### stdlib_base_dists_arcsine_pdf( x, a, b )
180
+
181
+ Evaluates the probability density function (PDF) for an arcsine distribution.
182
+
183
+ ```c
184
+ double out = stdlib_base_dists_arcsine_pdf( 0.5, 0.0, 4.0 );
185
+ // returns ~0.159
186
+ ```
187
+
188
+ The function accepts the following arguments:
189
+
190
+ - **x**: `[in] double` input value.
191
+ - **a**: `[in] double` minimum support.
192
+ - **b**: `[in] double` maximum support.
193
+
194
+ ```c
195
+ double stdlib_base_dists_arcsine_pdf( const double x, const double a, const double b );
196
+ ```
197
+
198
+ </section>
199
+
200
+ <!-- /.usage -->
201
+
202
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
203
+
204
+ <section class="notes">
205
+
206
+ </section>
207
+
208
+ <!-- /.notes -->
209
+
210
+ <!-- C API usage examples. -->
211
+
212
+ <section class="examples">
213
+
214
+ ### Examples
215
+
216
+ ```c
217
+ #include "stdlib/stats/base/dists/arcsine/pdf.h"
218
+ #include <stdlib.h>
219
+ #include <stdio.h>
220
+
221
+ static double random_uniform( const double min, const double max ) {
222
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
223
+ return min + ( v*(max-min) );
224
+ }
225
+
226
+ int main( void ) {
227
+ double x;
228
+ double a;
229
+ double b;
230
+ double y;
231
+ int i;
232
+
233
+ for ( i = 0; i < 25; i++ ) {
234
+ x = random_uniform( -10.0, 10.0 );
235
+ a = random_uniform( -20.0, 0.0 );
236
+ b = random_uniform( a, a+40.0 );
237
+ y = stdlib_base_dists_arcsine_pdf( x, a, b );
238
+ printf( "x: %lf, a: %lf, b: %lf, f(x;a,b): %lf\n", x, a, b, y );
239
+ }
152
240
  }
153
241
  ```
154
242
 
@@ -156,6 +244,18 @@ for ( i = 0; i < 25; i++ ) {
156
244
 
157
245
  <!-- /.examples -->
158
246
 
247
+ </section>
248
+
249
+ <!-- /.c -->
250
+
251
+ <!-- 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. -->
252
+
253
+ <section class="references">
254
+
255
+ </section>
256
+
257
+ <!-- /.references -->
258
+
159
259
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
160
260
 
161
261
  <section class="related">
@@ -190,7 +290,7 @@ See [LICENSE][stdlib-license].
190
290
 
191
291
  ## Copyright
192
292
 
193
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
293
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
194
294
 
195
295
  </section>
196
296
 
@@ -203,8 +303,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
203
303
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-arcsine-pdf.svg
204
304
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-arcsine-pdf
205
305
 
206
- [test-image]: https://github.com/stdlib-js/stats-base-dists-arcsine-pdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
207
- [test-url]: https://github.com/stdlib-js/stats-base-dists-arcsine-pdf/actions/workflows/test.yml?query=branch:v0.2.2
306
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-arcsine-pdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
307
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-arcsine-pdf/actions/workflows/test.yml?query=branch:v0.3.0
208
308
 
209
309
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-arcsine-pdf/main.svg
210
310
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-arcsine-pdf?branch=main
@@ -216,8 +316,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
216
316
 
217
317
  -->
218
318
 
219
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
220
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
319
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
320
+ [chat-url]: https://stdlib.zulipchat.com
221
321
 
222
322
  [stdlib]: https://github.com/stdlib-js/stdlib
223
323
 
@@ -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_ARCSINE_PDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_ARCSINE_PDF_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 probability density function (PDF) for an arcsine distribution with minimum support `a` and maximum support `b` at a value `x`.
31
+ */
32
+ double stdlib_base_dists_arcsine_pdf( const double x, const double a, const double b );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_ARCSINE_PDF_H
package/lib/native.js ADDED
@@ -0,0 +1,72 @@
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 probability density function (PDF) for an arcsine distribution with minimum support `a` and maximum support `b` at a value `x`.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {number} a - minimum support
34
+ * @param {number} b - maximum support
35
+ * @returns {number} evaluated PDF
36
+ *
37
+ * @example
38
+ * var y = pdf( 2.0, 0.0, 4.0 );
39
+ * // returns ~0.159
40
+ *
41
+ * @example
42
+ * var y = pdf( 5.0, 0.0, 4.0 );
43
+ * // returns 0.0
44
+ *
45
+ * @example
46
+ * var y = pdf( 0.25, 0.0, 1.0 );
47
+ * // returns ~0.735
48
+ *
49
+ * @example
50
+ * var y = pdf( NaN, 0.0, 1.0 );
51
+ * // returns NaN
52
+ *
53
+ * @example
54
+ * var y = pdf( 0.0, NaN, 1.0 );
55
+ * // returns NaN
56
+ *
57
+ * @example
58
+ * var y = pdf( 0.0, 0.0, NaN );
59
+ * // returns NaN
60
+ *
61
+ * @example
62
+ * var y = pdf( 2.0, 3.0, 1.0 );
63
+ * // returns NaN
64
+ */
65
+ function pdf( x, a, b ) {
66
+ return addon( x, a, b );
67
+ }
68
+
69
+
70
+ // EXPORTS //
71
+
72
+ module.exports = pdf;
package/manifest.json ADDED
@@ -0,0 +1,82 @@
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-sqrt",
44
+ "@stdlib/constants-float64-pi"
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-sqrt",
61
+ "@stdlib/constants-float64-pi"
62
+ ]
63
+ },
64
+ {
65
+ "task": "examples",
66
+ "wasm": false,
67
+ "src": [
68
+ "./src/main.c"
69
+ ],
70
+ "include": [
71
+ "./include"
72
+ ],
73
+ "libraries": [],
74
+ "libpath": [],
75
+ "dependencies": [
76
+ "@stdlib/math-base-assert-is-nan",
77
+ "@stdlib/math-base-special-sqrt",
78
+ "@stdlib/constants-float64-pi"
79
+ ]
80
+ }
81
+ ]
82
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-arcsine-pdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Arcsine distribution probability density function (PDF).",
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",
@@ -32,9 +35,11 @@
32
35
  "dependencies": {
33
36
  "@stdlib/constants-float64-pi": "^0.2.2",
34
37
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
35
- "@stdlib/math-base-special-sqrt": "^0.2.1",
38
+ "@stdlib/math-base-napi-ternary": "^0.3.1",
39
+ "@stdlib/math-base-special-sqrt": "^0.2.2",
36
40
  "@stdlib/utils-constant-function": "^0.2.2",
37
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
41
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
42
+ "@stdlib/utils-library-manifest": "^0.2.3"
38
43
  },
39
44
  "devDependencies": {},
40
45
  "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/arcsine/pdf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_arcsine_pdf )
package/src/main.c ADDED
@@ -0,0 +1,49 @@
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/arcsine/pdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/sqrt.h"
22
+ #include "stdlib/constants/float64/pi.h"
23
+
24
+ /**
25
+ * Evaluates the probability density function (PDF) for an arcsine distribution with minimum support `a` and maximum support `b` at a value `x`.
26
+ *
27
+ * @param x input value
28
+ * @param a minimum support
29
+ * @param b maximum support
30
+ * @return evaluated PDF
31
+ *
32
+ * @example
33
+ * double y = stdlib_base_dists_arcsine_pdf( 2.0, 0.0, 4.0 );
34
+ * // returns ~0.159
35
+ */
36
+ double stdlib_base_dists_arcsine_pdf( const double x, const double a, const double b ) {
37
+ if (
38
+ stdlib_base_is_nan( x ) ||
39
+ stdlib_base_is_nan( a ) ||
40
+ stdlib_base_is_nan( b ) ||
41
+ a >= b
42
+ ) {
43
+ return 0.0/0.0; // NaN
44
+ }
45
+ if ( x < a || x > b ) {
46
+ return 0.0;
47
+ }
48
+ return 1.0 / ( STDLIB_CONSTANT_FLOAT64_PI * stdlib_base_sqrt( ( x-a ) * ( b-x ) ) );
49
+ }