@stdlib/stats-base-dists-logistic-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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -145,21 +145,111 @@ y = mycdf( 8.0 );
145
145
  <!-- eslint no-undef: "error" -->
146
146
 
147
147
  ```javascript
148
- var randu = require( '@stdlib/random-base-randu' );
148
+ var uniform = require( '@stdlib/random-array-uniform' );
149
+ var logEachMap = require( '@stdlib/console-log-each-map' );
149
150
  var cdf = require( '@stdlib/stats-base-dists-logistic-cdf' );
150
151
 
151
- var mu;
152
- var s;
153
- var x;
154
- var y;
155
- var i;
156
-
157
- for ( i = 0; i < 10; i++ ) {
158
- x = randu() * 10.0;
159
- mu = randu() * 10.0;
160
- s = randu() * 10.0;
161
- y = cdf( x, mu, s );
162
- console.log( 'x: %d, µ: %d, s: %d, F(x;µ,s): %d', x, mu, s, y );
152
+ var opts = {
153
+ 'dtype': 'float64'
154
+ };
155
+ var x = uniform( 10, 0.0, 10.0, opts );
156
+ var mu = uniform( 10, 0.0, 10.0, opts );
157
+ var s = uniform( 10, 0.0, 10.0, opts );
158
+
159
+ logEachMap( 'x: %0.4f, µ: %0.4f, s: %0.4f, F(x;µ,s): %0.4f', x, mu, s, cdf );
160
+ ```
161
+
162
+ </section>
163
+
164
+ <!-- /.examples -->
165
+
166
+ <!-- C interface documentation. -->
167
+
168
+ * * *
169
+
170
+ <section class="c">
171
+
172
+ ## C APIs
173
+
174
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
175
+
176
+ <section class="intro">
177
+
178
+ </section>
179
+
180
+ <!-- /.intro -->
181
+
182
+ <!-- C usage documentation. -->
183
+
184
+ <section class="usage">
185
+
186
+ ### Usage
187
+
188
+ ```c
189
+ #include "stdlib/stats/base/dists/logistic/cdf.h"
190
+ ```
191
+
192
+ #### stdlib_base_dists_logistic_cdf( x, mu, s )
193
+
194
+ Evaluates the [cumulative distribution function][cdf] (CDF) for a [logistic][logistic-distribution] distribution with parameters `mu` (location parameter) and `s` (scale parameter).
195
+
196
+ ```c
197
+ double out = stdlib_base_dists_logistic_cdf( 2.0, 0.0, 1.0 );
198
+ // returns ~0.881
199
+ ```
200
+
201
+ The function accepts the following arguments:
202
+
203
+ - **x**: `[in] double` value parameter.
204
+ - **mu**: `[in] double` location parameter.
205
+ - **s**: `[in] double` scale parameter.
206
+
207
+ ```c
208
+ double stdlib_base_dists_logistic_cdf( const double x, const double mu, const double s );
209
+ ```
210
+
211
+ </section>
212
+
213
+ <!-- /.usage -->
214
+
215
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
216
+
217
+ <section class="notes">
218
+
219
+ </section>
220
+
221
+ <!-- /.notes -->
222
+
223
+ <!-- C API usage examples. -->
224
+
225
+ <section class="examples">
226
+
227
+ ### Examples
228
+
229
+ ```c
230
+ #include "stdlib/stats/base/dists/logistic/cdf.h"
231
+ #include <stdlib.h>
232
+ #include <stdio.h>
233
+
234
+ static double random_uniform( const double min, const double max ) {
235
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
236
+ return min + ( v*(max-min) );
237
+ }
238
+
239
+ int main( void ) {
240
+ double mu;
241
+ double s;
242
+ double x;
243
+ double y;
244
+ int i;
245
+
246
+ for ( i = 0; i < 25; i++ ) {
247
+ mu = random_uniform( 0.0, 10.0 );
248
+ s = random_uniform( 0.0, 10.0 );
249
+ x = random_uniform( 0.0, 10.0 );
250
+ y = stdlib_base_dists_logistic_cdf( x, mu, s );
251
+ printf( "x: %lf, µ: %lf, s: %lf, F(x;µ,s): %lf\n", x, mu, s, y );
252
+ }
163
253
  }
164
254
  ```
165
255
 
