@stdlib/stats-base-dists-degenerate-logcdf 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 CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -112,20 +112,108 @@ y = mylogcdf( 8.0 );
112
112
  <!-- eslint no-undef: "error" -->
113
113
 
114
114
  ```javascript
115
- var randu = require( '@stdlib/random-base-randu' );
116
- var round = require( '@stdlib/math-base-special-round' );
115
+ var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
116
+ var logEachMap = require( '@stdlib/console-log-each-map' );
117
117
  var logcdf = require( '@stdlib/stats-base-dists-degenerate-logcdf' );
118
118
 
119
- var mu;
120
- var x;
121
- var y;
122
- var i;
119
+ var opts = {
120
+ 'dtype': 'float64'
121
+ };
122
+ var x = discreteUniform( 10, 0, 10, opts );
123
+ var mu = discreteUniform( 10, 0, 10, opts );
123
124
 
124
- for ( i = 0; i < 100; i++ ) {
125
- x = round( randu()*10.0 );
126
- mu = round( randu()*10.0 );
127
- y = logcdf( x, mu );
128
- console.log( 'x: %d, µ: %d, ln(F(x;µ)): %d', x, mu, y );
125
+ logEachMap( 'x: %d, µ: %d, ln(F(x;µ)): %0.4f', x, mu, logcdf );
126
+ ```
127
+
128
+ </section>
129
+
130
+ <!-- /.examples -->
131
+
132
+ <!-- C interface documentation. -->
133
+
134
+ * * *
135
+
136
+ <section class="c">
137
+
138
+ ## C APIs
139
+
140
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
141
+
142
+ <section class="intro">
143
+
144
+ </section>
145
+
146
+ <!-- /.intro -->
147
+
148
+ <!-- C usage documentation. -->
149
+
150
+ <section class="usage">
151
+
152
+ ### Usage
153
+
154
+ ```c
155
+ #include "stdlib/stats/base/dists/degenerate/logcdf.h"
156
+ ```
157
+
158
+ #### stdlib_base_dists_degenerate_logcdf( x, mu )
159
+
160
+ Evaluates the natural logarithm of the [CDF][cdf] of a [degenerate distribution][degenerate-distribution] centered at `mu`.
161
+
162
+ ```c
163
+ double y = stdlib_base_dists_degenerate_logcdf( 2.0, 3.0 );
164
+ // returns -Infinity
165
+ ```
166
+
167
+ The function accepts the following arguments:
168
+
169
+ - **x**: `[in] double` input value.
170
+ - **mu**: `[in] double` constant value of distribution.
171
+
172
+ ```c
173
+ double stdlib_base_dists_degenerate_logcdf( const double x, const double mu );
174
+ ```
175
+
176
+ </section>
177
+
178
+ <!-- /.usage -->
179
+
180
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
181
+
182
+ <section class="notes">
183
+
184
+ </section>
185
+
186
+ <!-- /.notes -->
187
+
188
+ <!-- C API usage examples. -->
189
+
190
+ <section class="examples">
191
+
192
+ ### Examples
193
+
194
+ ```c
195
+ #include "stdlib/stats/base/dists/degenerate/logcdf.h"
196
+ #include "stdlib/math/base/special/round.h"
197
+ #include <stdlib.h>
198
+ #include <stdio.h>
199
+
200
+ static double random_uniform( const double min, const double max ) {
201
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
202
+ return min + ( v*(max-min) );
203
+ }
204
+
205
+ int main( void ) {
206
+ double mu;
207
+ double x;
208
+ double y;
209
+ int i;
210
+
211
+ for ( i = 0; i < 10; i++ ) {
212
+ x = stdlib_base_round( random_uniform( 0.0, 10.0 ) );
213
+ mu = stdlib_base_round( random_uniform( 0.0, 10.0 ) );
214
+ y = stdlib_base_dists_degenerate_logcdf( x, mu );
215
+ printf( "x: %lf, µ: %lf, ln(F(x;µ)): %lf\n", x, mu, y );
216
+ }
129
217
  }
130
218
  ```
131
219
 
