@stdlib/stats-base-dists-t-logpdf 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 +1 -1
- package/README.md +107 -15
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/docs/types/index.d.ts +4 -4
- package/include/stdlib/stats/base/dists/t/logpdf.h +38 -0
- package/lib/index.js +2 -2
- package/lib/native.js +63 -0
- package/manifest.json +88 -0
- package/package.json +8 -3
- package/src/addon.c +22 -0
- package/src/main.c +44 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -141,19 +141,107 @@ y = mylogpdf( 1.0 );
|
|
|
141
141
|
<!-- eslint no-undef: "error" -->
|
|
142
142
|
|
|
143
143
|
```javascript
|
|
144
|
-
var
|
|
144
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
145
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
145
146
|
var logpdf = require( '@stdlib/stats-base-dists-t-logpdf' );
|
|
146
147
|
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var
|
|
148
|
+
var opts = {
|
|
149
|
+
'dtype': 'float64'
|
|
150
|
+
};
|
|
151
|
+
var x = uniform( 10, -3.0, 3.0, opts );
|
|
152
|
+
var v = uniform( 10, 0.0, 10.0, opts );
|
|
151
153
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
logEachMap( 'x: %0.4f, v: %0.4f, ln(f(x;v)): %0.4f', x, v, logpdf );
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
</section>
|
|
158
|
+
|
|
159
|
+
<!-- /.examples -->
|
|
160
|
+
|
|
161
|
+
<!-- C interface documentation. -->
|
|
162
|
+
|
|
163
|
+
* * *
|
|
164
|
+
|
|
165
|
+
<section class="c">
|
|
166
|
+
|
|
167
|
+
## C APIs
|
|
168
|
+
|
|
169
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
170
|
+
|
|
171
|
+
<section class="intro">
|
|
172
|
+
|
|
173
|
+
</section>
|
|
174
|
+
|
|
175
|
+
<!-- /.intro -->
|
|
176
|
+
|
|
177
|
+
<!-- C usage documentation. -->
|
|
178
|
+
|
|
179
|
+
<section class="usage">
|
|
180
|
+
|
|
181
|
+
### Usage
|
|
182
|
+
|
|
183
|
+
```c
|
|
184
|
+
#include "stdlib/stats/base/dists/t/logpdf.h"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### stdlib_base_dists_t_logpdf( x, v )
|
|
188
|
+
|
|
189
|
+
Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for a [Student's t][t-distribution] distribution with degrees of freedom `v`.
|
|
190
|
+
|
|
191
|
+
```c
|
|
192
|
+
double out = stdlib_base_dists_t_logpdf( 0.5, 1.0 );
|
|
193
|
+
// returns ~-1.368
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
The function accepts the following arguments:
|
|
197
|
+
|
|
198
|
+
- **x**: `[in] double` input value.
|
|
199
|
+
- **v**: `[in] double` degrees of freedom.
|
|
200
|
+
|
|
201
|
+
```c
|
|
202
|
+
double stdlib_base_dists_t_logpdf( const double x, const double v );
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
</section>
|
|
206
|
+
|
|
207
|
+
<!-- /.usage -->
|
|
208
|
+
|
|
209
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
210
|
+
|
|
211
|
+
<section class="notes">
|
|
212
|
+
|
|
213
|
+
</section>
|
|
214
|
+
|
|
215
|
+
<!-- /.notes -->
|
|
216
|
+
|
|
217
|
+
<!-- C API usage examples. -->
|
|
218
|
+
|
|
219
|
+
<section class="examples">
|
|
220
|
+
|
|
221
|
+
### Examples
|
|
222
|
+
|
|
223
|
+
```c
|
|
224
|
+
#include "stdlib/stats/base/dists/t/logpdf.h"
|
|
225
|
+
#include <stdlib.h>
|
|
226
|
+
#include <stdio.h>
|
|
227
|
+
|
|
228
|
+
static double random_uniform( const double min, const double max ) {
|
|
229
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
230
|
+
return min + ( v*(max-min) );
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
int main( void ) {
|
|
234
|
+
double x;
|
|
235
|
+
double v;
|
|
236
|
+
double y;
|
|
237
|
+
int i;
|
|
238
|
+
|
|
239
|
+
for ( i = 0; i < 25; i++ ) {
|
|
240
|
+
x = random_uniform( -10.0, 10.0 );
|
|
241
|
+
v = random_uniform( 1.0, 100.0 );
|
|
242
|
+
y = stdlib_base_dists_t_logpdf( x, v );
|
|
243
|
+
printf( "x: %lf, v: %lf, ln(f(x;v)): %lf\n", x, v, y );
|
|
244
|
+
}
|
|
157
245
|
}
|
|
158
246
|
```
|
|
159
247
|
|
|
@@ -161,6 +249,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
161
249
|
|
|
162
250
|
<!-- /.examples -->
|
|
163
251
|
|
|
252
|
+
</section>
|
|
253
|
+
|
|
254
|
+
<!-- /.c -->
|
|
255
|
+
|
|
164
256
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
165
257
|
|
|
166
258
|
<section class="related">
|
|
@@ -195,7 +287,7 @@ See [LICENSE][stdlib-license].
|
|
|
195
287
|
|
|
196
288
|
## Copyright
|
|
197
289
|
|
|
198
|
-
Copyright © 2016-
|
|
290
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
199
291
|
|
|
200
292
|
</section>
|
|
201
293
|
|
|
@@ -208,8 +300,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
208
300
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-t-logpdf.svg
|
|
209
301
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-t-logpdf
|
|
210
302
|
|
|
211
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-t-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
212
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-t-logpdf/actions/workflows/test.yml?query=branch:v0.
|
|
303
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-t-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
304
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-t-logpdf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
213
305
|
|
|
214
306
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-t-logpdf/main.svg
|
|
215
307
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-t-logpdf?branch=main
|
|
@@ -221,8 +313,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
221
313
|
|
|
222
314
|
-->
|
|
223
315
|
|
|
224
|
-
[chat-image]: https://img.shields.io/
|
|
225
|
-
[chat-url]: https://
|
|
316
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
317
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
226
318
|
|
|
227
319
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
228
320
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference path="../docs/types/index.d.ts" />
|
|
2
|
-
import
|
|
3
|
-
export =
|
|
2
|
+
import logpdf from '../docs/types/index';
|
|
3
|
+
export = logpdf;
|
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 betaln = require( '@stdlib/math-base-special-betaln' );\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the probability density function (PDF) for a Student's t distribution with degrees of freedom `v` at a value `x`.\n*\n* @param {number} x - input value\n* @param {PositiveNumber} v - degrees of freedom\n* @returns {number} evaluated logPDF\n*\n* @example\n* var y = logpdf( 0.3, 4.0 );\n* // returns ~-1.036\n*\n* @example\n* var y = logpdf( 2.0, 0.7 );\n* // returns ~-2.841\n*\n* @example\n* var y = logpdf( -1.0, 0.5 );\n* // returns ~-2.134\n*\n* @example\n* var y = logpdf( 0.0, NaN );\n* // returns NaN\n*\n* @example\n* var y = logpdf( NaN, 2.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 2.0, -1.0 );\n* // returns NaN\n*/\nfunction logpdf( x, v ) {\n\tvar betaTerm;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( v ) ||\n\t\tv <= 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tbetaTerm = ln( sqrt( v ) ) + betaln( v/2.0, 0.5 );\n\treturn ( ( (1.0+v) / 2.0 ) * ln( v / ( v + pow( x, 2.0 ) ) ) ) - betaTerm;\n}\n\n\n// EXPORTS //\n\nmodule.exports = logpdf;\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 betaln = require( '@stdlib/math-base-special-betaln' );\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the natural logarithm of the probability density function (PDF) for a Student's t distribution with `v` degrees of freedom.\n*\n* @param {PositiveNumber} v - degrees of freedom\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 1.0 );\n* var y = logpdf( 3.0 );\n* // returns ~-3.447\n*\n* y = logpdf( 1.0 );\n* // returns ~-1.838\n*/\nfunction factory( v ) {\n\tvar exponent;\n\tvar betaTerm;\n\n\tif ( isnan( v ) || v <= 0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tbetaTerm = ln( sqrt( v ) ) + betaln( v/2.0, 0.5 );\n\texponent = ( 1.0 + v ) / 2.0;\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the natural logarithm of the probability density function (PDF) for a Student's t distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logPDF\n\t*\n\t* @example\n\t* var y = logpdf( 2.3 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn ( exponent * ln( v / ( v + pow( x, 2.0 ) ) ) ) - betaTerm;\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* Natural logarithm of the probability density function (PDF) for a Student's t distribution.\n*\n* @module @stdlib/stats-base-dists-t-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-t-logpdf' );\n*\n* var y = logpdf( 3.0, 1.0 );\n* // returns ~-3.
|
|
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 betaln = require( '@stdlib/math-base-special-betaln' );\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the probability density function (PDF) for a Student's t distribution with degrees of freedom `v` at a value `x`.\n*\n* @param {number} x - input value\n* @param {PositiveNumber} v - degrees of freedom\n* @returns {number} evaluated logPDF\n*\n* @example\n* var y = logpdf( 0.3, 4.0 );\n* // returns ~-1.036\n*\n* @example\n* var y = logpdf( 2.0, 0.7 );\n* // returns ~-2.841\n*\n* @example\n* var y = logpdf( -1.0, 0.5 );\n* // returns ~-2.134\n*\n* @example\n* var y = logpdf( 0.0, NaN );\n* // returns NaN\n*\n* @example\n* var y = logpdf( NaN, 2.0 );\n* // returns NaN\n*\n* @example\n* var y = logpdf( 2.0, -1.0 );\n* // returns NaN\n*/\nfunction logpdf( x, v ) {\n\tvar betaTerm;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( v ) ||\n\t\tv <= 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tbetaTerm = ln( sqrt( v ) ) + betaln( v/2.0, 0.5 );\n\treturn ( ( (1.0+v) / 2.0 ) * ln( v / ( v + pow( x, 2.0 ) ) ) ) - betaTerm;\n}\n\n\n// EXPORTS //\n\nmodule.exports = logpdf;\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 betaln = require( '@stdlib/math-base-special-betaln' );\nvar sqrt = require( '@stdlib/math-base-special-sqrt' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar ln = require( '@stdlib/math-base-special-ln' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the natural logarithm of the probability density function (PDF) for a Student's t distribution with `v` degrees of freedom.\n*\n* @param {PositiveNumber} v - degrees of freedom\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 1.0 );\n* var y = logpdf( 3.0 );\n* // returns ~-3.447\n*\n* y = logpdf( 1.0 );\n* // returns ~-1.838\n*/\nfunction factory( v ) {\n\tvar exponent;\n\tvar betaTerm;\n\n\tif ( isnan( v ) || v <= 0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tbetaTerm = ln( sqrt( v ) ) + betaln( v/2.0, 0.5 );\n\texponent = ( 1.0 + v ) / 2.0;\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the natural logarithm of the probability density function (PDF) for a Student's t distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logPDF\n\t*\n\t* @example\n\t* var y = logpdf( 2.3 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\treturn ( exponent * ln( v / ( v + pow( x, 2.0 ) ) ) ) - betaTerm;\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* Natural logarithm of the probability density function (PDF) for a Student's t distribution.\n*\n* @module @stdlib/stats-base-dists-t-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-t-logpdf' );\n*\n* var y = logpdf( 3.0, 1.0 );\n* // returns ~-3.447\n*\n* var mylogPDF = logpdf.factory( 3.0 );\n* y = mylogPDF( 1.0 );\n* // returns ~-1.576\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,EAAS,QAAS,kCAAmC,EACrDC,EAAO,QAAS,gCAAiC,EACjDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAoCjD,SAASC,EAAQC,EAAGC,EAAI,CACvB,IAAIC,EACJ,OACCR,EAAOM,CAAE,GACTN,EAAOO,CAAE,GACTA,GAAK,EAEE,KAERC,EAAWJ,EAAIF,EAAMK,CAAE,CAAE,EAAIN,EAAQM,EAAE,EAAK,EAAI,GACpC,EAAIA,GAAK,EAAQH,EAAIG,GAAMA,EAAIJ,EAAKG,EAAG,CAAI,EAAI,EAAME,EAClE,CAKAT,EAAO,QAAUM,IC9EjB,IAAAI,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAQ,QAAS,iCAAkC,EACnDC,EAAS,QAAS,kCAAmC,EACrDC,EAAO,QAAS,gCAAiC,EACjDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAmBjD,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAEJ,GAAKR,EAAOM,CAAE,GAAKA,GAAK,EACvB,OAAOP,EAAkB,GAAI,EAE9B,OAAAS,EAAWJ,EAAIF,EAAMI,CAAE,CAAE,EAAIL,EAAQK,EAAE,EAAK,EAAI,EAChDC,GAAa,EAAMD,GAAM,EAClBG,EAaP,SAASA,EAAQC,EAAI,CACpB,OAAKV,EAAOU,CAAE,EACN,IAECH,EAAWH,EAAIE,GAAMA,EAAIH,EAAKO,EAAG,CAAI,EAAI,EAAMF,CACzD,CACD,CAKAV,EAAO,QAAUO,ICzCjB,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", "betaln", "sqrt", "pow", "ln", "logpdf", "x", "v", "betaTerm", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "isnan", "betaln", "sqrt", "pow", "ln", "factory", "v", "exponent", "betaTerm", "logpdf", "x", "setReadOnly", "main", "factory"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -93,15 +93,15 @@ interface LogPDF {
|
|
|
93
93
|
*
|
|
94
94
|
* @example
|
|
95
95
|
* var y = logpdf( 3.0, 1.0 );
|
|
96
|
-
* // returns ~-3.
|
|
96
|
+
* // returns ~-3.447
|
|
97
97
|
*
|
|
98
98
|
* var mylogPDF = logpdf.factory( 3.0 );
|
|
99
99
|
* y = mylogPDF( 1.0 );
|
|
100
|
-
* // returns ~-1.
|
|
100
|
+
* // returns ~-1.576
|
|
101
101
|
*/
|
|
102
|
-
declare var
|
|
102
|
+
declare var logpdf: LogPDF;
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
// EXPORTS //
|
|
106
106
|
|
|
107
|
-
export =
|
|
107
|
+
export = logpdf;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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_T_LOGPDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_T_LOGPDF_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 log probability density function (logPDF) for a Student's t distribution with degrees of freedom `v` at a value `x`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_t_logpdf( const double x, const double v );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_T_LOGPDF_H
|
package/lib/index.js
CHANGED
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
* var logpdf = require( '@stdlib/stats-base-dists-t-logpdf' );
|
|
28
28
|
*
|
|
29
29
|
* var y = logpdf( 3.0, 1.0 );
|
|
30
|
-
* // returns ~-3.
|
|
30
|
+
* // returns ~-3.447
|
|
31
31
|
*
|
|
32
32
|
* var mylogPDF = logpdf.factory( 3.0 );
|
|
33
33
|
* y = mylogPDF( 1.0 );
|
|
34
|
-
* // returns ~-1.
|
|
34
|
+
* // returns ~-1.576
|
|
35
35
|
*/
|
|
36
36
|
|
|
37
37
|
// MODULES //
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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 log probability density function (logPDF) for a Student's t distribution with degrees of freedom `v` at a value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {number} v - degrees of freedom
|
|
34
|
+
* @returns {number} evaluated logPDF
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var y = logpdf( 0.5, 1.0 );
|
|
38
|
+
* // returns ~-1.3678734371636097
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var y = logpdf( 0.0, 2.0 );
|
|
42
|
+
* // returns ~-1.0397207708399179
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var y = logpdf( NaN, 1.0 );
|
|
46
|
+
* // returns NaN
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var y = logpdf( 0.0, NaN );
|
|
50
|
+
* // returns NaN
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* var y = logpdf( 0.0, -1.0 );
|
|
54
|
+
* // returns NaN
|
|
55
|
+
*/
|
|
56
|
+
function logpdf( x, v ) {
|
|
57
|
+
return addon( x, v );
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// EXPORTS //
|
|
62
|
+
|
|
63
|
+
module.exports = logpdf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
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-betaln",
|
|
44
|
+
"@stdlib/math-base-special-ln",
|
|
45
|
+
"@stdlib/math-base-special-pow",
|
|
46
|
+
"@stdlib/math-base-special-sqrt"
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"task": "benchmark",
|
|
51
|
+
"wasm": false,
|
|
52
|
+
"src": [
|
|
53
|
+
"./src/main.c"
|
|
54
|
+
],
|
|
55
|
+
"include": [
|
|
56
|
+
"./include"
|
|
57
|
+
],
|
|
58
|
+
"libraries": [],
|
|
59
|
+
"libpath": [],
|
|
60
|
+
"dependencies": [
|
|
61
|
+
"@stdlib/math-base-assert-is-nan",
|
|
62
|
+
"@stdlib/math-base-special-betaln",
|
|
63
|
+
"@stdlib/math-base-special-ln",
|
|
64
|
+
"@stdlib/math-base-special-pow",
|
|
65
|
+
"@stdlib/math-base-special-sqrt"
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"task": "examples",
|
|
70
|
+
"wasm": false,
|
|
71
|
+
"src": [
|
|
72
|
+
"./src/main.c"
|
|
73
|
+
],
|
|
74
|
+
"include": [
|
|
75
|
+
"./include"
|
|
76
|
+
],
|
|
77
|
+
"libraries": [],
|
|
78
|
+
"libpath": [],
|
|
79
|
+
"dependencies": [
|
|
80
|
+
"@stdlib/math-base-assert-is-nan",
|
|
81
|
+
"@stdlib/math-base-special-betaln",
|
|
82
|
+
"@stdlib/math-base-special-ln",
|
|
83
|
+
"@stdlib/math-base-special-pow",
|
|
84
|
+
"@stdlib/math-base-special-sqrt"
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
]
|
|
88
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-t-logpdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Natural logarithm of the probability density function (PDF) for a Student's t distribution.",
|
|
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,12 +34,14 @@
|
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
34
|
-
"@stdlib/math-base-
|
|
37
|
+
"@stdlib/math-base-napi-binary": "^0.3.1",
|
|
38
|
+
"@stdlib/math-base-special-betaln": "^0.2.2",
|
|
35
39
|
"@stdlib/math-base-special-ln": "^0.2.4",
|
|
36
40
|
"@stdlib/math-base-special-pow": "^0.3.0",
|
|
37
41
|
"@stdlib/math-base-special-sqrt": "^0.2.2",
|
|
38
42
|
"@stdlib/utils-constant-function": "^0.2.2",
|
|
39
|
-
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
|
|
43
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
44
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
40
45
|
},
|
|
41
46
|
"devDependencies": {},
|
|
42
47
|
"engines": {
|
package/src/addon.c
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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/math/base/napi/binary.h"
|
|
20
|
+
#include "stdlib/stats/base/dists/t/logpdf.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_t_logpdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2024 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/t/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/betaln.h"
|
|
22
|
+
#include "stdlib/math/base/special/ln.h"
|
|
23
|
+
#include "stdlib/math/base/special/pow.h"
|
|
24
|
+
#include "stdlib/math/base/special/sqrt.h"
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Evaluates the log probability density function (logPDF) for a Student's t distribution with degrees of freedom `v` at a value `x`.
|
|
28
|
+
*
|
|
29
|
+
* @param x input value
|
|
30
|
+
* @param v degrees of freedom
|
|
31
|
+
* @return evaluated logPDF
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* double y = stdlib_base_dists_t_logpdf( 0.5, 1.0 );
|
|
35
|
+
* // returns ~-1.1447
|
|
36
|
+
*/
|
|
37
|
+
double stdlib_base_dists_t_logpdf( const double x, const double v ) {
|
|
38
|
+
double betaTerm;
|
|
39
|
+
if ( stdlib_base_is_nan( x ) || stdlib_base_is_nan( v ) || v <= 0.0 ) {
|
|
40
|
+
return 0.0 / 0.0; // NaN
|
|
41
|
+
}
|
|
42
|
+
betaTerm = stdlib_base_ln( stdlib_base_sqrt( v ) ) + stdlib_base_betaln( v / 2.0, 0.5 );
|
|
43
|
+
return ( ( ( 1.0 + v ) / 2.0 ) * stdlib_base_ln( v / ( v + stdlib_base_pow( x, 2.0 ) ) ) ) - betaTerm;
|
|
44
|
+
}
|