@stdlib/stats-base-dists-exponential-entropy 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
@@ -116,18 +116,103 @@ var v = entropy( -1.0 );
116
116
  <!-- eslint no-undef: "error" -->
117
117
 
118
118
  ```javascript
119
- var randu = require( '@stdlib/random-base-randu' );
120
- var round = require( '@stdlib/math-base-special-round' );
119
+ var uniform = require( '@stdlib/random-array-uniform' );
120
+ var logEachMap = require( '@stdlib/console-log-each-map' );
121
121
  var entropy = require( '@stdlib/stats-base-dists-exponential-entropy' );
122
122
 
123
- var lambda;
124
- var v;
125
- var i;
123
+ var opts = {
124
+ 'dtype': 'float64'
125
+ };
126
+ var lambda = uniform( 10, 0.0, 20.0, opts );
126
127
 
127
- for ( i = 0; i < 10; i++ ) {
128
- lambda = randu() * 20.0;
129
- v = entropy( lambda );
130
- console.log( 'λ: %d, h(X;λ): %d', lambda.toFixed( 4 ), v.toFixed( 4 ) );
128
+ logEachMap( 'λ: %0.4f, h(X;λ): %0.4f', lambda, entropy );
129
+ ```
130
+
131
+ </section>
132
+
133
+ <!-- /.examples -->
134
+
135
+ <!-- C interface documentation. -->
136
+
137
+ * * *
138
+
139
+ <section class="c">
140
+
141
+ ## C APIs
142
+
143
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
144
+
145
+ <section class="intro">
146
+
147
+ </section>
148
+
149
+ <!-- /.intro -->
150
+
151
+ <!-- C usage documentation. -->
152
+
153
+ <section class="usage">
154
+
155
+ ### Usage
156
+
157
+ ```c
158
+ #include "stdlib/stats/base/dists/exponential/entropy.h"
159
+ ```
160
+
161
+ #### stdlib_base_dists_exponential_entropy( lambda )
162
+
163
+ Returns the [differential entropy][entropy] of an [exponential][exponential-distribution] distribution with rate parameter `lambda` (in [nats][nats]).
164
+
165
+ ```c
166
+ double out = stdlib_base_dists_exponential_entropy( 9.0 );
167
+ // returns ~-1.197
168
+ ```
169
+
170
+ The function accepts the following arguments:
171
+
172
+ - **lambda**: `[in] double` rate parameter.
173
+
174
+ ```c
175
+ double stdlib_base_dists_exponential_entropy( const double lambda );
176
+ ```
177
+
178
+ </section>
179
+
180
+ <!-- /.usage -->
181
+
182
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
183
+
184
+ <section class="notes">
185
+
186
+ </section>
187
+
188
+ <!-- /.notes -->
189
+
190
+ <!-- C API usage examples. -->
191
+
192
+ <section class="examples">
193
+
194
+ ### Examples
195
+
196
+ ```c
197
+ #include "stdlib/stats/base/dists/exponential/entropy.h"
198
+ #include <stdlib.h>
199
+ #include <stdio.h>
200
+
201
+ static double random_uniform( const double min, const double max ) {
202
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
203
+ return min + ( v*(max-min) );
204
+ }
205
+
206
+ int main( void ) {
207
+ double lambda;
208
+ double y;
209
+ int i;
210
+
211
+ for ( i = 0; i < 25; i++ ) {
212
+ lambda = random_uniform( 0.0, 20.0 );
213
+ y = stdlib_base_dists_exponential_entropy( lambda );
214
+ printf( "λ: %lf, h(X;λ): %lf\n", lambda, y );
215
+ }
131
216
  }
132
217
  ```
133
218
 
