@stdlib/stats-base-dists-rayleigh-logcdf 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 +108 -16
- 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/rayleigh/logcdf.h +38 -0
- package/lib/index.js +2 -2
- package/lib/native.js +68 -0
- package/manifest.json +98 -0
- package/package.json +9 -4
- package/src/addon.c +22 -0
- package/src/main.c +59 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -123,7 +123,7 @@ Returns a function for evaluating the logarithm of the [cumulative distribution
|
|
|
123
123
|
|
|
124
124
|
```javascript
|
|
125
125
|
var mylogCDF = logcdf.factory( 0.5 );
|
|
126
|
-
y = mylogCDF( 1.0 );
|
|
126
|
+
var y = mylogCDF( 1.0 );
|
|
127
127
|
// returns ~-0.145
|
|
128
128
|
|
|
129
129
|
y = mylogCDF( 0.5 );
|
|
@@ -151,19 +151,107 @@ y = mylogCDF( 0.5 );
|
|
|
151
151
|
<!-- eslint no-undef: "error" -->
|
|
152
152
|
|
|
153
153
|
```javascript
|
|
154
|
-
var
|
|
154
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
155
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
155
156
|
var logcdf = require( '@stdlib/stats-base-dists-rayleigh-logcdf' );
|
|
156
157
|
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
var
|
|
158
|
+
var opts = {
|
|
159
|
+
'dtype': 'float64'
|
|
160
|
+
};
|
|
161
|
+
var x = uniform( 10, 0.0, 10.0, opts );
|
|
162
|
+
var sigma = uniform( 10, 0.0, 10.0, opts );
|
|
161
163
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
logEachMap( 'x: %0.4f, σ: %0.4f, ln(F(x;σ)): %0.4f', x, sigma, logcdf );
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
</section>
|
|
168
|
+
|
|
169
|
+
<!-- /.examples -->
|
|
170
|
+
|
|
171
|
+
<!-- C interface documentation. -->
|
|
172
|
+
|
|
173
|
+
* * *
|
|
174
|
+
|
|
175
|
+
<section class="c">
|
|
176
|
+
|
|
177
|
+
## C APIs
|
|
178
|
+
|
|
179
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
180
|
+
|
|
181
|
+
<section class="intro">
|
|
182
|
+
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
<!-- /.intro -->
|
|
186
|
+
|
|
187
|
+
<!-- C usage documentation. -->
|
|
188
|
+
|
|
189
|
+
<section class="usage">
|
|
190
|
+
|
|
191
|
+
### Usage
|
|
192
|
+
|
|
193
|
+
```c
|
|
194
|
+
#include "stdlib/stats/base/dists/rayleigh/logcdf.h"
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
#### stdlib_base_dists_rayleigh_logcdf( x, sigma )
|
|
198
|
+
|
|
199
|
+
Evaluates the logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution.
|
|
200
|
+
|
|
201
|
+
```c
|
|
202
|
+
double out = stdlib_base_dists_rayleigh_logcdf( 2.0, 3.0 );
|
|
203
|
+
// returns ~-1.613
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The function accepts the following arguments:
|
|
207
|
+
|
|
208
|
+
- **x**: `[in] double` input value.
|
|
209
|
+
- **sigma**: `[in] double` scale parameter.
|
|
210
|
+
|
|
211
|
+
```c
|
|
212
|
+
double stdlib_base_dists_rayleigh_logcdf( const double x, const double sigma );
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
</section>
|
|
216
|
+
|
|
217
|
+
<!-- /.usage -->
|
|
218
|
+
|
|
219
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
220
|
+
|
|
221
|
+
<section class="notes">
|
|
222
|
+
|
|
223
|
+
</section>
|
|
224
|
+
|
|
225
|
+
<!-- /.notes -->
|
|
226
|
+
|
|
227
|
+
<!-- C API usage examples. -->
|
|
228
|
+
|
|
229
|
+
<section class="examples">
|
|
230
|
+
|
|
231
|
+
### Examples
|
|
232
|
+
|
|
233
|
+
```c
|
|
234
|
+
#include "stdlib/stats/base/dists/rayleigh/logcdf.h"
|
|
235
|
+
#include <stdlib.h>
|
|
236
|
+
#include <stdio.h>
|
|
237
|
+
|
|
238
|
+
static double random_uniform( const double min, const double max ) {
|
|
239
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
240
|
+
return min + ( v*(max-min) );
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
int main( void ) {
|
|
244
|
+
double sigma;
|
|
245
|
+
double x;
|
|
246
|
+
double y;
|
|
247
|
+
int i;
|
|
248
|
+
|
|
249
|
+
for ( i = 0; i < 25; i++ ) {
|
|
250
|
+
x = random_uniform( 0.0, 10.0 );
|
|
251
|
+
sigma = random_uniform( 0.0, 10.0 );
|
|
252
|
+
y = stdlib_base_dists_rayleigh_logcdf( x, sigma );
|
|
253
|
+
printf( "x: %lf, σ: %lf, ln(F(x;σ)): %lf\n", x, sigma, y );
|
|
254
|
+
}
|
|
167
255
|
}
|
|
168
256
|
```
|
|
169
257
|
|
|
@@ -171,6 +259,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
171
259
|
|
|
172
260
|
<!-- /.examples -->
|
|
173
261
|
|
|
262
|
+
</section>
|
|
263
|
+
|
|
264
|
+
<!-- /.c -->
|
|
265
|
+
|
|
174
266
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
175
267
|
|
|
176
268
|
<section class="related">
|
|
@@ -205,7 +297,7 @@ See [LICENSE][stdlib-license].
|
|
|
205
297
|
|
|
206
298
|
## Copyright
|
|
207
299
|
|
|
208
|
-
Copyright © 2016-
|
|
300
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
209
301
|
|
|
210
302
|
</section>
|
|
211
303
|
|
|
@@ -218,8 +310,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
218
310
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-rayleigh-logcdf.svg
|
|
219
311
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-rayleigh-logcdf
|
|
220
312
|
|
|
221
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-rayleigh-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
222
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-rayleigh-logcdf/actions/workflows/test.yml?query=branch:v0.
|
|
313
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-rayleigh-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
314
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-rayleigh-logcdf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
223
315
|
|
|
224
316
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-rayleigh-logcdf/main.svg
|
|
225
317
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-rayleigh-logcdf?branch=main
|
|
@@ -231,8 +323,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
231
323
|
|
|
232
324
|
-->
|
|
233
325
|
|
|
234
|
-
[chat-image]: https://img.shields.io/
|
|
235
|
-
[chat-url]: https://
|
|
326
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
327
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
236
328
|
|
|
237
329
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
238
330
|
|
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 logcdf from '../docs/types/index';
|
|
3
|
+
export = logcdf;
|
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 expm1 = require( '@stdlib/math-base-special-expm1' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar LNHALF = require( '@stdlib/constants-float64-ln-half' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma` at a value `x`.\n*\n* @param {number} x - input value\n* @param {NonNegativeNumber} sigma - scale parameter\n* @returns {number} evaluated logCDF\n*\n* @example\n* var y = logcdf( 2.0, 3.0 );\n* // returns ~-1.613\n*\n* @example\n* var y = logcdf( 1.0, 2.0 );\n* // returns ~-2.141\n*\n* @example\n* var y = logcdf( -1.0, 4.0 );\n* // returns -Infinity\n*\n* @example\n* var y = logcdf( NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logcdf( 0.0, NaN );\n* // returns NaN\n*\n* @example\n* // Negative scale parameter:\n* var y = logcdf( 2.0, -1.0 );\n* // returns NaN\n*/\nfunction logcdf( x, sigma ) {\n\tvar s2;\n\tvar p;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( sigma ) ||\n\t\tsigma < 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( sigma === 0.0 ) {\n\t\treturn ( x < 0.0 ) ? NINF : 0.0;\n\t}\n\tif ( x < 0.0 ) {\n\t\treturn NINF;\n\t}\n\ts2 = pow( sigma, 2.0 );\n\tp = -pow( x, 2.0 ) / ( 2.0 * s2 );\n\treturn ( p < LNHALF ) ? log1p( -exp( p ) ) : ln( -expm1( p ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = logcdf;\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-logcdf' ).factory;\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar LNHALF = require( '@stdlib/constants-float64-ln-half' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma`.\n*\n* @param {NonNegativeNumber} sigma - scale parameter\n* @returns {Function} logCDF\n*\n* @example\n* var logcdf = factory( 2.0 );\n* var y = logcdf( 3.0 );\n* // returns ~-0.393\n*\n* y = logcdf( 1.0 );\n* // returns ~-2.141\n*/\nfunction factory( sigma ) {\n\tvar s2;\n\tif ( isnan( sigma ) || sigma < 0.0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tif ( sigma === 0.0 ) {\n\t\treturn degenerate( 0.0 );\n\t}\n\ts2 = pow( sigma, 2.0 );\n\treturn logcdf;\n\n\t/**\n\t* Evaluates the logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logCDF\n\t*\n\t* @example\n\t* var y = logcdf( 2 );\n\t* // returns <number>\n\t*/\n\tfunction logcdf( x ) {\n\t\tvar p;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x < 0.0 ) {\n\t\t\treturn NINF;\n\t\t}\n\t\tp = -pow( x, 2.0 ) / ( 2.0 * s2 );\n\t\treturn ( p < LNHALF ) ? log1p( -exp( p ) ) : ln( -expm1( p ) );\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* Rayleigh distribution logarithm of cumulative distribution function (CDF).\n*\n* @module @stdlib/stats-base-dists-rayleigh-logcdf\n*\n* @example\n* var logcdf = require( '@stdlib/stats-base-dists-rayleigh-logcdf' );\n*\n* var y = logcdf( 2.0, 5.0 );\n* // returns ~-2.
|
|
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 expm1 = require( '@stdlib/math-base-special-expm1' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar LNHALF = require( '@stdlib/constants-float64-ln-half' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Evaluates the logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma` at a value `x`.\n*\n* @param {number} x - input value\n* @param {NonNegativeNumber} sigma - scale parameter\n* @returns {number} evaluated logCDF\n*\n* @example\n* var y = logcdf( 2.0, 3.0 );\n* // returns ~-1.613\n*\n* @example\n* var y = logcdf( 1.0, 2.0 );\n* // returns ~-2.141\n*\n* @example\n* var y = logcdf( -1.0, 4.0 );\n* // returns -Infinity\n*\n* @example\n* var y = logcdf( NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logcdf( 0.0, NaN );\n* // returns NaN\n*\n* @example\n* // Negative scale parameter:\n* var y = logcdf( 2.0, -1.0 );\n* // returns NaN\n*/\nfunction logcdf( x, sigma ) {\n\tvar s2;\n\tvar p;\n\tif (\n\t\tisnan( x ) ||\n\t\tisnan( sigma ) ||\n\t\tsigma < 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( sigma === 0.0 ) {\n\t\treturn ( x < 0.0 ) ? NINF : 0.0;\n\t}\n\tif ( x < 0.0 ) {\n\t\treturn NINF;\n\t}\n\ts2 = pow( sigma, 2.0 );\n\tp = -pow( x, 2.0 ) / ( 2.0 * s2 );\n\treturn ( p < LNHALF ) ? log1p( -exp( p ) ) : ln( -expm1( p ) );\n}\n\n\n// EXPORTS //\n\nmodule.exports = logcdf;\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-logcdf' ).factory;\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\nvar isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar log1p = require( '@stdlib/math-base-special-log1p' );\nvar exp = require( '@stdlib/math-base-special-exp' );\nvar pow = require( '@stdlib/math-base-special-pow' );\nvar ln = require( '@stdlib/math-base-special-ln' );\nvar LNHALF = require( '@stdlib/constants-float64-ln-half' );\nvar NINF = require( '@stdlib/constants-float64-ninf' );\n\n\n// MAIN //\n\n/**\n* Returns a function for evaluating the logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma`.\n*\n* @param {NonNegativeNumber} sigma - scale parameter\n* @returns {Function} logCDF\n*\n* @example\n* var logcdf = factory( 2.0 );\n* var y = logcdf( 3.0 );\n* // returns ~-0.393\n*\n* y = logcdf( 1.0 );\n* // returns ~-2.141\n*/\nfunction factory( sigma ) {\n\tvar s2;\n\tif ( isnan( sigma ) || sigma < 0.0 ) {\n\t\treturn constantFunction( NaN );\n\t}\n\tif ( sigma === 0.0 ) {\n\t\treturn degenerate( 0.0 );\n\t}\n\ts2 = pow( sigma, 2.0 );\n\treturn logcdf;\n\n\t/**\n\t* Evaluates the logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution.\n\t*\n\t* @private\n\t* @param {number} x - input value\n\t* @returns {number} evaluated logCDF\n\t*\n\t* @example\n\t* var y = logcdf( 2 );\n\t* // returns <number>\n\t*/\n\tfunction logcdf( x ) {\n\t\tvar p;\n\t\tif ( isnan( x ) ) {\n\t\t\treturn NaN;\n\t\t}\n\t\tif ( x < 0.0 ) {\n\t\t\treturn NINF;\n\t\t}\n\t\tp = -pow( x, 2.0 ) / ( 2.0 * s2 );\n\t\treturn ( p < LNHALF ) ? log1p( -exp( p ) ) : ln( -expm1( p ) );\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* Rayleigh distribution logarithm of cumulative distribution function (CDF).\n*\n* @module @stdlib/stats-base-dists-rayleigh-logcdf\n*\n* @example\n* var logcdf = require( '@stdlib/stats-base-dists-rayleigh-logcdf' );\n*\n* var y = logcdf( 2.0, 5.0 );\n* // returns ~-2.565\n*\n* var mylogcdf = logcdf.factory( 0.5 );\n* y = mylogcdf( 1.0 );\n* // returns ~-0.145\n*\n* y = mylogcdf( 0.5 );\n* // returns ~-0.933\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,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAS,QAAS,mCAAoC,EACtDC,EAAO,QAAS,gCAAiC,EAqCrD,SAASC,EAAQC,EAAGC,EAAQ,CAC3B,IAAIC,EACAC,EACJ,OACCX,EAAOQ,CAAE,GACTR,EAAOS,CAAM,GACbA,EAAQ,EAED,IAEHA,IAAU,EACLD,EAAI,EAAQF,EAAO,EAExBE,EAAI,EACDF,GAERI,EAAKP,EAAKM,EAAO,CAAI,EACrBE,EAAI,CAACR,EAAKK,EAAG,CAAI,GAAM,EAAME,GACpBC,EAAIN,EAAWJ,EAAO,CAACC,EAAKS,CAAE,CAAE,EAAIP,EAAI,CAACL,EAAOY,CAAE,CAAE,EAC9D,CAKAb,EAAO,QAAUS,IC1FjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,EAAa,QAAS,4CAA6C,EAAE,QACrEC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAQ,QAAS,iCAAkC,EACnDC,EAAM,QAAS,+BAAgC,EAC/CC,EAAM,QAAS,+BAAgC,EAC/CC,EAAK,QAAS,8BAA+B,EAC7CC,EAAS,QAAS,mCAAoC,EACtDC,EAAO,QAAS,gCAAiC,EAmBrD,SAASC,EAASC,EAAQ,CACzB,IAAIC,EACJ,GAAKT,EAAOQ,CAAM,GAAKA,EAAQ,EAC9B,OAAOX,EAAkB,GAAI,EAE9B,GAAKW,IAAU,EACd,OAAOV,EAAY,CAAI,EAExB,OAAAW,EAAKN,EAAKK,EAAO,CAAI,EACdE,EAaP,SAASA,EAAQC,EAAI,CACpB,IAAIC,EACJ,OAAKZ,EAAOW,CAAE,EACN,IAEHA,EAAI,EACDL,GAERM,EAAI,CAACT,EAAKQ,EAAG,CAAI,GAAM,EAAMF,GACpBG,EAAIP,EAAWJ,EAAO,CAACC,EAAKU,CAAE,CAAE,EAAIR,EAAI,CAACL,EAAOa,CAAE,CAAE,EAC9D,CACD,CAKAhB,EAAO,QAAUW,IC/CjB,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", "expm1", "isnan", "log1p", "exp", "pow", "ln", "LNHALF", "NINF", "logcdf", "x", "sigma", "s2", "p", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "degenerate", "expm1", "isnan", "log1p", "exp", "pow", "ln", "LNHALF", "NINF", "factory", "sigma", "s2", "logcdf", "x", "p", "setReadOnly", "main", "factory"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -94,18 +94,18 @@ interface LogCDF {
|
|
|
94
94
|
*
|
|
95
95
|
* @example
|
|
96
96
|
* var y = logcdf( 2.0, 5.0 );
|
|
97
|
-
* // returns ~-2.
|
|
97
|
+
* // returns ~-2.565
|
|
98
98
|
*
|
|
99
99
|
* var mylogcdf = logcdf.factory( 0.5 );
|
|
100
100
|
* y = mylogcdf( 1.0 );
|
|
101
101
|
* // returns ~-0.145
|
|
102
102
|
*
|
|
103
103
|
* y = mylogcdf( 0.5 );
|
|
104
|
-
* // returns ~-0.
|
|
104
|
+
* // returns ~-0.933
|
|
105
105
|
*/
|
|
106
|
-
declare var
|
|
106
|
+
declare var logcdf: LogCDF;
|
|
107
107
|
|
|
108
108
|
|
|
109
109
|
// EXPORTS //
|
|
110
110
|
|
|
111
|
-
export =
|
|
111
|
+
export = logcdf;
|
|
@@ -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_RAYLEIGH_LOGCDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_RAYLEIGH_LOGCDF_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 logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma` at a value `x`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_rayleigh_logcdf( const double x, const double sigma );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_RAYLEIGH_LOGCDF_H
|
package/lib/index.js
CHANGED
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
* var logcdf = require( '@stdlib/stats-base-dists-rayleigh-logcdf' );
|
|
28
28
|
*
|
|
29
29
|
* var y = logcdf( 2.0, 5.0 );
|
|
30
|
-
* // returns ~-2.
|
|
30
|
+
* // returns ~-2.565
|
|
31
31
|
*
|
|
32
32
|
* var mylogcdf = logcdf.factory( 0.5 );
|
|
33
33
|
* y = mylogcdf( 1.0 );
|
|
34
34
|
* // returns ~-0.145
|
|
35
35
|
*
|
|
36
36
|
* y = mylogcdf( 0.5 );
|
|
37
|
-
* // returns ~-0.
|
|
37
|
+
* // returns ~-0.933
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
40
|
// MODULES //
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
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 logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma` at a value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {NonNegativeNumber} sigma - scale parameter
|
|
34
|
+
* @returns {number} evaluated logCDF
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* var y = logcdf( 2.0, 3.0 );
|
|
38
|
+
* // returns ~-1.613
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* var y = logcdf( 1.0, 2.0 );
|
|
42
|
+
* // returns ~-2.141
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* var y = logcdf( -1.0, 4.0 );
|
|
46
|
+
* // returns -Infinity
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* var y = logcdf( NaN, 1.0 );
|
|
50
|
+
* // returns NaN
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* var y = logcdf( 0.0, NaN );
|
|
54
|
+
* // returns NaN
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Negative scale parameter:
|
|
58
|
+
* var y = logcdf( 2.0, -1.0 );
|
|
59
|
+
* // returns NaN
|
|
60
|
+
*/
|
|
61
|
+
function logcdf( x, sigma ) {
|
|
62
|
+
return addon( x, sigma );
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// EXPORTS //
|
|
67
|
+
|
|
68
|
+
module.exports = logcdf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
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-special-expm1",
|
|
43
|
+
"@stdlib/math-base-assert-is-nan",
|
|
44
|
+
"@stdlib/math-base-special-log1p",
|
|
45
|
+
"@stdlib/math-base-special-exp",
|
|
46
|
+
"@stdlib/math-base-special-pow",
|
|
47
|
+
"@stdlib/math-base-special-ln",
|
|
48
|
+
"@stdlib/constants-float64-ln-half",
|
|
49
|
+
"@stdlib/constants-float64-ninf"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"task": "benchmark",
|
|
54
|
+
"wasm": false,
|
|
55
|
+
"src": [
|
|
56
|
+
"./src/main.c"
|
|
57
|
+
],
|
|
58
|
+
"include": [
|
|
59
|
+
"./include"
|
|
60
|
+
],
|
|
61
|
+
"libraries": [],
|
|
62
|
+
"libpath": [],
|
|
63
|
+
"dependencies": [
|
|
64
|
+
"@stdlib/constants-float64-eps",
|
|
65
|
+
"@stdlib/math-base-special-expm1",
|
|
66
|
+
"@stdlib/math-base-assert-is-nan",
|
|
67
|
+
"@stdlib/math-base-special-log1p",
|
|
68
|
+
"@stdlib/math-base-special-exp",
|
|
69
|
+
"@stdlib/math-base-special-pow",
|
|
70
|
+
"@stdlib/math-base-special-ln",
|
|
71
|
+
"@stdlib/constants-float64-ln-half",
|
|
72
|
+
"@stdlib/constants-float64-ninf"
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"task": "examples",
|
|
77
|
+
"wasm": false,
|
|
78
|
+
"src": [
|
|
79
|
+
"./src/main.c"
|
|
80
|
+
],
|
|
81
|
+
"include": [
|
|
82
|
+
"./include"
|
|
83
|
+
],
|
|
84
|
+
"libraries": [],
|
|
85
|
+
"libpath": [],
|
|
86
|
+
"dependencies": [
|
|
87
|
+
"@stdlib/math-base-special-expm1",
|
|
88
|
+
"@stdlib/math-base-assert-is-nan",
|
|
89
|
+
"@stdlib/math-base-special-log1p",
|
|
90
|
+
"@stdlib/math-base-special-exp",
|
|
91
|
+
"@stdlib/math-base-special-pow",
|
|
92
|
+
"@stdlib/math-base-special-ln",
|
|
93
|
+
"@stdlib/constants-float64-ln-half",
|
|
94
|
+
"@stdlib/constants-float64-ninf"
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-rayleigh-logcdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Rayleigh distribution logarithm of cumulative distribution function (CDF).",
|
|
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",
|
|
@@ -33,14 +36,16 @@
|
|
|
33
36
|
"@stdlib/constants-float64-ln-half": "^0.2.2",
|
|
34
37
|
"@stdlib/constants-float64-ninf": "^0.2.2",
|
|
35
38
|
"@stdlib/math-base-assert-is-nan": "^0.2.2",
|
|
36
|
-
"@stdlib/math-base-
|
|
39
|
+
"@stdlib/math-base-napi-binary": "^0.3.1",
|
|
40
|
+
"@stdlib/math-base-special-exp": "^0.2.4",
|
|
37
41
|
"@stdlib/math-base-special-expm1": "^0.2.3",
|
|
38
42
|
"@stdlib/math-base-special-ln": "^0.2.4",
|
|
39
43
|
"@stdlib/math-base-special-log1p": "^0.2.3",
|
|
40
44
|
"@stdlib/math-base-special-pow": "^0.3.0",
|
|
41
|
-
"@stdlib/stats-base-dists-degenerate-logcdf": "^0.
|
|
45
|
+
"@stdlib/stats-base-dists-degenerate-logcdf": "^0.3.0",
|
|
42
46
|
"@stdlib/utils-constant-function": "^0.2.2",
|
|
43
|
-
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
|
|
47
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
48
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
44
49
|
},
|
|
45
50
|
"devDependencies": {},
|
|
46
51
|
"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/stats/base/dists/rayleigh/logcdf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/binary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DD_D( stdlib_base_dists_rayleigh_logcdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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/rayleigh/logcdf.h"
|
|
20
|
+
#include "stdlib/math/base/special/expm1.h"
|
|
21
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
22
|
+
#include "stdlib/math/base/special/log1p.h"
|
|
23
|
+
#include "stdlib/math/base/special/exp.h"
|
|
24
|
+
#include "stdlib/math/base/special/pow.h"
|
|
25
|
+
#include "stdlib/math/base/special/ln.h"
|
|
26
|
+
#include "stdlib/constants/float64/ln_half.h"
|
|
27
|
+
#include "stdlib/constants/float64/ninf.h"
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Evaluates the logarithm of the cumulative distribution function (CDF) for a Rayleigh distribution with scale parameter `sigma` at a value `x`.
|
|
31
|
+
*
|
|
32
|
+
* @param x input value
|
|
33
|
+
* @param sigma scale parameter
|
|
34
|
+
* @return evaluated logCDF
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* double y = stdlib_base_dists_rayleigh_logcdf( 2.0, 3.0 );
|
|
38
|
+
* // returns ~-1.613
|
|
39
|
+
*/
|
|
40
|
+
double stdlib_base_dists_rayleigh_logcdf( const double x, const double sigma ) {
|
|
41
|
+
double s2;
|
|
42
|
+
double p;
|
|
43
|
+
if (
|
|
44
|
+
stdlib_base_is_nan( x ) ||
|
|
45
|
+
stdlib_base_is_nan( sigma ) ||
|
|
46
|
+
sigma < 0.0
|
|
47
|
+
) {
|
|
48
|
+
return 0.0/0.0; // NaN
|
|
49
|
+
}
|
|
50
|
+
if ( sigma == 0.0 ) {
|
|
51
|
+
return ( x < 0.0 ) ? STDLIB_CONSTANT_FLOAT64_NINF : 0.0;
|
|
52
|
+
}
|
|
53
|
+
if ( x < 0.0 ) {
|
|
54
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
55
|
+
}
|
|
56
|
+
s2 = stdlib_base_pow( sigma, 2.0 );
|
|
57
|
+
p = -stdlib_base_pow( x, 2.0 ) / ( 2.0 * s2 );
|
|
58
|
+
return ( p < STDLIB_CONSTANT_FLOAT64_LN_HALF ) ? stdlib_base_log1p( -stdlib_base_exp( p ) ) : stdlib_base_ln( - stdlib_base_expm1( p ) );
|
|
59
|
+
}
|