@@ -167,6 +257,10 @@ for ( i = 0; i < 10; i++ ) {
167
257
 
168
258
  <!-- /.examples -->
169
259
 
260
+ </section>
261
+
262
+ <!-- /.c -->
263
+
170
264
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
171
265
 
172
266
  <section class="related">
@@ -201,7 +295,7 @@ See [LICENSE][stdlib-license].
201
295
 
202
296
  ## Copyright
203
297
 
204
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
298
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
205
299
 
206
300
  </section>
207
301
 
@@ -214,8 +308,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
214
308
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-logistic-cdf.svg
215
309
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-logistic-cdf
216
310
 
217
- [test-image]: https://github.com/stdlib-js/stats-base-dists-logistic-cdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
218
- [test-url]: https://github.com/stdlib-js/stats-base-dists-logistic-cdf/actions/workflows/test.yml?query=branch:v0.2.2
311
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-logistic-cdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
312
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-logistic-cdf/actions/workflows/test.yml?query=branch:v0.3.0
219
313
 
220
314
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-logistic-cdf/main.svg
221
315
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-logistic-cdf?branch=main
@@ -227,8 +321,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
227
321
 
228
322
  -->
229
323
 
230
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
231
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
324
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
325
+ [chat-url]: https://stdlib.zulipchat.com
232
326
 
233
327
  [stdlib]: https://github.com/stdlib-js/stdlib
234
328
 
@@ -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_LOGISTIC_CDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_LOGISTIC_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 logistic distribution with location parameter `mu` and scale parameter `s` at a value `x`.
31
+ */
32
+ double stdlib_base_dists_logistic_cdf( const double x, const double mu, const double s );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_LOGISTIC_CDF_H
package/lib/native.js ADDED
@@ -0,0 +1,63 @@
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 logistic distribution with location parameter `mu` and scale parameter `s` at a value `x`.
30
+ *
31
+ * @param {number} x - input value
32
+ * @param {number} mu - location parameter
33
+ * @param {NonNegativeNumber} s - scale parameter
34
+ * @returns {Probability} evaluated CDF
35
+ *
36
+ * @example
37
+ * var y = cdf( 2.0, 0.0, 1.0 );
38
+ * // returns ~0.881
39
+ *
40
+ * @example
41
+ * var y = cdf( 5.0, 10.0, 3.0 );
42
+ * // returns ~0.159
43
+ *
44
+ * @example
45
+ * var y = cdf( 2.0, 0.0, NaN );
46
+ * // returns NaN
47
+ *
48
+ * @example
49
+ * var y = cdf( 2.0, NaN, 1.0 );
50
+ * // returns NaN
51
+ *
52
+ * @example
53
+ * var y = cdf( NaN, 0.0, 1.0 );
54
+ * // returns NaN
55
+ */
56
+ function cdf( x, mu, s ) {
57
+ return addon( x, mu, s );
58
+ }
59
+
60
+
61
+ // EXPORTS //
62
+
63
+ 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-special-exp",
43
+ "@stdlib/math-base-assert-is-nan"
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-logistic-cdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Logistic 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,10 +34,12 @@
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
- "@stdlib/stats-base-dists-degenerate-cdf": "^0.2.2",
39
+ "@stdlib/stats-base-dists-degenerate-cdf": "^0.3.0",
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,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/logistic/cdf.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_logistic_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/logistic/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 logistic distribution with location parameter `mu` and scale parameter `s` at a value `x`.
25
+ *
26
+ * @param x input value
27
+ * @param mu location parameter
28
+ * @param s scale parameter
29
+ * @return evaluated CDF
30
+ *
31
+ * @example
32
+ * double y = stdlib_base_dists_logistic_cdf( 2.0, 0.0, 1.0 );
33
+ * // returns ~0.881
34
+ */
35
+ double stdlib_base_dists_logistic_cdf( const double x, const double mu, const double s ) {
36
+ double z;
37
+ if (
38
+ stdlib_base_is_nan( x ) ||
39
+ stdlib_base_is_nan( mu ) ||
40
+ stdlib_base_is_nan( s ) ||
41
+ s < 0.0
42
+ ) {
43
+ return 0.0 / 0.0; // NaN
44
+ }
45
+ if ( s == 0.0 ) {
46
+ return ( x < mu ) ? 0.0 : 1.0;
47
+ }
48
+ z = ( x - mu ) / s;
49
+ return 1.0 / ( 1.0 + stdlib_base_exp( -z ) );
50
+ }