@@ -135,6 +220,10 @@ for ( i = 0; i < 10; i++ ) {
135
220
 
136
221
  <!-- /.examples -->
137
222
 
223
+ </section>
224
+
225
+ <!-- /.c -->
226
+
138
227
  <!-- 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. -->
139
228
 
140
229
  <section class="references">
@@ -177,7 +266,7 @@ See [LICENSE][stdlib-license].
177
266
 
178
267
  ## Copyright
179
268
 
180
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
269
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
181
270
 
182
271
  </section>
183
272
 
@@ -190,8 +279,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
190
279
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-exponential-entropy.svg
191
280
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-exponential-entropy
192
281
 
193
- [test-image]: https://github.com/stdlib-js/stats-base-dists-exponential-entropy/actions/workflows/test.yml/badge.svg?branch=v0.2.2
194
- [test-url]: https://github.com/stdlib-js/stats-base-dists-exponential-entropy/actions/workflows/test.yml?query=branch:v0.2.2
282
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-exponential-entropy/actions/workflows/test.yml/badge.svg?branch=v0.3.0
283
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-exponential-entropy/actions/workflows/test.yml?query=branch:v0.3.0
195
284
 
196
285
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-exponential-entropy/main.svg
197
286
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-exponential-entropy?branch=main
@@ -203,8 +292,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
203
292
 
204
293
  -->
205
294
 
206
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
207
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
295
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
296
+ [chat-url]: https://stdlib.zulipchat.com
208
297
 
209
298
  [stdlib]: https://github.com/stdlib-js/stdlib
210
299
 
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Returns the entropy of an exponential distribution.\n*\n* @param {NonNegativeNumber} lambda - rate parameter\n* @returns {number} entropy\n*\n* @example\n* var v = entropy( 9.0 );\n* // returns ~-1.197\n*\n* @example\n* var v = entropy( 1.0 );\n* // returns 1.0\n*\n* @example\n* var v = entropy( -0.2 );\n* // returns NaN\n*\n* @example\n* var v = entropy( NaN );\n* // returns NaN\n*/\nfunction entropy( lambda ) {\n\tif ( isnan( lambda ) || lambda < 0.0 ) {\n\t\treturn NaN;\n\t}\n\treturn 1.0 - ln( lambda );\n}\n\n\n// EXPORTS //\n\nmodule.exports = entropy;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Exponential distribution differential entropy.\n*\n* @module @stdlib/stats-base-dists-exponential-entropy\n*\n* @example\n* var entropy = require( '@stdlib/stats-base-dists-exponential-entropy' );\n*\n* var v = entropy( 11.0 );\n* // returns ~-1.398\n*\n* v = entropy( 4.5 );\n* // returns ~-0.504\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n// MODULES //\n\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Returns the differential entropy of an exponential distribution.\n*\n* @param {NonNegativeNumber} lambda - rate parameter\n* @returns {number} differential entropy\n*\n* @example\n* var v = entropy( 9.0 );\n* // returns ~-1.197\n*\n* @example\n* var v = entropy( 1.0 );\n* // returns 1.0\n*\n* @example\n* var v = entropy( -0.2 );\n* // returns NaN\n*\n* @example\n* var v = entropy( NaN );\n* // returns NaN\n*/\nfunction entropy( lambda ) {\n\tif ( isnan( lambda ) || lambda < 0.0 ) {\n\t\treturn NaN;\n\t}\n\treturn 1.0 - ln( lambda );\n}\n\n\n// EXPORTS //\n\nmodule.exports = entropy;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2018 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n\n'use strict';\n\n/**\n* Exponential distribution differential entropy.\n*\n* @module @stdlib/stats-base-dists-exponential-entropy\n*\n* @example\n* var entropy = require( '@stdlib/stats-base-dists-exponential-entropy' );\n*\n* var v = entropy( 11.0 );\n* // returns ~-1.398\n*\n* v = entropy( 4.5 );\n* // returns ~-0.504\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
5
  "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAQ,QAAS,iCAAkC,EACnDC,EAAK,QAAS,8BAA+B,EA2BjD,SAASC,EAASC,EAAS,CAC1B,OAAKH,EAAOG,CAAO,GAAKA,EAAS,EACzB,IAED,EAAMF,EAAIE,CAAO,CACzB,CAKAJ,EAAO,QAAUG,ICvBjB,IAAIE,EAAO,IAKX,OAAO,QAAUA",
6
6
  "names": ["require_main", "__commonJSMin", "exports", "module", "isnan", "ln", "entropy", "lambda", "main"]
7
7
  }