@@ -133,6 +221,10 @@ for ( i = 0; i < 100; i++ ) {
133
221
 
134
222
  <!-- /.examples -->
135
223
 
224
+ </section>
225
+
226
+ <!-- /.c -->
227
+
136
228
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
137
229
 
138
230
  <section class="related">
@@ -167,7 +259,7 @@ See [LICENSE][stdlib-license].
167
259
 
168
260
  ## Copyright
169
261
 
170
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
262
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
171
263
 
172
264
  </section>
173
265
 
@@ -180,8 +272,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
180
272
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-degenerate-logcdf.svg
181
273
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-degenerate-logcdf
182
274
 
183
- [test-image]: https://github.com/stdlib-js/stats-base-dists-degenerate-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.2.1
184
- [test-url]: https://github.com/stdlib-js/stats-base-dists-degenerate-logcdf/actions/workflows/test.yml?query=branch:v0.2.1
275
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-degenerate-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
276
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-degenerate-logcdf/actions/workflows/test.yml?query=branch:v0.3.0
185
277
 
186
278
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-degenerate-logcdf/main.svg
187
279
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-degenerate-logcdf?branch=main
@@ -193,8 +285,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
193
285
 
194
286
  -->
195
287
 
196
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
197
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
288
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
289
+ [chat-url]: https://stdlib.zulipchat.com
198
290
 
199
291
  [stdlib]: https://github.com/stdlib-js/stdlib
200
292
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /// <reference path="../docs/types/index.d.ts" />
2
- import logCDF from '../docs/types/index';
3
- export = logCDF;
2
+ import logcdf from '../docs/types/index';
3
+ export = logcdf;
@@ -99,9 +99,9 @@ interface LogCDF {
99
99
  * y = mylogcdf( 6.0 );
100
100
  * // returns 0.0
101
101
  */
102
- declare var logCDF: LogCDF;
102
+ declare var logcdf: LogCDF;
103
103
 
104
104
 
105
105
  // EXPORTS //
106
106
 
107
- export = logCDF;
107
+ export = logcdf;
@@ -0,0 +1,39 @@
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_DEGENERATE_LOGCDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_DEGENERATE_LOGCDF_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
+
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+ /**
31
+ * Evaluates the natural logarithm of the (CDF) of a degenerate distribution centered at `mu`.
32
+ */
33
+ double stdlib_base_dists_degenerate_logcdf( const double x, const double mu );
34
+
35
+ #ifdef __cplusplus
36
+ }
37
+ #endif
38
+
39
+ #endif // !STDLIB_STATS_BASE_DISTS_DEGENERATE_LOGCDF_H
package/lib/native.js 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
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var addon = require( './../src/addon.node' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Evaluates the natural logarithm of the cumulative distribution function (logCDF) for a degenerate distribution with mean `mu`.
30
+ *
31
+ * @private
32
+ * @param {number} x - input value
33
+ * @param {number} mu - constant value of distribution
34
+ * @returns {number} natural logarithm of cumulative distribution function
35
+ *
36
+ * @example
37
+ * var y = logcdf( 2.0, 3.0 );
38
+ * // returns -Infinity
39
+ */
40
+ function logcdf( x, mu ) {
41
+ return addon( x, mu );
42
+ }
43
+
44
+
45
+ // EXPORTS //
46
+
47
+ module.exports = logcdf;
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-binary",
42
+ "@stdlib/math-base-assert-is-nan",
43
+ "@stdlib/constants-float64-ninf"
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-ninf"
60
+ ]
61
+ },
62
+ {
63
+ "task": "examples",
64
+ "wasm": false,
65
+ "src": [
66
+ "./src/main.c"
67
+ ],
68
+ "include": [
69
+ "./include"
70
+ ],
71
+ "libraries": [],
72
+ "libpath": [],
73
+ "dependencies": [
74
+ "@stdlib/math-base-assert-is-nan",
75
+ "@stdlib/constants-float64-ninf",
76
+ "@stdlib/math-base-special-round"
77
+ ]
78
+ }
79
+ ]
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-degenerate-logcdf",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Degenerate distribution logarithm of cumulative distribution function (logCDF).",
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,10 +33,12 @@
30
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
34
  },
32
35
  "dependencies": {
33
- "@stdlib/constants-float64-ninf": "^0.2.1",
34
- "@stdlib/math-base-assert-is-nan": "^0.2.1",
35
- "@stdlib/utils-constant-function": "^0.2.1",
36
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1"
36
+ "@stdlib/constants-float64-ninf": "^0.2.2",
37
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
38
+ "@stdlib/math-base-napi-binary": "^0.3.1",
39
+ "@stdlib/utils-constant-function": "^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/degenerate/logcdf.h"
20
+ #include "stdlib/math/base/napi/binary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_degenerate_logcdf )
package/src/main.c ADDED
@@ -0,0 +1,39 @@
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/degenerate/logcdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/constants/float64/ninf.h"
22
+
23
+ /**
24
+ * Evaluates the natural logarithm of the (CDF) of a degenerate distribution centered at `mu`.
25
+ *
26
+ * @param x input value
27
+ * @param mu constant value of distribution
28
+ * @return evaluated logCDF
29
+ *
30
+ * @example
31
+ * double y = stdlib_base_dists_degenerate_logcdf( 2.0, 3.0 );
32
+ * // returns -Infinity
33
+ */
34
+ double stdlib_base_dists_degenerate_logcdf( const double x, const double mu ) {
35
+ if ( stdlib_base_is_nan( x ) || stdlib_base_is_nan( mu ) ) {
36
+ return 0.0 / 0.0;
37
+ }
38
+ return ( x < mu ) ? STDLIB_CONSTANT_FLOAT64_NINF : 0.0;
39
+ }