@stdlib/stats-base-dists-gamma-mgf 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
@@ -130,7 +130,7 @@ y = mgf( 2.0, 1.0, -1.0 );
130
130
 
131
131
  #### mgf.factory( alpha, beta )
132
132
 
133
- Return a function for evaluating the [MGF][mgf] of a [gamma][gamma-distribution] distribution with parameters `alpha` (shape parameter) and `beta` (rate parameter).
133
+ Returns a function for evaluating the [MGF][mgf] of a [gamma][gamma-distribution] distribution with parameters `alpha` (shape parameter) and `beta` (rate parameter).
134
134
 
135
135
  ```javascript
136
136
  var mymgf = mgf.factory( 3.0, 1.5 );
@@ -163,21 +163,111 @@ y = mymgf( 0.5 );
163
163
  <!-- eslint no-undef: "error" -->
164
164
 
165
165
  ```javascript
166
- var randu = require( '@stdlib/random-base-randu' );
166
+ var uniform = require( '@stdlib/random-array-uniform' );
167
+ var logEachMap = require( '@stdlib/console-log-each-map' );
167
168
  var mgf = require( '@stdlib/stats-base-dists-gamma-mgf' );
168
169
 
169
- var a;
170
- var b;
171
- var t;
172
- var v;
173
- var i;
174
-
175
- for ( i = 0; i < 10; i++ ) {
176
- t = randu();
177
- a = randu() * 5.0;
178
- b = a + (randu() * 5.0);
179
- v = mgf( t, a, b );
180
- console.log( 't: %d, a: %d, b: %d, M_X(t;a,b): %d', t.toFixed( 4 ), a.toFixed( 4 ), b.toFixed( 4 ), v.toFixed( 4 ) );
170
+ var opts = {
171
+ 'dtype': 'float64'
172
+ };
173
+ var t = uniform( 10, 0.0, 3.0, opts );
174
+ var alpha = uniform( 10, 0.0, 5.0, opts );
175
+ var beta = uniform( 10, 0.0, 5.0, opts );
176
+
177
+ logEachMap( 't: %0.4f, α: %0.4f, β: %0.4f, M_X(t;α,β): %0.4f', t, alpha, beta, mgf );
178
+ ```
179
+
180
+ </section>
181
+
182
+ <!-- /.examples -->
183
+
184
+ <!-- C interface documentation. -->
185
+
186
+ * * *
187
+
188
+ <section class="c">
189
+
190
+ ## C APIs
191
+
192
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
193
+
194
+ <section class="intro">
195
+
196
+ </section>
197
+
198
+ <!-- /.intro -->
199
+
200
+ <!-- C usage documentation. -->
201
+
202
+ <section class="usage">
203
+
204
+ ### Usage
205
+
206
+ ```c
207
+ #include "stdlib/stats/base/dists/gamma/mgf.h"
208
+ ```
209
+
210
+ #### stdlib_base_dists_gamma_mgf( t, alpha, beta )
211
+
212
+ Evaluates the [moment-generating function][mgf] (MGF) for a [gamma][gamma-distribution] distribution with parameters `alpha` (shape parameter) and `beta` (rate parameter).
213
+
214
+ ```c
215
+ double y = stdlib_base_dists_gamma_mgf( 0.5, 0.5, 1.0 );
216
+ // returns ~1.414
217
+ ```
218
+
219
+ The function accepts the following arguments:
220
+
221
+ - **t**: `[in] double` input value.
222
+ - **alpha**: `[in] double` shape parameter.
223
+ - **beta**: `[in] double` rate parameter.
224
+
225
+ ```c
226
+ double stdlib_base_dists_gamma_mgf( const double t, const double alpha, const double beta );
227
+ ```
228
+
229
+ </section>
230
+
231
+ <!-- /.usage -->
232
+
233
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
234
+
235
+ <section class="notes">
236
+
237
+ </section>
238
+
239
+ <!-- /.notes -->
240
+
241
+ <!-- C API usage examples. -->
242
+
243
+ <section class="examples">
244
+
245
+ ### Examples
246
+
247
+ ```c
248
+ #include "stdlib/stats/base/dists/gamma/mgf.h"
249
+ #include <stdlib.h>
250
+ #include <stdio.h>
251
+
252
+ static double random_uniform( const double min, const double max ) {
253
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
254
+ return min + ( v*(max-min) );
255
+ }
256
+
257
+ int main( void ) {
258
+ double alpha;
259
+ double beta;
260
+ double t;
261
+ double y;
262
+ int i;
263
+
264
+ for ( i = 0; i < 10; i++ ) {
265
+ t = random_uniform( 0.0, 3.0 );
266
+ alpha = random_uniform( 0.0, 5.0 );
267
+ beta = random_uniform( 0.0, 5.0 );
268
+ y = stdlib_base_dists_gamma_mgf( t, alpha, beta );
269
+ printf( "t: %lf, α: %lf, β: %lf, M_X(t;α,β): %lf\n", t, alpha, beta, y );
270
+ }
181
271
  }
182
272
  ```
183
273
 
@@ -185,6 +275,10 @@ for ( i = 0; i < 10; i++ ) {
185
275
 
186
276
  <!-- /.examples -->
187
277
 
278
+ </section>
279
+
280
+ <!-- /.c -->
281
+
188
282
  <!-- 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. -->
189
283
 
190
284
  <section class="references">
@@ -227,7 +321,7 @@ See [LICENSE][stdlib-license].
227
321
 
228
322
  ## Copyright
229
323
 
230
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
324
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
231
325
 
232
326
  </section>
233
327
 
@@ -240,8 +334,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
240
334
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-gamma-mgf.svg
241
335
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-gamma-mgf
242
336
 
243
- [test-image]: https://github.com/stdlib-js/stats-base-dists-gamma-mgf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
244
- [test-url]: https://github.com/stdlib-js/stats-base-dists-gamma-mgf/actions/workflows/test.yml?query=branch:v0.2.2
337
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-gamma-mgf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
338
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-gamma-mgf/actions/workflows/test.yml?query=branch:v0.3.0
245
339
 
246
340
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-gamma-mgf/main.svg
247
341
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-gamma-mgf?branch=main
@@ -253,8 +347,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
253
347
 
254
348
  -->
255
349
 
256
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
257
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
350
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
351
+ [chat-url]: https://stdlib.zulipchat.com
258
352
 
259
353
  [stdlib]: https://github.com/stdlib-js/stdlib
260
354
 
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../lib/main.js", "../lib/factory.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 pow = require( '@stdlib/math-base-special-pow' );\n\n\n// MAIN //\n\n/**\n* Evaluates the moment-generating function (MGF) for a gamma distribution.\n*\n* @param {number} t - input value\n* @param {NonNegativeNumber} alpha - shape parameter\n* @param {PositiveNumber} beta - rate parameter\n* @returns {number} evaluated MGF\n*\n* @example\n* var y = mgf( 0.5, 0.5, 1.0 );\n* // returns ~1.414\n*\n* @example\n* var y = mgf( 0.1, 1.0, 1.0 );\n* // returns ~1.111\n*\n* @example\n* var y = mgf( -1.0, 4.0, 2.0 );\n* // returns ~0.198\n*\n* @example\n* var y = mgf( NaN, 1.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 0.0, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 0.0, 1.0, NaN );\n* // returns NaN\n*\n* @example\n* var y = mgf( 2.0, 4.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 2.0, -0.5, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 2.0, 1.0, 0.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 2.0, 1.0, -1.0 );\n* // returns NaN\n*/\nfunction mgf( t, alpha, beta ) {\n\tvar base;\n\tif (\n\t\tisnan( t ) ||\n\t\tisnan( alpha ) ||\n\t\tisnan( beta ) ||\n\t\talpha < 0.0 ||\n\t\tbeta <= 0.0 ||\n\t\tt >= beta\n\t) {\n\t\treturn NaN;\n\t}\n\tbase = 1.0 - (t / beta);\n\treturn pow( base, -alpha );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mgf;\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// MODULES //\n\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar pow = require( '@stdlib/math-base-special-pow' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the moment-generating function (MGF) of a gamma distribution with shape `alpha` and rate `beta`.\n*\n* @param {NonNegativeNumber} alpha - shape parameter\n* @param {PositiveNumber} beta - rate parameter\n* @returns {Function} MGF\n*\n* @example\n* var mgf = factory( 3.0, 1.5 );\n*\n* var y = mgf( 1.0 );\n* // returns ~27.0\n*\n* y = mgf( 0.5 );\n* // returns ~3.375\n*/\nfunction factory( alpha, beta ) {\n\tif (\n\t\tisnan( alpha ) ||\n\t\tisnan( beta ) ||\n\t\talpha < 0.0 ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\treturn mgf;\n\n\t/**\n\t* Evaluates the moment-generating function (MGF) of a gamma distribution.\n\t*\n\t* @private\n\t* @param {number} t - input value\n\t* @returns {number} evaluated MGF\n\t*\n\t* @example\n\t* var y = mgf( 0.5 );\n\t* // returns <number>\n\t*/\n\tfunction mgf( t ) {\n\t\tvar base;\n\t\tif ( t >= beta ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tbase = 1.0 - (t / beta);\n\t\treturn pow( base, -alpha );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\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* Evaluate the moment-generating function (MGF) of a gamma distribution.\n*\n* @module @stdlib/stats-base-dists-gamma-mgf\n*\n* @example\n* var mgf = require( '@stdlib/stats-base-dists-gamma-mgf' );\n*\n* var y = mgf( 0.5, 0.5, 1.0 );\n* // returns ~1.414\n*\n* y = mgf( 0.1, 1.0, 1.0 );\n* // returns ~1.111\n*\n* y = mgf( -1.0, 4.0, 2.0 );\n* // returns ~0.198\n*\n* var mymgf = mgf.factory( 3.0, 1.5 );\n*\n* y = mymgf( 1.0 );\n* // returns ~26.999\n*\n* y = mymgf( 0.5 );\n* // returns ~3.375\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\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 pow = require( '@stdlib/math-base-special-pow' );\n\n\n// MAIN //\n\n/**\n* Evaluates the moment-generating function (MGF) for a gamma distribution.\n*\n* @param {number} t - input value\n* @param {NonNegativeNumber} alpha - shape parameter\n* @param {PositiveNumber} beta - rate parameter\n* @returns {number} evaluated MGF\n*\n* @example\n* var y = mgf( 0.5, 0.5, 1.0 );\n* // returns ~1.414\n*\n* @example\n* var y = mgf( 0.1, 1.0, 1.0 );\n* // returns ~1.111\n*\n* @example\n* var y = mgf( -1.0, 4.0, 2.0 );\n* // returns ~0.198\n*\n* @example\n* var y = mgf( NaN, 1.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 0.0, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 0.0, 1.0, NaN );\n* // returns NaN\n*\n* @example\n* var y = mgf( 2.0, 4.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 2.0, -0.5, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 2.0, 1.0, 0.0 );\n* // returns NaN\n*\n* @example\n* var y = mgf( 2.0, 1.0, -1.0 );\n* // returns NaN\n*/\nfunction mgf( t, alpha, beta ) {\n\tvar base;\n\tif (\n\t\tisnan( t ) ||\n\t\tisnan( alpha ) ||\n\t\tisnan( beta ) ||\n\t\talpha < 0.0 ||\n\t\tbeta <= 0.0 ||\n\t\tt >= beta\n\t) {\n\t\treturn NaN;\n\t}\n\tbase = 1.0 - (t / beta);\n\treturn pow( base, -alpha );\n}\n\n\n// EXPORTS //\n\nmodule.exports = mgf;\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// MODULES //\n\nvar constantFunction = require( '@stdlib/utils-constant-function' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar pow = require( '@stdlib/math-base-special-pow' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the moment-generating function (MGF) of a gamma distribution with shape `alpha` and rate `beta`.\n*\n* @param {NonNegativeNumber} alpha - shape parameter\n* @param {PositiveNumber} beta - rate parameter\n* @returns {Function} MGF\n*\n* @example\n* var mgf = factory( 3.0, 1.5 );\n*\n* var y = mgf( 1.0 );\n* // returns ~27.0\n*\n* y = mgf( 0.5 );\n* // returns ~3.375\n*/\nfunction factory( alpha, beta ) {\n\tif (\n\t\tisnan( alpha ) ||\n\t\tisnan( beta ) ||\n\t\talpha < 0.0 ||\n\t\tbeta <= 0.0\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\treturn mgf;\n\n\t/**\n\t* Evaluates the moment-generating function (MGF) of a gamma distribution.\n\t*\n\t* @private\n\t* @param {number} t - input value\n\t* @returns {number} evaluated MGF\n\t*\n\t* @example\n\t* var y = mgf( 0.5 );\n\t* // returns <number>\n\t*/\n\tfunction mgf( t ) {\n\t\tvar base;\n\t\tif ( t >= beta ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tbase = 1.0 - (t / beta);\n\t\treturn pow( base, -alpha );\n\t}\n}\n\n\n// EXPORTS //\n\nmodule.exports = factory;\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* Evaluate the moment-generating function (MGF) of a gamma distribution.\n*\n* @module @stdlib/stats-base-dists-gamma-mgf\n*\n* @example\n* var mgf = require( '@stdlib/stats-base-dists-gamma-mgf' );\n*\n* var y = mgf( 0.5, 0.5, 1.0 );\n* // returns ~1.414\n*\n* y = mgf( 0.1, 1.0, 1.0 );\n* // returns ~1.111\n*\n* y = mgf( -1.0, 4.0, 2.0 );\n* // returns ~0.198\n*\n* var mymgf = mgf.factory( 3.0, 1.5 );\n*\n* y = mymgf( 1.0 );\n* // returns ~27.0\n*\n* y = mymgf( 0.5 );\n* // returns ~3.375\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar factory = require( './factory.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'factory', factory );\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,EAAM,QAAS,+BAAgC,EAqDnD,SAASC,EAAKC,EAAGC,EAAOC,EAAO,CAC9B,IAAIC,EACJ,OACCN,EAAOG,CAAE,GACTH,EAAOI,CAAM,GACbJ,EAAOK,CAAK,GACZD,EAAQ,GACRC,GAAQ,GACRF,GAAKE,EAEE,KAERC,EAAO,EAAOH,EAAIE,EACXJ,EAAKK,EAAM,CAACF,CAAM,EAC1B,CAKAL,EAAO,QAAUG,IC/FjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAqBnD,SAASC,EAASC,EAAOC,EAAO,CAC/B,GACCJ,EAAOG,CAAM,GACbH,EAAOI,CAAK,GACZD,EAAQ,GACRC,GAAQ,EAER,OAAOL,EAAkB,GAAI,EAE9B,OAAOM,EAaP,SAASA,EAAKC,EAAI,CACjB,IAAIC,EACJ,OAAKD,GAAKF,EACF,KAERG,EAAO,EAAOD,EAAIF,EACXH,EAAKM,EAAM,CAACJ,CAAM,EAC1B,CACD,CAKAL,EAAO,QAAUI,IChCjB,IAAIM,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAU,IAKdF,EAAaC,EAAM,UAAWC,CAAQ,EAKtC,OAAO,QAAUD",
6
6
  "names": ["require_main", "__commonJSMin", "exports", "module", "isnan", "pow", "mgf", "t", "alpha", "beta", "base", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "isnan", "pow", "factory", "alpha", "beta", "mgf", "t", "base", "setReadOnly", "main", "factory"]
7
7
  }
@@ -124,7 +124,7 @@ interface MGF {
124
124
  * var mymgf = mgf.factory( 3.0, 1.5 );
125
125
  *
126
126
  * y = mymgf( 1.0 );
127
- * // returns ~26.999
127
+ * // returns ~27.0
128
128
  *
129
129
  * y = mymgf( 0.5 );
130
130
  * // returns ~3.375
@@ -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_GAMMA_MGF_H
20
+ #define STDLIB_STATS_BASE_DISTS_GAMMA_MGF_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 moment-generating function (MGF) for a gamma distribution with shape parameter `alpha` and rate parameter 'beta`.
32
+ */
33
+ double stdlib_base_dists_gamma_mgf( const double t, const double alpha, const double beta );
34
+
35
+ #ifdef __cplusplus
36
+ }
37
+ #endif
38
+
39
+ #endif // !STDLIB_STATS_BASE_DISTS_GAMMA_MGF_H
package/lib/index.js CHANGED
@@ -38,7 +38,7 @@
38
38
  * var mymgf = mgf.factory( 3.0, 1.5 );