@@ -19,14 +19,14 @@
19
19
  // TypeScript Version: 4.1
20
20
 
21
21
  /**
22
- * Returns the entropy of an exponential distribution.
22
+ * Returns the differential entropy of an exponential distribution.
23
23
  *
24
24
  * ## Notes
25
25
  *
26
26
  * - If provided a negative value for `λ`, the function returns `NaN`.
27
27
  *
28
28
  * @param lambda - rate parameter
29
- * @returns entropy
29
+ * @returns differential entropy
30
30
  *
31
31
  * @example
32
32
  * var v = entropy( 9.0 );
@@ -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_EXPONENTIAL_ENTROPY_H
20
+ #define STDLIB_STATS_BASE_DISTS_EXPONENTIAL_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 entropy of an exponential distribution.
31
+ */
32
+ double stdlib_base_dists_exponential_entropy( const double lambda );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_EXPONENTIAL_ENTROPY_H
package/lib/main.js CHANGED
@@ -27,10 +27,10 @@ var ln = require( '@stdlib/math-base-special-ln' );
27
27
  // MAIN //
28
28
 
29
29
  /**
30
- * Returns the entropy of an exponential distribution.
30
+ * Returns the differential entropy of an exponential distribution.
31
31
  *
32
32
  * @param {NonNegativeNumber} lambda - rate parameter
33
- * @returns {number} entropy
33
+ * @returns {number} differential entropy
34
34
  *
35
35
  * @example
36
36
  * var v = entropy( 9.0 );
package/lib/native.js ADDED
@@ -0,0 +1,58 @@
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 entropy of an exponential distribution.
30
+ *
31
+ * @private
32
+ * @param {NonNegativeNumber} lambda - rate parameter
33
+ * @returns {number} entropy
34
+ *
35
+ * @example
36
+ * var v = entropy( 9.0 );
37
+ * // returns ~-1.197
38
+ *
39
+ * @example
40
+ * var v = entropy( 1.0 );
41
+ * // returns 1.0
42
+ *
43
+ * @example
44
+ * var v = entropy( -0.2 );
45
+ * // returns NaN
46
+ *
47
+ * @example
48
+ * var v = entropy( NaN );
49
+ * // returns NaN
50
+ */
51
+ function entropy( lambda ) {
52
+ return addon( lambda );
53
+ }
54
+
55
+
56
+ // EXPORTS //
57
+
58
+ 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-unary",
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-exponential-entropy",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Exponential distribution differential 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",
@@ -31,7 +34,9 @@
31
34
  },
32
35
  "dependencies": {
33
36
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
34
- "@stdlib/math-base-special-ln": "^0.2.3"
37
+ "@stdlib/math-base-napi-unary": "^0.2.4",
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,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/exponential/entropy.h"
20
+ #include "stdlib/math/base/napi/unary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_D_D( stdlib_base_dists_exponential_entropy )
package/src/main.c ADDED
@@ -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
+ #include "stdlib/stats/base/dists/exponential/entropy.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/ln.h"
22
+
23
+ /**
24
+ * Returns the entropy of an exponential distribution.
25
+ *
26
+ * @param lambda rate parameter
27
+ * @return entropy
28
+ *
29
+ * @example
30
+ * double y = stdlib_base_exponential_entropy( 9.0 );
31
+ * // returns ~-1.197
32
+ */
33
+ double stdlib_base_dists_exponential_entropy( const double lambda ) {
34
+ if ( stdlib_base_is_nan( lambda ) || lambda < 0.0 ) {
35
+ return 0.0 / 0.0; // NaN
36
+ }
37
+ return 1.0 - stdlib_base_ln( lambda );
38
+ }