@stdlib/stats-base-dists-logistic-entropy 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
@@ -130,19 +130,107 @@ y = entropy( 0.0, -1.0 );
130
130
  <!-- eslint no-undef: "error" -->
131
131
 
132
132
  ```javascript
133
- var randu = require( '@stdlib/random-base-randu' );
133
+ var uniform = require( '@stdlib/random-array-uniform' );
134
+ var logEachMap = require( '@stdlib/console-log-each-map' );
134
135
  var entropy = require( '@stdlib/stats-base-dists-logistic-entropy' );
135
136
 
136
- var mu;
137
- var s;
138
- var y;
139
- var i;
137
+ var opts = {
138
+ 'dtype': 'float64'
139
+ };
140
+ var mu = uniform( 10, -5.0, 5.0, opts );
141
+ var s = uniform( 10, 0.0, 20.0, opts );
140
142
 
141
- for ( i = 0; i < 10; i++ ) {
142
- mu = ( randu()*10.0 ) - 5.0;
143
- s = randu() * 20.0;
144
- y = entropy( mu, s );
145
- console.log( 'µ: %d, s: %d, h(X;µ,s): %d', mu.toFixed( 4 ), s.toFixed( 4 ), y.toFixed( 4 ) );
143
+ logEachMap( 'µ: %0.4f, s: %0.4f, h(X;µ,s): %0.4f', mu, s, entropy );
144
+ ```
145
+
146
+ </section>
147
+
148
+ <!-- /.examples -->
149
+
150
+ <!-- C interface documentation. -->
151
+
152
+ * * *
153
+
154
+ <section class="c">
155
+
156
+ ## C APIs
157
+
158
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
159
+
160
+ <section class="intro">
161
+
162
+ </section>
163
+
164
+ <!-- /.intro -->
165
+
166
+ <!-- C usage documentation. -->
167
+
168
+ <section class="usage">
169
+
170
+ ### Usage
171
+
172
+ ```c
173
+ #include "stdlib/stats/base/dists/logistic/entropy.h"
174
+ ```
175
+
176
+ #### stdlib_base_dists_logistic_entropy( mu, s )
177
+
178
+ Returns the differential entropy for a logistic distribution with location `mu` and scale `s`.
179
+
180
+ ```c
181
+ double out = stdlib_base_dists_logistic_entropy( 0.0, 1.0 );
182
+ // returns 2.0
183
+ ```
184
+
185
+ The function accepts the following arguments:
186
+
187
+ - **mu**: `[in] double` location parameter.
188
+ - **s**: `[in] double` scale parameter.
189
+
190
+ ```c
191
+ double stdlib_base_dists_logistic_entropy( const double mu, const double s );
192
+ ```
193
+
194
+ </section>
195
+
196
+ <!-- /.usage -->
197
+
198
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
199
+
200
+ <section class="notes">
201
+
202
+ </section>
203
+
204
+ <!-- /.notes -->
205
+
206
+ <!-- C API usage examples. -->
207
+
208
+ <section class="examples">
209
+
210
+ ### Examples
211
+
212
+ ```c
213
+ #include "stdlib/stats/base/dists/logistic/entropy.h"
214
+ #include <stdlib.h>
215
+ #include <stdio.h>
216
+
217
+ static double random_uniform( const double min, const double max ) {
218
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
219
+ return min + ( v*(max-min) );
220
+ }
221
+
222
+ int main( void ) {
223
+ double mu;
224
+ double s;
225
+ double y;
226
+ int i;
227
+
228
+ for ( i = 0; i < 25; i++ ) {
229
+ mu = random_uniform( -5.0, 5.0 );
230
+ s = random_uniform( 0.0, 20.0 );
231
+ y = stdlib_base_dists_logistic_entropy( mu, s );
232
+ printf( "µ: %lf, s: %lf, h(X;µ,s): %lf\n", mu, s, y );
233
+ }
146
234
  }
147
235
  ```
148
236
 