39
39
  *
40
40
  * y = mymgf( 1.0 );
41
- * // returns ~26.999
41
+ * // returns ~27.0
42
42
  *
43
43
  * y = mymgf( 0.5 );
44
44
  * // returns ~3.375
package/lib/native.js ADDED
@@ -0,0 +1,84 @@
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 moment-generating function (MGF) for a gamma distribution.
30
+ *
31
+ * @private
32
+ * @param {number} t - input value
33
+ * @param {NonNegativeNumber} alpha - shape parameter
34
+ * @param {PositiveNumber} beta - rate parameter
35
+ * @returns {number} evaluated MGF
36
+ *
37
+ * @example
38
+ * var y = mgf( 0.5, 0.5, 1.0 );
39
+ * // returns ~1.414
40
+ *
41
+ * @example
42
+ * var y = mgf( 0.1, 1.0, 1.0 );
43
+ * // returns ~1.111
44
+ *
45
+ * @example
46
+ * var y = mgf( -1.0, 4.0, 2.0 );
47
+ * // returns ~0.198
48
+ *
49
+ * @example
50
+ * var y = mgf( NaN, 1.0, 1.0 );
51
+ * // returns NaN
52
+ *
53
+ * @example
54
+ * var y = mgf( 0.0, NaN, 1.0 );
55
+ * // returns NaN
56
+ *
57
+ * @example
58
+ * var y = mgf( 0.0, 1.0, NaN );
59
+ * // returns NaN
60
+ *
61
+ * @example
62
+ * var y = mgf( 2.0, 4.0, 1.0 );
63
+ * // returns NaN
64
+ *
65
+ * @example
66
+ * var y = mgf( 2.0, -0.5, 1.0 );
67
+ * // returns NaN
68
+ *
69
+ * @example
70
+ * var y = mgf( 2.0, 1.0, 0.0 );
71
+ * // returns NaN
72
+ *
73
+ * @example
74
+ * var y = mgf( 2.0, 1.0, -1.0 );
75
+ * // returns NaN
76
+ */
77
+ function mgf( t, alpha, beta ) {
78
+ return addon( t, alpha, beta );
79
+ }
80
+
81
+
82
+ // EXPORTS //
83
+
84
+ module.exports = mgf;
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-pow"
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/math-base-special-pow",
60
+ "@stdlib/constants-float64-eps"
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-pow"
77
+ ]
78
+ }
79
+ ]
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-gamma-mgf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Gamma distribution moment-generating function (MGF).",
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-pow": "^0.3.0",
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/gamma/mgf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_gamma_mgf )
package/src/main.c ADDED
@@ -0,0 +1,49 @@
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/gamma/mgf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/pow.h"
22
+
23
+ /**
24
+ * Evaluates the moment-generating function (MGF) for a gamma distribution with shape parameter `alpha` and rate parameter `beta`.
25
+ *
26
+ * @param t input value
27
+ * @param alpha shape parameter
28
+ * @param beta rate parameter
29
+ * @return evaluated MGF
30
+ *
31
+ * @example
32
+ * double y = stdlib_base_dists_gamma_mgf( 0.5, 0.5, 1.0 );
33
+ * // returns ~1.414
34
+ */
35
+ double stdlib_base_dists_gamma_mgf( const double t, const double alpha, const double beta ) {
36
+ double base;
37
+ if (
38
+ stdlib_base_is_nan( t ) ||
39
+ stdlib_base_is_nan( alpha ) ||
40
+ stdlib_base_is_nan( beta ) ||
41
+ alpha < 0.0 ||
42
+ beta <= 0.0 ||
43
+ t >= beta
44
+ ) {
45
+ return 0.0 / 0.0;
46
+ }
47
+ base = 1.0 - (t / beta);
48
+ return stdlib_base_pow( base, -alpha );
49
+ }