@stdlib/stats-base-dists-chi-logpdf 0.2.2 → 0.3.1
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 +109 -17
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/docs/types/index.d.ts +3 -3
- package/include/stdlib/stats/base/dists/chi/logpdf.h +38 -0
- package/lib/index.js +1 -1
- package/lib/native.js +68 -0
- package/manifest.json +91 -0
- package/package.json +15 -10
- package/src/addon.c +22 -0
- package/src/main.c +55 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ limitations under the License.
|
|
|
33
33
|
|
|
34
34
|
[![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
|
|
35
35
|
|
|
36
|
-
> Evaluate the natural logarithm of the [probability density function][pdf] (PDF) for a [chi][chi-distribution] distribution
|
|
36
|
+
> Evaluate the natural logarithm of the [probability density function][pdf] (PDF) for a [chi][chi-distribution] distribution.
|
|
37
37
|
|
|
38
38
|
<section class="intro">
|
|
39
39
|
|
|
@@ -48,7 +48,7 @@ The [probability density function][pdf] (PDF) for a [chi][chi-distribution] rand
|
|
|
48
48
|
|
|
49
49
|
<!-- </equation> -->
|
|
50
50
|
|
|
51
|
-
where `k` is the degrees of freedom and `Γ` denotes the [gamma][gamma-function] function.
|
|
51
|
+
where `k` is the degrees of freedom and `Γ` denotes the [gamma][gamma-function] function.
|
|
52
52
|
|
|
53
53
|
</section>
|
|
54
54
|
|
|
@@ -139,19 +139,107 @@ y = mylogPDF( 1.0 );
|
|
|
139
139
|
<!-- eslint no-undef: "error" -->
|
|
140
140
|
|
|
141
141
|
```javascript
|
|
142
|
-
var
|
|
142
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
143
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
143
144
|
var logpdf = require( '@stdlib/stats-base-dists-chi-logpdf' );
|
|
144
145
|
|
|
145
|
-
var
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
var
|
|
146
|
+
var opts = {
|
|
147
|
+
'dtype': 'float64'
|
|
148
|
+
};
|
|
149
|
+
var x = uniform( 20, 0.0, 10.0, opts );
|
|
150
|
+
var k = uniform( 20, 0.0, 10.0, opts );
|
|
149
151
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
logEachMap( 'x: %0.4f, k: %0.4f, ln(f(x;k)): %0.4f', x, k, logpdf );
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
</section>
|
|
156
|
+
|
|
157
|
+
<!-- /.examples -->
|
|
158
|
+
|
|
159
|
+
<!-- C interface documentation. -->
|
|
160
|
+
|
|
161
|
+
* * *
|
|
162
|
+
|
|
163
|
+
<section class="c">
|
|
164
|
+
|
|
165
|
+
## C APIs
|
|
166
|
+
|
|
167
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
168
|
+
|
|
169
|
+
<section class="intro">
|
|
170
|
+
|
|
171
|
+
</section>
|
|
172
|
+
|
|
173
|
+
<!-- /.intro -->
|
|
174
|
+
|
|
175
|
+
<!-- C usage documentation. -->
|
|
176
|
+
|
|
177
|
+
<section class="usage">
|
|
178
|
+
|
|
179
|
+
### Usage
|
|
180
|
+
|
|
181
|
+
```c
|
|
182
|
+
#include "stdlib/stats/base/dists/chi/logpdf.h"
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### stdlib_base_dists_chi_logpdf( x, k )
|
|
186
|
+
|
|
187
|
+
Evaluates the natural logarithm of the [probability density function][pdf] (PDF) for a [chi][chi-distribution] distribution with degrees of freedom `k`.
|
|
188
|
+
|
|
189
|
+
```c
|
|
190
|
+
double out = stdlib_base_dists_chi_logpdf( 2.0, 2.0 );
|
|
191
|
+
// returns ~-1.309
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The function accepts the following arguments:
|
|
195
|
+
|
|
196
|
+
- **x**: `[in] double` input value.
|
|
197
|
+
- **k**: `[in] double` degrees of freedom.
|
|
198
|
+
|
|
199
|
+
```c
|
|
200
|
+
double stdlib_base_dists_chi_logpdf( const double x, const double k );
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
</section>
|
|
204
|
+
|
|
205
|
+
<!-- /.usage -->
|
|
206
|
+
|
|
207
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
208
|
+
|
|
209
|
+
<section class="notes">
|
|
210
|
+
|
|
211
|
+
</section>
|
|
212
|
+
|
|
213
|
+
<!-- /.notes -->
|
|
214
|
+
|
|
215
|
+
<!-- C API usage examples. -->
|
|
216
|
+
|
|
217
|
+
<section class="examples">
|
|
218
|
+
|
|
219
|
+
### Examples
|
|
220
|
+
|
|
221
|
+
```c
|
|
222
|
+
#include "stdlib/stats/base/dists/chi/logpdf.h"
|
|
223
|
+
#include <stdlib.h>
|
|
224
|
+
#include <stdio.h>
|
|
225
|
+
|
|
226
|
+
static double random_uniform( const double min, const double max ) {
|
|
227
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
228
|
+
return min + ( v*(max-min) );
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
int main( void ) {
|
|
232
|
+
double x;
|
|
233
|
+
double k;
|
|
234
|
+
double y;
|
|
235
|
+
int i;
|
|
236
|
+
|
|
237
|
+
for ( i = 0; i < 25; i++ ) {
|
|
238
|
+
x = random_uniform( 0.0, 10.0 );
|
|
239
|
+
k = random_uniform( 0.1, 10.0 );
|
|
240
|
+
y = stdlib_base_dists_chi_logpdf( x, k );
|
|
241
|
+
printf( "x: %lf, k: %lf, ln(f(x;k)): %lf\n", x, k, y );
|
|
242
|
+
}
|
|
155
243
|
}
|
|
156
244
|
```
|
|
157
245
|
|
|
@@ -159,6 +247,10 @@ for ( i = 0; i < 20; i++ ) {
|
|
|
159
247
|
|
|
160
248
|
<!-- /.examples -->
|
|
161
249
|
|
|
250
|
+
</section>
|
|
251
|
+
|
|
252
|
+
<!-- /.c -->
|
|
253
|
+
|
|
162
254
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
163
255
|
|
|
164
256
|
<section class="related">
|
|
@@ -193,7 +285,7 @@ See [LICENSE][stdlib-license].
|
|
|
193
285
|
|
|
194
286
|
## Copyright
|
|
195
287
|
|
|
196
|
-
Copyright © 2016-
|
|
288
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
197
289
|
|
|
198
290
|
</section>
|
|
199
291
|
|
|
@@ -206,8 +298,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
206
298
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-chi-logpdf.svg
|
|
207
299
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-chi-logpdf
|
|
208
300
|
|
|
209
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-chi-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
210
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-chi-logpdf/actions/workflows/test.yml?query=branch:v0.
|
|
301
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-chi-logpdf/actions/workflows/test.yml/badge.svg?branch=v0.3.1
|
|
302
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-chi-logpdf/actions/workflows/test.yml?query=branch:v0.3.1
|
|
211
303
|
|
|
212
304
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-chi-logpdf/main.svg
|
|
213
305
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-chi-logpdf?branch=main
|
|
@@ -219,8 +311,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
219
311
|
|
|
220
312
|
-->
|
|
221
313
|
|
|
222
|
-
[chat-image]: https://img.shields.io/
|
|
223
|
-
[chat-url]: https://
|
|
314
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
315
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
224
316
|
|
|
225
317
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
226
318
|
|
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 gammaln = require( '@stdlib/math-base-special-gammaln' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the probability density function (PDF) for a chi distribution with degrees of freedom `k` at a value `x`.\n*\n* @param {number} x - input value\n* @param {NonNegativeNumber} k - degrees of freedom\n* @returns {number} evaluated logPDF\n*\n* @example\n* var y = logpdf( 0.3, 4.0 );\n* // returns ~-4.35\n*\n* @example\n* var y = logpdf( 0.7, 0.7 );\n* // returns ~-0.622\n*\n* @example\n* var y = logpdf( -1.0, 0.5 );\n* // returns -Infinity\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* // Negative degrees of freedom:\n* var y = logpdf( 2.0, -1.0 );\n* // returns NaN\n*/\nfunction logpdf( x, k ) {\n\tvar out;\n\tvar kh;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( k ) ||\n\t\tk < 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( k === 0.0 ) {\n\t\t// Point mass at 0...\n\t\treturn ( x === 0.0 ) ? PINF : NINF;\n\t}\n\tif ( x < 0.0 || x === PINF ) {\n\t\treturn NINF;\n\t}\n\tkh = k / 2.0;\n\tout = ( ( 1.0-kh ) * LN2 ) + ( ( k-1.0 ) * ln( x ) ) - ( (x*x) / 2.0 );\n\tout -= gammaln( kh );\n\treturn out;\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 degenerate = require( '@stdlib/stats-base-dists-degenerate-logpdf' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar gammaln = require( '@stdlib/math-base-special-gammaln' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the natural logarithm of the probability density function (PDF) for a chi distribution with degrees of freedom `k`.\n*\n* @param {NonNegativeNumber} k - degrees of freedom\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 0.5 );\n*\n* var y = logpdf( 2.0 );\n* // returns ~-3.115\n*\n* y = logpdf( 1.0 );\n* // returns ~-1.268\n*/\nfunction factory( k ) {\n\tvar km1;\n\tvar kh;\n\n\tif ( isnan( k ) || k < 0.0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tif ( k === 0.0 ) {\n\t\treturn degenerate( 0.0 );\n\t}\n\n\tkh = k / 2.0;\n\tkm1 = k - 1.0;\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the natural logarithm of the probability density function (PDF) for a chi distribution with degrees of freedom `k`.\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( 1.0 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tvar out;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x < 0.0 || x === PINF ) {\n\t\t\treturn NINF;\n\t\t}\n\t\tout = ( ( 1.0-kh ) * LN2 ) + ( km1 * ln( x ) ) - ( (x*x) / 2.0 );\n\t\tout -= gammaln( kh );\n\t\treturn out;\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 chi distribution.\n*\n* @module @stdlib/stats-base-dists-chi-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-chi-logpdf' );\n*\n* var y = logpdf( 2.0, 1.0 );\n* // returns ~-2.226\n*\n* @example\n* var factory = require( '@stdlib/stats-base-dists-chi-logpdf' ).factory;\n*\n* var logpdf = factory( 6.0 );\n*\n* var y = logpdf( 3.0 );\n* // returns ~-1.
|
|
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 gammaln = require( '@stdlib/math-base-special-gammaln' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\n\n\n// MAIN //\n\n/**\n* Evaluates the natural logarithm of the probability density function (PDF) for a chi distribution with degrees of freedom `k` at a value `x`.\n*\n* @param {number} x - input value\n* @param {NonNegativeNumber} k - degrees of freedom\n* @returns {number} evaluated logPDF\n*\n* @example\n* var y = logpdf( 0.3, 4.0 );\n* // returns ~-4.35\n*\n* @example\n* var y = logpdf( 0.7, 0.7 );\n* // returns ~-0.622\n*\n* @example\n* var y = logpdf( -1.0, 0.5 );\n* // returns -Infinity\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* // Negative degrees of freedom:\n* var y = logpdf( 2.0, -1.0 );\n* // returns NaN\n*/\nfunction logpdf( x, k ) {\n\tvar out;\n\tvar kh;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( k ) ||\n\t\tk < 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( k === 0.0 ) {\n\t\t// Point mass at 0...\n\t\treturn ( x === 0.0 ) ? PINF : NINF;\n\t}\n\tif ( x < 0.0 || x === PINF ) {\n\t\treturn NINF;\n\t}\n\tkh = k / 2.0;\n\tout = ( ( 1.0-kh ) * LN2 ) + ( ( k-1.0 ) * ln( x ) ) - ( (x*x) / 2.0 );\n\tout -= gammaln( kh );\n\treturn out;\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 degenerate = require( '@stdlib/stats-base-dists-degenerate-logpdf' ).factory;\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar gammaln = require( '@stdlib/math-base-special-gammaln' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\nvar PINF = require( '@stdlib/constants-float64-pinf' );\nvar LN2 = require( '@stdlib/constants-float64-ln-two' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the natural logarithm of the probability density function (PDF) for a chi distribution with degrees of freedom `k`.\n*\n* @param {NonNegativeNumber} k - degrees of freedom\n* @returns {Function} logPDF\n*\n* @example\n* var logpdf = factory( 0.5 );\n*\n* var y = logpdf( 2.0 );\n* // returns ~-3.115\n*\n* y = logpdf( 1.0 );\n* // returns ~-1.268\n*/\nfunction factory( k ) {\n\tvar km1;\n\tvar kh;\n\n\tif ( isnan( k ) || k < 0.0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tif ( k === 0.0 ) {\n\t\treturn degenerate( 0.0 );\n\t}\n\n\tkh = k / 2.0;\n\tkm1 = k - 1.0;\n\treturn logpdf;\n\n\t/**\n\t* Evaluates the natural logarithm of the probability density function (PDF) for a chi distribution with degrees of freedom `k`.\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( 1.0 );\n\t* // returns <number>\n\t*/\n\tfunction logpdf( x ) {\n\t\tvar out;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x < 0.0 || x === PINF ) {\n\t\t\treturn NINF;\n\t\t}\n\t\tout = ( ( 1.0-kh ) * LN2 ) + ( km1 * ln( x ) ) - ( (x*x) / 2.0 );\n\t\tout -= gammaln( kh );\n\t\treturn out;\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 chi distribution.\n*\n* @module @stdlib/stats-base-dists-chi-logpdf\n*\n* @example\n* var logpdf = require( '@stdlib/stats-base-dists-chi-logpdf' );\n*\n* var y = logpdf( 2.0, 1.0 );\n* // returns ~-2.226\n*\n* @example\n* var factory = require( '@stdlib/stats-base-dists-chi-logpdf' ).factory;\n*\n* var logpdf = factory( 6.0 );\n*\n* var y = logpdf( 3.0 );\n* // returns ~-1.086\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,EAAU,QAAS,mCAAoC,EACvDC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EACjDC,EAAO,QAAS,gCAAiC,EACjDC,EAAM,QAAS,kCAAmC,EAqCtD,SAASC,EAAQC,EAAGC,EAAI,CACvB,IAAIC,EACAC,EACJ,OACCV,EAAOO,CAAE,GACTP,EAAOQ,CAAE,GACTA,EAAI,EAEG,IAEHA,IAAM,EAEDD,IAAM,EAAQH,EAAOD,EAE1BI,EAAI,GAAOA,IAAMH,EACdD,GAERO,EAAKF,EAAI,EACTC,GAAU,EAAIC,GAAOL,GAAYG,EAAE,GAAQN,EAAIK,CAAE,EAASA,EAAEA,EAAK,EACjEE,GAAOR,EAASS,CAAG,EACZD,EACR,CAKAV,EAAO,QAAUO,IC1FjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAa,QAAS,4CAA6C,EAAE,QACrEC,EAAQ,QAAS,iCAAkC,EACnDC,EAAU,QAAS,mCAAoC,EACvDC,EAAK,QAAS,8BAA+B,EAC7CC,EAAO,QAAS,gCAAiC,EACjDC,EAAO,QAAS,gCAAiC,EACjDC,EAAM,QAAS,kCAAmC,EAoBtD,SAASC,EAASC,EAAI,CACrB,IAAIC,EACAC,EAEJ,GAAKT,EAAOO,CAAE,GAAKA,EAAI,EACtB,OAAOT,EAAkB,GAAI,EAE9B,GAAKS,IAAM,EACV,OAAOR,EAAY,CAAI,EAGxB,OAAAU,EAAKF,EAAI,EACTC,EAAMD,EAAI,EACHG,EAaP,SAASA,EAAQC,EAAI,CACpB,IAAIC,EACJ,OAAKZ,EAAOW,CAAE,EACN,IAEHA,EAAI,GAAOA,IAAMP,EACdD,GAERS,GAAU,EAAIH,GAAOJ,EAAUG,EAAMN,EAAIS,CAAE,EAASA,EAAEA,EAAK,EAC3DC,GAAOX,EAASQ,CAAG,EACZG,EACR,CACD,CAKAf,EAAO,QAAUS,IClDjB,IAAIO,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", "gammaln", "ln", "NINF", "PINF", "LN2", "logpdf", "x", "k", "out", "kh", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "degenerate", "isnan", "gammaln", "ln", "NINF", "PINF", "LN2", "factory", "k", "km1", "kh", "logpdf", "x", "out", "setReadOnly", "main", "factory"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -100,11 +100,11 @@ interface LogPDF {
|
|
|
100
100
|
* var mylogpdf = logpdf.factory( 6.0 );
|
|
101
101
|
*
|
|
102
102
|
* y = mylogpdf( 3.0 );
|
|
103
|
-
* // returns ~-1.
|
|
103
|
+
* // returns ~-1.086
|
|
104
104
|
*/
|
|
105
|
-
declare var
|
|
105
|
+
declare var logpdf: LogPDF;
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
// EXPORTS //
|
|
109
109
|
|
|
110
|
-
export =
|
|
110
|
+
export = logpdf;
|
|
@@ -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_CHI_LOGPDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_CHI_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 Chi distribution with degrees of freedom `k` at a value `x`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_chi_logpdf( const double x, const double k );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_CHI_LOGPDF_H
|
package/lib/index.js
CHANGED
package/lib/native.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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 log probability density function (logPDF) for a Chi distribution with degrees of freedom `k` at a value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {number} k - degrees of freedom
|
|
34
|
+
* @returns {number} evaluated logPDF
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var y = logpdf( 0.3, 4.0 );
|
|
38
|
+
* // returns ~-4.35
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var y = logpdf( 0.7, 0.7 );
|
|
42
|
+
* // returns ~-0.622
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var y = logpdf( -1.0, 0.5 );
|
|
46
|
+
* // returns -Infinity
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var y = logpdf( 0.0, NaN );
|
|
50
|
+
* // returns NaN
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* var y = logpdf( NaN, 2.0 );
|
|
54
|
+
* // returns NaN
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Negative degrees of freedom:
|
|
58
|
+
* var y = logpdf( 2.0, -1.0 );
|
|
59
|
+
* // returns NaN
|
|
60
|
+
*/
|
|
61
|
+
function logpdf( x, k ) {
|
|
62
|
+
return addon( x, k );
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// EXPORTS //
|
|
67
|
+
|
|
68
|
+
module.exports = logpdf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
"@stdlib/math-base-special-gammaln",
|
|
45
|
+
"@stdlib/constants-float64-ln-two",
|
|
46
|
+
"@stdlib/constants-float64-pinf",
|
|
47
|
+
"@stdlib/constants-float64-ninf"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"task": "benchmark",
|
|
52
|
+
"wasm": false,
|
|
53
|
+
"src": [
|
|
54
|
+
"./src/main.c"
|
|
55
|
+
],
|
|
56
|
+
"include": [
|
|
57
|
+
"./include"
|
|
58
|
+
],
|
|
59
|
+
"libraries": [],
|
|
60
|
+
"libpath": [],
|
|
61
|
+
"dependencies": [
|
|
62
|
+
"@stdlib/math-base-assert-is-nan",
|
|
63
|
+
"@stdlib/math-base-special-ln",
|
|
64
|
+
"@stdlib/math-base-special-gammaln",
|
|
65
|
+
"@stdlib/constants-float64-ln-two",
|
|
66
|
+
"@stdlib/constants-float64-pinf",
|
|
67
|
+
"@stdlib/constants-float64-ninf"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"task": "examples",
|
|
72
|
+
"wasm": false,
|
|
73
|
+
"src": [
|
|
74
|
+
"./src/main.c"
|
|
75
|
+
],
|
|
76
|
+
"include": [
|
|
77
|
+
"./include"
|
|
78
|
+
],
|
|
79
|
+
"libraries": [],
|
|
80
|
+
"libpath": [],
|
|
81
|
+
"dependencies": [
|
|
82
|
+
"@stdlib/math-base-assert-is-nan",
|
|
83
|
+
"@stdlib/math-base-special-ln",
|
|
84
|
+
"@stdlib/math-base-special-gammaln",
|
|
85
|
+
"@stdlib/constants-float64-ln-two",
|
|
86
|
+
"@stdlib/constants-float64-pinf",
|
|
87
|
+
"@stdlib/constants-float64-ninf"
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-chi-logpdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Natural logarithm of the probability density function (PDF) for a chi 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",
|
|
@@ -30,15 +33,17 @@
|
|
|
30
33
|
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
31
34
|
},
|
|
32
35
|
"dependencies": {
|
|
33
|
-
"@stdlib/constants-float64-ln-two": "^0.2.
|
|
34
|
-
"@stdlib/constants-float64-ninf": "^0.2.
|
|
35
|
-
"@stdlib/constants-float64-pinf": "^0.2.
|
|
36
|
-
"@stdlib/math-base-assert-is-nan": "^0.2.
|
|
37
|
-
"@stdlib/math-base-
|
|
38
|
-
"@stdlib/math-base-special-
|
|
39
|
-
"@stdlib/
|
|
40
|
-
"@stdlib/
|
|
41
|
-
"@stdlib/utils-
|
|
36
|
+
"@stdlib/constants-float64-ln-two": "^0.2.3",
|
|
37
|
+
"@stdlib/constants-float64-ninf": "^0.2.3",
|
|
38
|
+
"@stdlib/constants-float64-pinf": "^0.2.3",
|
|
39
|
+
"@stdlib/math-base-assert-is-nan": "^0.2.3",
|
|
40
|
+
"@stdlib/math-base-napi-binary": "^0.3.3",
|
|
41
|
+
"@stdlib/math-base-special-gammaln": "^0.3.0",
|
|
42
|
+
"@stdlib/math-base-special-ln": "^0.2.5",
|
|
43
|
+
"@stdlib/stats-base-dists-degenerate-logpdf": "^0.3.1",
|
|
44
|
+
"@stdlib/utils-constant-function": "^0.2.3",
|
|
45
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.3",
|
|
46
|
+
"@stdlib/utils-library-manifest": "^0.2.4"
|
|
42
47
|
},
|
|
43
48
|
"devDependencies": {},
|
|
44
49
|
"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/chi/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/binary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_chi_logpdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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/chi/logpdf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/ln.h"
|
|
22
|
+
#include "stdlib/math/base/special/gammaln.h"
|
|
23
|
+
#include "stdlib/constants/float64/ln_two.h"
|
|
24
|
+
#include "stdlib/constants/float64/pinf.h"
|
|
25
|
+
#include "stdlib/constants/float64/ninf.h"
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Evaluates the log probability density function (logPDF) for a Chi distribution with degrees of freedom `k` at a value `x`.
|
|
29
|
+
*
|
|
30
|
+
* @param x input value
|
|
31
|
+
* @param k degrees of freedom
|
|
32
|
+
* @return evaluated logPDF
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* double y = stdlib_base_dists_chi_logpdf( 2.0, 2.0 );
|
|
36
|
+
* // returns ~-1.309
|
|
37
|
+
*/
|
|
38
|
+
double stdlib_base_dists_chi_logpdf( const double x, const double k ) {
|
|
39
|
+
double out;
|
|
40
|
+
double kh;
|
|
41
|
+
if ( stdlib_base_is_nan( x ) || stdlib_base_is_nan( k ) || k < 0.0 ) {
|
|
42
|
+
return 0.0 / 0.0; // NaN
|
|
43
|
+
}
|
|
44
|
+
if ( k == 0.0 ) {
|
|
45
|
+
// Point mass at 0...
|
|
46
|
+
return ( x == 0.0 ) ? STDLIB_CONSTANT_FLOAT64_PINF : STDLIB_CONSTANT_FLOAT64_NINF;
|
|
47
|
+
}
|
|
48
|
+
if ( x < 0.0 || x == STDLIB_CONSTANT_FLOAT64_PINF ) {
|
|
49
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
50
|
+
}
|
|
51
|
+
kh = k / 2.0;
|
|
52
|
+
out = ( ( 1.0 - kh ) * STDLIB_CONSTANT_FLOAT64_LN2 ) + ( ( k - 1.0 ) * stdlib_base_ln( x ) ) - ( ( x * x ) / 2.0 );
|
|
53
|
+
out -= stdlib_base_gammaln( kh );
|
|
54
|
+
return out;
|
|
55
|
+
}
|