@@ -150,6 +238,10 @@ for ( i = 0; i < 10; i++ ) {
150
238
 
151
239
  <!-- /.examples -->
152
240
 
241
+ </section>
242
+
243
+ <!-- /.c -->
244
+
153
245
  <!-- 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. -->
154
246
 
155
247
  <section class="references">
@@ -192,7 +284,7 @@ See [LICENSE][stdlib-license].
192
284
 
193
285
  ## Copyright
194
286
 
195
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
287
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
196
288
 
197
289
  </section>
198
290
 
@@ -205,8 +297,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
205
297
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-logistic-entropy.svg
206
298
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-logistic-entropy
207
299
 
208
- [test-image]: https://github.com/stdlib-js/stats-base-dists-logistic-entropy/actions/workflows/test.yml/badge.svg?branch=v0.2.1
209
- [test-url]: https://github.com/stdlib-js/stats-base-dists-logistic-entropy/actions/workflows/test.yml?query=branch:v0.2.1
300
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-logistic-entropy/actions/workflows/test.yml/badge.svg?branch=v0.3.0
301
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-logistic-entropy/actions/workflows/test.yml?query=branch:v0.3.0
210
302
 
211
303
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-logistic-entropy/main.svg
212
304
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-logistic-entropy?branch=main
@@ -218,8 +310,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
218
310
 
219
311
  -->
220
312
 
221
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
222
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
313
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
314
+ [chat-url]: https://stdlib.zulipchat.com
223
315
 
224
316
  [stdlib]: https://github.com/stdlib-js/stdlib
225
317
 
@@ -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_ENTROPY_H
20
+ #define STDLIB_STATS_BASE_DISTS_LOGISTIC_ENTROPY_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 differential entropy for a logistic distribution with location `mu` and scale `s`.
31
+ */
32
+ double stdlib_base_dists_logistic_entropy( const double mu, const double s );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_LOGISTIC_ENTROPY_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
+ * Returns the differential entropy for a logistic distribution with location `mu` and scale `s`.
30
+ *
31
+ * @private
32
+ * @param {number} mu - location parameter
33
+ * @param {PositiveNumber} s - scale parameter
34
+ * @returns {number} entropy
35
+ *
36
+ * @example
37
+ * var y = entropy( 0.0, 1.0 );
38
+ * // returns 2.0
39
+ *
40
+ * @example
41
+ * var y = entropy( 5.0, 2.0 );
42
+ * // returns ~2.693
43
+ *
44
+ * @example
45
+ * var y = entropy( NaN, 1.0 );
46
+ * // returns NaN
47
+ *
48
+ * @example
49
+ * var y = entropy( 0.0, NaN );
50
+ * // returns NaN
51
+ *
52
+ * @example
53
+ * var y = entropy( 0.0, 0.0 );
54
+ * // returns NaN
55
+ */
56
+ function entropy( mu, s ) {
57
+ return addon( mu, s );
58
+ }
59
+
60
+
61
+ // EXPORTS //
62
+
63
+ module.exports = entropy;
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/math-base-special-ln"
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-ln"
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-ln"
77
+ ]
78
+ }
79
+ ]
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-logistic-entropy",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Logistic distribution entropy.",
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,8 +33,10 @@
30
33
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
34
  },
32
35
  "dependencies": {
33
- "@stdlib/math-base-assert-is-nan": "^0.2.1",
34
- "@stdlib/math-base-special-ln": "^0.2.1"
36
+ "@stdlib/math-base-assert-is-nan": "^0.2.2",
37
+ "@stdlib/math-base-napi-binary": "^0.3.1",
38
+ "@stdlib/math-base-special-ln": "^0.2.4",
39
+ "@stdlib/utils-library-manifest": "^0.2.3"
35
40
  },
36
41
  "devDependencies": {},
37
42
  "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/entropy.h"
20
+ #include "stdlib/math/base/napi/binary.h"
21
+
22
+ // cppcheck-suppress shadowFunction
23
+ STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_logistic_entropy )
package/src/main.c ADDED
@@ -0,0 +1,43 @@
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/entropy.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/ln.h"
22
+
23
+ /**
24
+ * Returns the differential entropy for a logistic distribution with location `mu` and scale `s`.
25
+ *
26
+ * @param mu location parameter
27
+ * @param s scale parameter
28
+ * @return entropy
29
+ *
30
+ * @example
31
+ * double y = stdlib_base_dists_logistic_entropy( 0.0, 1.0 );
32
+ * // returns 2.0
33
+ */
34
+ double stdlib_base_dists_logistic_entropy( const double mu, const double s ) {
35
+ if (
36
+ stdlib_base_is_nan( mu ) ||
37
+ stdlib_base_is_nan( s ) ||
38
+ s <= 0.0
39
+ ) {
40
+ return 0.0 / 0.0; // NaN
41
+ }
42
+ return stdlib_base_ln( s ) + 2.0;
43
+ }