@stdlib/stats-base-dists-laplace-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 +1 -1
- package/README.md +112 -18
- package/include/stdlib/stats/base/dists/laplace/cdf.h +38 -0
- package/lib/native.js +69 -0
- package/manifest.json +80 -0
- package/package.json +7 -2
- package/src/addon.c +22 -0
- package/src/main.c +50 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -132,21 +132,111 @@ y = mycdf( 4.0 );
|
|
|
132
132
|
<!-- eslint no-undef: "error" -->
|
|
133
133
|
|
|
134
134
|
```javascript
|
|
135
|
-
var
|
|
135
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
136
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
136
137
|
var cdf = require( '@stdlib/stats-base-dists-laplace-cdf' );
|
|
137
138
|
|
|
138
|
-
var
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
var
|
|
142
|
-
var
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
139
|
+
var opts = {
|
|
140
|
+
'dtype': 'float64'
|
|
141
|
+
};
|
|
142
|
+
var x = uniform( 100, 0.0, 10.0, opts );
|
|
143
|
+
var mu = uniform( 100, 0.0, 10.0, opts );
|
|
144
|
+
var b = uniform( 100, 0.0, 10.0, opts );
|
|
145
|
+
|
|
146
|
+
logEachMap( 'x: %04f, µ: %04f, b: %04f, F(x;µ,b): %04f', x, mu, b, cdf );
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
</section>
|
|
150
|
+
|
|
151
|
+
<!-- /.examples -->
|
|
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/laplace/cdf.h"
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### stdlib_base_dists_laplace_cdf( x, mu, b )
|
|
180
|
+
|
|
181
|
+
Evaluates the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a value `x`.
|
|
182
|
+
|
|
183
|
+
```c
|
|
184
|
+
double out = stdlib_base_dists_laplace_cdf( 2.0, 0.0, 1.0 );
|
|
185
|
+
// returns ~0.932
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
The function accepts the following arguments:
|
|
189
|
+
|
|
190
|
+
- **p**: `[in] double` input value.
|
|
191
|
+
- **mu**: `[in] double` location parameter.
|
|
192
|
+
- **b**: `[in] double` rate parameter.
|
|
193
|
+
|
|
194
|
+
```c
|
|
195
|
+
double stdlib_base_dists_laplace_cdf( const double x, const double mu, 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/laplace/cdf.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 mu;
|
|
228
|
+
double b;
|
|
229
|
+
double x;
|
|
230
|
+
double y;
|
|
231
|
+
int i;
|
|
232
|
+
|
|
233
|
+
for ( i = 0; i < 25; i++ ) {
|
|
234
|
+
mu = random_uniform( -5.0, 5.0 );
|
|
235
|
+
b = random_uniform( 0.0, 20.0 );
|
|
236
|
+
x = random_uniform( 0.0, 1.0 );
|
|
237
|
+
y = stdlib_base_dists_laplace_cdf( x, mu, b );
|
|
238
|
+
printf( "x: %lf, µ: %lf, b: %lf, F(x;µ,b): %lf\n", x, mu, b, y );
|
|
239
|
+
}
|
|
150
240
|
}
|
|
151
241
|
```
|
|
152
242
|
|
|
@@ -154,6 +244,10 @@ for ( i = 0; i < 100; i++ ) {
|
|
|
154
244
|
|
|
155
245
|
<!-- /.examples -->
|
|
156
246
|
|
|
247
|
+
</section>
|
|
248
|
+
|
|
249
|
+
<!-- /.c -->
|
|
250
|
+
|
|
157
251
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
158
252
|
|
|
159
253
|
<section class="related">
|
|
@@ -188,7 +282,7 @@ See [LICENSE][stdlib-license].
|
|
|
188
282
|
|
|
189
283
|
## Copyright
|
|
190
284
|
|
|
191
|
-
Copyright © 2016-
|
|
285
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
192
286
|
|
|
193
287
|
</section>
|
|
194
288
|
|
|
@@ -201,8 +295,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
201
295
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-laplace-cdf.svg
|
|
202
296
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-laplace-cdf
|
|
203
297
|
|
|
204
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-laplace-cdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
205
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-laplace-cdf/actions/workflows/test.yml?query=branch:v0.
|
|
298
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-laplace-cdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
299
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-laplace-cdf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
206
300
|
|
|
207
301
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-laplace-cdf/main.svg
|
|
208
302
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-laplace-cdf?branch=main
|
|
@@ -214,8 +308,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
214
308
|
|
|
215
309
|
-->
|
|
216
310
|
|
|
217
|
-
[chat-image]: https://img.shields.io/
|
|
218
|
-
[chat-url]: https://
|
|
311
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
312
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
219
313
|
|
|
220
314
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
221
315
|
|
|
@@ -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_LAPLACE_CDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_LAPLACE_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 Laplace distribution with location parameter `mu` and scale parameter `b` at a value `x`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_laplace_cdf( const double x, const double mu, const double b );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_LAPLACE_CDF_H
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
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 Laplace distribution with location parameter `mu` and scale parameter `b` at value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {number} mu - location parameter
|
|
34
|
+
* @param {PositiveNumber} b - scale parameter
|
|
35
|
+
* @returns {Probability} evaluated CDF
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var y = cdf( 2.0, 0.0, 1.0 );
|
|
39
|
+
* // returns ~0.932
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var y = cdf( 5.0, 10.0, 3.0 );
|
|
43
|
+
* // returns ~0.094
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = cdf( NaN, 0.0, 1.0 );
|
|
47
|
+
* // returns NaN
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var y = cdf( 2, NaN, 1.0 );
|
|
51
|
+
* // returns NaN
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var y = cdf( 2.0, 0.0, NaN );
|
|
55
|
+
* // returns NaN
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* // Negative scale parameter:
|
|
59
|
+
* var y = cdf( 2.0, 0.0, -1.0 );
|
|
60
|
+
* // returns NaN
|
|
61
|
+
*/
|
|
62
|
+
function cdf( x, mu, b ) {
|
|
63
|
+
return addon( x, mu, b );
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// EXPORTS //
|
|
68
|
+
|
|
69
|
+
module.exports = cdf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
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-exp"
|
|
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/constants-float64-eps",
|
|
60
|
+
"@stdlib/math-base-special-exp"
|
|
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-exp"
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-laplace-cdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Laplace 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-exp": "^0.2.4",
|
|
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/laplace/cdf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/ternary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_laplace_cdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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/laplace/cdf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/exp.h"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Evaluates the cumulative distribution function (CDF) for a Laplace distribution with location parameter `mu` and scale parameter `b` at a value `x`.
|
|
25
|
+
*
|
|
26
|
+
* @param x input value
|
|
27
|
+
* @param mu location parameter
|
|
28
|
+
* @param b scale parameter
|
|
29
|
+
* @return evaluated CDF
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* double y = stdlib_base_dists_laplace_cdf( 2.0, 0.0, 1.0 );
|
|
33
|
+
* // returns ~0.932
|
|
34
|
+
*/
|
|
35
|
+
double stdlib_base_dists_laplace_cdf( const double x, const double mu, const double b ) {
|
|
36
|
+
double z;
|
|
37
|
+
if (
|
|
38
|
+
stdlib_base_is_nan( x ) ||
|
|
39
|
+
stdlib_base_is_nan( mu ) ||
|
|
40
|
+
stdlib_base_is_nan( b ) ||
|
|
41
|
+
b <= 0.0
|
|
42
|
+
) {
|
|
43
|
+
return 0.0/0.0; // NaN
|
|
44
|
+
}
|
|
45
|
+
z = ( x - mu ) / b;
|
|
46
|
+
if ( x < mu ) {
|
|
47
|
+
return 0.5 * stdlib_base_exp( z );
|
|
48
|
+
}
|
|
49
|
+
return 1.0 - ( 0.5 * stdlib_base_exp( -z ) );
|
|
50
|
+
}
|