@stdlib/stats-base-dists-weibull-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 +114 -20
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/docs/types/index.d.ts +9 -9
- package/include/stdlib/stats/base/dists/weibull/logcdf.h +38 -0
- package/lib/factory.js +2 -2
- package/lib/main.js +3 -3
- package/lib/native.js +76 -0
- package/manifest.json +101 -0
- package/package.json +8 -3
- package/src/addon.c +22 -0
- package/src/main.c +56 -0
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ The [cumulative distribution function][cdf] for a [Weibull][weibull-distribution
|
|
|
48
48
|
|
|
49
49
|
<!-- </equation> -->
|
|
50
50
|
|
|
51
|
-
where `lambda > 0` is the [
|
|
51
|
+
where `lambda > 0` is the [scale parameter][scale] and `k > 0` is the [shape parameter][shape].
|
|
52
52
|
|
|
53
53
|
</section>
|
|
54
54
|
|
|
@@ -125,7 +125,7 @@ y = logcdf( 2.0, 0.5, 0.0 );
|
|
|
125
125
|
|
|
126
126
|
#### logcdf.factory( k, lambda )
|
|
127
127
|
|
|
128
|
-
Returns a function for evaluating the [cumulative distribution function][cdf] of a [Weibull][weibull-distribution] distribution with [shape parameter][shape] `k` and [scale parameter][scale] `lambda`.
|
|
128
|
+
Returns a function for evaluating the [cumulative distribution function][cdf] of a [Weibull][weibull-distribution] distribution with [shape parameter][shape] `k` and [scale parameter][scale] `lambda`.
|
|
129
129
|
|
|
130
130
|
```javascript
|
|
131
131
|
var mylogcdf = logcdf.factory( 2.0, 10.0 );
|
|
@@ -158,21 +158,111 @@ y = mylogcdf( 8.0 );
|
|
|
158
158
|
<!-- eslint no-undef: "error" -->
|
|
159
159
|
|
|
160
160
|
```javascript
|
|
161
|
-
var
|
|
161
|
+
var uniform = require( '@stdlib/random-array-uniform' );
|
|
162
|
+
var logEachMap = require( '@stdlib/console-log-each-map' );
|
|
162
163
|
var logcdf = require( '@stdlib/stats-base-dists-weibull-logcdf' );
|
|
163
164
|
|
|
164
|
-
var
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
var
|
|
168
|
-
var
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
165
|
+
var opts = {
|
|
166
|
+
'dtype': 'float64'
|
|
167
|
+
};
|
|
168
|
+
var lambda = uniform( 10, 0.0, 10.0, opts );
|
|
169
|
+
var k = uniform( 10, 0.0, 10.0, opts );
|
|
170
|
+
var x = uniform( 10, 0.0, 10.0, opts );
|
|
171
|
+
|
|
172
|
+
logEachMap( 'x: %0.4f, k: %0.4f, λ: %0.4f, ln(F(x;k,λ)): %0.4f', x, k, lambda, logcdf );
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
</section>
|
|
176
|
+
|
|
177
|
+
<!-- /.examples -->
|
|
178
|
+
|
|
179
|
+
<!-- C interface documentation. -->
|
|
180
|
+
|
|
181
|
+
* * *
|
|
182
|
+
|
|
183
|
+
<section class="c">
|
|
184
|
+
|
|
185
|
+
## C APIs
|
|
186
|
+
|
|
187
|
+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
|
|
188
|
+
|
|
189
|
+
<section class="intro">
|
|
190
|
+
|
|
191
|
+
</section>
|
|
192
|
+
|
|
193
|
+
<!-- /.intro -->
|
|
194
|
+
|
|
195
|
+
<!-- C usage documentation. -->
|
|
196
|
+
|
|
197
|
+
<section class="usage">
|
|
198
|
+
|
|
199
|
+
### Usage
|
|
200
|
+
|
|
201
|
+
```c
|
|
202
|
+
#include "stdlib/stats/base/dists/weibull/logcdf.h"
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### stdlib_base_dists_weibull_logcdf( x, k, lambda )
|
|
206
|
+
|
|
207
|
+
Evaluates the natural logarithm of the [cumulative distribution function][cdf] (CDF) for a [Weibull][weibull-distribution] distribution with [shape parameter][shape] `k` and [scale parameter][scale] `lambda`.
|
|
208
|
+
|
|
209
|
+
```c
|
|
210
|
+
double out = stdlib_base_dists_weibull_logcdf( 2.0, 1.0, 1.0 );
|
|
211
|
+
// returns ~-0.145
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
The function accepts the following arguments:
|
|
215
|
+
|
|
216
|
+
- **x**: `[in] double` input value.
|
|
217
|
+
- **k**: `[in] double` shape parameter.
|
|
218
|
+
- **lambda**: `[in] double` scale parameter.
|
|
219
|
+
|
|
220
|
+
```c
|
|
221
|
+
double stdlib_base_dists_weibull_logcdf( const double x, const double k, const double lambda );
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
</section>
|
|
225
|
+
|
|
226
|
+
<!-- /.usage -->
|
|
227
|
+
|
|
228
|
+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
|
|
229
|
+
|
|
230
|
+
<section class="notes">
|
|
231
|
+
|
|
232
|
+
</section>
|
|
233
|
+
|
|
234
|
+
<!-- /.notes -->
|
|
235
|
+
|
|
236
|
+
<!-- C API usage examples. -->
|
|
237
|
+
|
|
238
|
+
<section class="examples">
|
|
239
|
+
|
|
240
|
+
### Examples
|
|
241
|
+
|
|
242
|
+
```c
|
|
243
|
+
#include "stdlib/stats/base/dists/weibull/logcdf.h"
|
|
244
|
+
#include <stdlib.h>
|
|
245
|
+
#include <stdio.h>
|
|
246
|
+
|
|
247
|
+
static double random_uniform( const double min, const double max ) {
|
|
248
|
+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
|
|
249
|
+
return min + ( v*(max-min) );
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
int main( void ) {
|
|
253
|
+
double lambda;
|
|
254
|
+
double x;
|
|
255
|
+
double k;
|
|
256
|
+
double y;
|
|
257
|
+
int i;
|
|
258
|
+
|
|
259
|
+
for ( i = 0; i < 25; i++ ) {
|
|
260
|
+
x = random_uniform( 0.0, 10.0 );
|
|
261
|
+
lambda = random_uniform( 0.0, 10.0 );
|
|
262
|
+
k = random_uniform( 0.0, 10.0 );
|
|
263
|
+
y = stdlib_base_dists_weibull_logcdf( x, k, lambda );
|
|
264
|
+
printf( "x: %lf, k: %lf, λ: %lf, ln(F(x;k,λ)): %lf\n", x, k, lambda, y );
|
|
265
|
+
}
|
|
176
266
|
}
|
|
177
267
|
```
|
|
178
268
|
|
|
@@ -180,6 +270,10 @@ for ( i = 0; i < 10; i++ ) {
|
|
|
180
270
|
|
|
181
271
|
<!-- /.examples -->
|
|
182
272
|
|
|
273
|
+
</section>
|
|
274
|
+
|
|
275
|
+
<!-- /.c -->
|
|
276
|
+
|
|
183
277
|
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
|
|
184
278
|
|
|
185
279
|
<section class="related">
|
|
@@ -214,7 +308,7 @@ See [LICENSE][stdlib-license].
|
|
|
214
308
|
|
|
215
309
|
## Copyright
|
|
216
310
|
|
|
217
|
-
Copyright © 2016-
|
|
311
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
218
312
|
|
|
219
313
|
</section>
|
|
220
314
|
|
|
@@ -227,8 +321,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
227
321
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-weibull-logcdf.svg
|
|
228
322
|
[npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-weibull-logcdf
|
|
229
323
|
|
|
230
|
-
[test-image]: https://github.com/stdlib-js/stats-base-dists-weibull-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.
|
|
231
|
-
[test-url]: https://github.com/stdlib-js/stats-base-dists-weibull-logcdf/actions/workflows/test.yml?query=branch:v0.
|
|
324
|
+
[test-image]: https://github.com/stdlib-js/stats-base-dists-weibull-logcdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
|
|
325
|
+
[test-url]: https://github.com/stdlib-js/stats-base-dists-weibull-logcdf/actions/workflows/test.yml?query=branch:v0.3.0
|
|
232
326
|
|
|
233
327
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-weibull-logcdf/main.svg
|
|
234
328
|
[coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-weibull-logcdf?branch=main
|
|
@@ -240,8 +334,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
240
334
|
|
|
241
335
|
-->
|
|
242
336
|
|
|
243
|
-
[chat-image]: https://img.shields.io/
|
|
244
|
-
[chat-url]: https://
|
|
337
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
338
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
245
339
|
|
|
246
340
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
247
341
|
|
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 isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\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 natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution with
|
|
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 expm1 = require( '@stdlib/math-base-special-expm1' );\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 natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution with shape parameter `k` and scale parameter `lambda` at a value `x`.\n*\n* @param {number} x - input value\n* @param {PositiveNumber} k - shape parameter\n* @param {PositiveNumber} lambda - scale parameter\n* @returns {number} natural logarithm of CDF\n*\n* @example\n* var y = logcdf( 2.0, 1.0, 1.0 );\n* // returns ~-0.145\n*\n* @example\n* var y = logcdf( -1.0, 2.0, 2.0 );\n* // returns -Infinity\n*\n* @example\n* var y = logcdf( +Infinity, 4.0, 2.0 );\n* // returns 0.0\n*\n* @example\n* var y = logcdf( -Infinity, 4.0, 2.0 );\n* // returns -Infinity\n*\n* @example\n* var y = logcdf( NaN, 0.0, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logcdf( 0.0, NaN, 1.0 );\n* // returns NaN\n*\n* @example\n* var y = logcdf( 0.0, 0.0, NaN );\n* // returns NaN\n*\n* @example\n* var y = logcdf( 2.0, 0.0, -1.0 );\n* // returns NaN\n*/\nfunction logcdf( x, k, lambda ) {\n\tvar p;\n\tif (\n\t\tisnan( k ) ||\n\t\tisnan( lambda ) ||\n\t\tk <= 0.0 ||\n\t\tlambda <= 0.0\n\t) {\n\t\treturn NaN;\n\t}\n\tif ( x < 0.0 ) {\n\t\treturn NINF;\n\t}\n\tp = -pow( x / lambda, k );\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 isnan = require( '@stdlib/math-base-assert-is-nan' );\nvar expm1 = require( '@stdlib/math-base-special-expm1' );\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 natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution.\n*\n* @param {PositiveNumber} k - shape parameter\n* @param {PositiveNumber} lambda - scale parameter\n* @returns {Function} logCDF\n*\n* @example\n* var logcdf = factory( 2.0, 10.0 );\n* var y = logcdf( 12.0 );\n* // returns ~-0.27\n*\n* y = logcdf( 8.0 );\n* // returns ~-0.749\n*/\nfunction factory( k, lambda ) {\n\tif (\n\t\tisnan( k ) ||\n\t\tisnan( lambda ) ||\n\t\tk <= 0.0 ||\n\t\tlambda <= 0.0\n\t) {\n\t\treturn constantFunction( NaN );\n\t}\n\treturn logcdf;\n\n\t/**\n\t* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Weibull 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.0 );\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 / lambda, k );\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* Weibull distribution logarithm of cumulative distribution function (CDF).\n*\n* @module @stdlib/stats-base-dists-weibull-logcdf\n*\n* @example\n* var logcdf = require( '@stdlib/stats-base-dists-weibull-logcdf' );\n*\n* var y = logcdf( 2.0, 1.0, 1.0 );\n* // returns ~-0.145\n*\n* var mylogcdf = logcdf.factory( 2.0, 10.0 );\n* y = mylogcdf( 12.0 );\n* // returns ~-0.27\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,EA6CrD,SAASC,EAAQC,EAAGC,EAAGC,EAAS,CAC/B,IAAIC,EACJ,OACCZ,EAAOU,CAAE,GACTV,EAAOW,CAAO,GACdD,GAAK,GACLC,GAAU,EAEH,IAEHF,EAAI,EACDF,GAERK,EAAI,CAACR,EAAKK,EAAIE,EAAQD,CAAE,EACfE,EAAIN,EAAWJ,EAAO,CAACC,EAAKS,CAAE,CAAE,EAAIP,EAAI,CAACJ,EAAOW,CAAE,CAAE,EAC9D,CAKAb,EAAO,QAAUS,IC9FjB,IAAAK,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,iCAAkC,EAC9DC,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,EAoBrD,SAASC,EAASC,EAAGC,EAAS,CAC7B,GACCV,EAAOS,CAAE,GACTT,EAAOU,CAAO,GACdD,GAAK,GACLC,GAAU,EAEV,OAAOX,EAAkB,GAAI,EAE9B,OAAOY,EAaP,SAASA,EAAQC,EAAI,CACpB,IAAIC,EACJ,OAAKb,EAAOY,CAAE,EACN,IAEHA,EAAI,EACDL,GAERM,EAAI,CAACT,EAAKQ,EAAIF,EAAQD,CAAE,EACfI,EAAIP,EAAWJ,EAAO,CAACC,EAAKU,CAAE,CAAE,EAAIR,EAAI,CAACJ,EAAOY,CAAE,CAAE,EAC9D,CACD,CAKAf,EAAO,QAAUU,IClDjB,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", "expm1", "log1p", "exp", "pow", "ln", "LNHALF", "NINF", "logcdf", "x", "k", "lambda", "p", "require_factory", "__commonJSMin", "exports", "module", "constantFunction", "isnan", "expm1", "log1p", "exp", "pow", "ln", "LNHALF", "NINF", "factory", "k", "lambda", "logcdf", "x", "p", "setReadOnly", "main", "factory"]
|
|
7
7
|
}
|
package/docs/types/index.d.ts
CHANGED
|
@@ -31,15 +31,15 @@ type Unary = ( x: number ) => number;
|
|
|
31
31
|
*/
|
|
32
32
|
interface LogCDF {
|
|
33
33
|
/**
|
|
34
|
-
* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution with
|
|
34
|
+
* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution with shape parameter `k` and scale parameter `lambda` at a value `x`.
|
|
35
35
|
*
|
|
36
36
|
* ## Notes
|
|
37
37
|
*
|
|
38
38
|
* - If provided a non-positive value for `lambda` or `k`, the function returns `NaN`.
|
|
39
39
|
*
|
|
40
40
|
* @param x - input value
|
|
41
|
-
* @param k -
|
|
42
|
-
* @param lambda -
|
|
41
|
+
* @param k - shape parameter
|
|
42
|
+
* @param lambda - scale parameter
|
|
43
43
|
* @returns natural logarithm of CDF
|
|
44
44
|
*
|
|
45
45
|
* @example
|
|
@@ -79,8 +79,8 @@ interface LogCDF {
|
|
|
79
79
|
/**
|
|
80
80
|
* Returns a function for evaluating the natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution.
|
|
81
81
|
*
|
|
82
|
-
* @param k -
|
|
83
|
-
* @param lambda -
|
|
82
|
+
* @param k - shape parameter
|
|
83
|
+
* @param lambda - scale parameter
|
|
84
84
|
* @returns logCDF
|
|
85
85
|
*
|
|
86
86
|
* @example
|
|
@@ -98,8 +98,8 @@ interface LogCDF {
|
|
|
98
98
|
* Weibull distribution logarithm of cumulative distribution function (CDF).
|
|
99
99
|
*
|
|
100
100
|
* @param x - input value
|
|
101
|
-
* @param k -
|
|
102
|
-
* @param lambda -
|
|
101
|
+
* @param k - shape parameter
|
|
102
|
+
* @param lambda - scale parameter
|
|
103
103
|
* @returns evaluated logCDF
|
|
104
104
|
*
|
|
105
105
|
* @example
|
|
@@ -110,9 +110,9 @@ interface LogCDF {
|
|
|
110
110
|
* y = mylogcdf( 12.0 );
|
|
111
111
|
* // returns ~-0.27
|
|
112
112
|
*/
|
|
113
|
-
declare var
|
|
113
|
+
declare var logcdf: LogCDF;
|
|
114
114
|
|
|
115
115
|
|
|
116
116
|
// EXPORTS //
|
|
117
117
|
|
|
118
|
-
export =
|
|
118
|
+
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_WEIBULL_LOGCDF_H
|
|
20
|
+
#define STDLIB_STATS_BASE_DISTS_WEIBULL_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 natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution with shape parameter `k` and scale parameter `lambda` at a value `x`.
|
|
31
|
+
*/
|
|
32
|
+
double stdlib_base_dists_weibull_logcdf( const double x, const double k, const double lambda );
|
|
33
|
+
|
|
34
|
+
#ifdef __cplusplus
|
|
35
|
+
}
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
#endif // !STDLIB_STATS_BASE_DISTS_WEIBULL_LOGCDF_H
|
package/lib/factory.js
CHANGED
|
@@ -36,8 +36,8 @@ var NINF = require( '@stdlib/constants-float64-ninf' );
|
|
|
36
36
|
/**
|
|
37
37
|
* Returns a function for evaluating the natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution.
|
|
38
38
|
*
|
|
39
|
-
* @param {PositiveNumber} k -
|
|
40
|
-
* @param {PositiveNumber} lambda -
|
|
39
|
+
* @param {PositiveNumber} k - shape parameter
|
|
40
|
+
* @param {PositiveNumber} lambda - scale parameter
|
|
41
41
|
* @returns {Function} logCDF
|
|
42
42
|
*
|
|
43
43
|
* @example
|
package/lib/main.js
CHANGED
|
@@ -33,11 +33,11 @@ var NINF = require( '@stdlib/constants-float64-ninf' );
|
|
|
33
33
|
// MAIN //
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution with
|
|
36
|
+
* Evaluates the natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution with shape parameter `k` and scale parameter `lambda` at a value `x`.
|
|
37
37
|
*
|
|
38
38
|
* @param {number} x - input value
|
|
39
|
-
* @param {PositiveNumber} k -
|
|
40
|
-
* @param {PositiveNumber} lambda -
|
|
39
|
+
* @param {PositiveNumber} k - shape parameter
|
|
40
|
+
* @param {PositiveNumber} lambda - scale parameter
|
|
41
41
|
* @returns {number} natural logarithm of CDF
|
|
42
42
|
*
|
|
43
43
|
* @example
|
package/lib/native.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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 natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution with shape parameter `k` and scale parameter `lambda` at a value `x`.
|
|
30
|
+
*
|
|
31
|
+
* @private
|
|
32
|
+
* @param {number} x - input value
|
|
33
|
+
* @param {PositiveNumber} k - shape parameter
|
|
34
|
+
* @param {PositiveNumber} lambda - scale parameter
|
|
35
|
+
* @returns {number} natural logarithm of CDF
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* var y = logcdf( 2.0, 1.0, 1.0 );
|
|
39
|
+
* // returns ~-0.145
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* var y = logcdf( -1.0, 2.0, 2.0 );
|
|
43
|
+
* // returns -Infinity
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* var y = logcdf( +Infinity, 4.0, 2.0 );
|
|
47
|
+
* // returns 0.0
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* var y = logcdf( -Infinity, 4.0, 2.0 );
|
|
51
|
+
* // returns -Infinity
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* var y = logcdf( NaN, 0.0, 1.0 );
|
|
55
|
+
* // returns NaN
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* var y = logcdf( 0.0, NaN, 1.0 );
|
|
59
|
+
* // returns NaN
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* var y = logcdf( 0.0, 0.0, NaN );
|
|
63
|
+
* // returns NaN
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* var y = logcdf( 2.0, 0.0, -1.0 );
|
|
67
|
+
* // returns NaN
|
|
68
|
+
*/
|
|
69
|
+
function logcdf( x, k, lambda ) {
|
|
70
|
+
return addon( x, k, lambda );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
// EXPORTS //
|
|
75
|
+
|
|
76
|
+
module.exports = logcdf;
|
package/manifest.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": {
|
|
3
|
+
"task": "build",
|
|
4
|
+
"wasm": false
|
|
5
|
+
},
|
|
6
|
+
"fields": [
|
|
7
|
+
{
|
|
8
|
+
"field": "src",
|
|
9
|
+
"resolve": true,
|
|
10
|
+
"relative": true
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"field": "include",
|
|
14
|
+
"resolve": true,
|
|
15
|
+
"relative": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"field": "libraries",
|
|
19
|
+
"resolve": false,
|
|
20
|
+
"relative": false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"field": "libpath",
|
|
24
|
+
"resolve": true,
|
|
25
|
+
"relative": false
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"confs": [
|
|
29
|
+
{
|
|
30
|
+
"task": "build",
|
|
31
|
+
"wasm": false,
|
|
32
|
+
"src": [
|
|
33
|
+
"./src/main.c"
|
|
34
|
+
],
|
|
35
|
+
"include": [
|
|
36
|
+
"./include"
|
|
37
|
+
],
|
|
38
|
+
"libraries": [],
|
|
39
|
+
"libpath": [],
|
|
40
|
+
"dependencies": [
|
|
41
|
+
"@stdlib/math-base-napi-ternary",
|
|
42
|
+
"@stdlib/math-base-assert-is-nan",
|
|
43
|
+
"@stdlib/math-base-special-expm1",
|
|
44
|
+
"@stdlib/math-base-special-log1p",
|
|
45
|
+
"@stdlib/math-base-special-pow",
|
|
46
|
+
"@stdlib/math-base-special-exp",
|
|
47
|
+
"@stdlib/math-base-special-ln",
|
|
48
|
+
"@stdlib/math-base-special-pow",
|
|
49
|
+
"@stdlib/constants-float64-ln-half",
|
|
50
|
+
"@stdlib/constants-float64-ninf"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"task": "benchmark",
|
|
55
|
+
"wasm": false,
|
|
56
|
+
"src": [
|
|
57
|
+
"./src/main.c"
|
|
58
|
+
],
|
|
59
|
+
"include": [
|
|
60
|
+
"./include"
|
|
61
|
+
],
|
|
62
|
+
"libraries": [],
|
|
63
|
+
"libpath": [],
|
|
64
|
+
"dependencies": [
|
|
65
|
+
"@stdlib/constants-float64-eps",
|
|
66
|
+
"@stdlib/math-base-assert-is-nan",
|
|
67
|
+
"@stdlib/math-base-special-expm1",
|
|
68
|
+
"@stdlib/math-base-special-log1p",
|
|
69
|
+
"@stdlib/math-base-special-pow",
|
|
70
|
+
"@stdlib/math-base-special-exp",
|
|
71
|
+
"@stdlib/math-base-special-ln",
|
|
72
|
+
"@stdlib/math-base-special-pow",
|
|
73
|
+
"@stdlib/constants-float64-ln-half",
|
|
74
|
+
"@stdlib/constants-float64-ninf"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"task": "examples",
|
|
79
|
+
"wasm": false,
|
|
80
|
+
"src": [
|
|
81
|
+
"./src/main.c"
|
|
82
|
+
],
|
|
83
|
+
"include": [
|
|
84
|
+
"./include"
|
|
85
|
+
],
|
|
86
|
+
"libraries": [],
|
|
87
|
+
"libpath": [],
|
|
88
|
+
"dependencies": [
|
|
89
|
+
"@stdlib/math-base-assert-is-nan",
|
|
90
|
+
"@stdlib/math-base-special-expm1",
|
|
91
|
+
"@stdlib/math-base-special-log1p",
|
|
92
|
+
"@stdlib/math-base-special-pow",
|
|
93
|
+
"@stdlib/math-base-special-exp",
|
|
94
|
+
"@stdlib/math-base-special-ln",
|
|
95
|
+
"@stdlib/math-base-special-pow",
|
|
96
|
+
"@stdlib/constants-float64-ln-half",
|
|
97
|
+
"@stdlib/constants-float64-ninf"
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/stats-base-dists-weibull-logcdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Weibull 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,13 +36,15 @@
|
|
|
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-ternary": "^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
45
|
"@stdlib/utils-constant-function": "^0.2.2",
|
|
42
|
-
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
|
|
46
|
+
"@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
|
|
47
|
+
"@stdlib/utils-library-manifest": "^0.2.3"
|
|
43
48
|
},
|
|
44
49
|
"devDependencies": {},
|
|
45
50
|
"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/weibull/logcdf.h"
|
|
20
|
+
#include "stdlib/math/base/napi/ternary.h"
|
|
21
|
+
|
|
22
|
+
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_weibull_logcdf )
|
package/src/main.c
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
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/weibull/logcdf.h"
|
|
20
|
+
#include "stdlib/math/base/assert/is_nan.h"
|
|
21
|
+
#include "stdlib/math/base/special/expm1.h"
|
|
22
|
+
#include "stdlib/math/base/special/log1p.h"
|
|
23
|
+
#include "stdlib/math/base/special/pow.h"
|
|
24
|
+
#include "stdlib/math/base/special/exp.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 natural logarithm of the cumulative distribution function (CDF) for a Weibull distribution with shape parameter `k` and scale parameter `lambda` at a value `x`.
|
|
31
|
+
*
|
|
32
|
+
* @param x input value
|
|
33
|
+
* @param k shape parameter
|
|
34
|
+
* @param lambda scale parameter
|
|
35
|
+
* @return natural logarithm of CDF
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* double y = stdlib_base_dists_weibull_logcdf( 2.0, 1.0, 1.0 );
|
|
39
|
+
* // returns ~0.145
|
|
40
|
+
*/
|
|
41
|
+
double stdlib_base_dists_weibull_logcdf( const double x, const double k, const double lambda ) {
|
|
42
|
+
double p;
|
|
43
|
+
if (
|
|
44
|
+
stdlib_base_is_nan( x ) ||
|
|
45
|
+
stdlib_base_is_nan( lambda ) ||
|
|
46
|
+
k <= 0.0 ||
|
|
47
|
+
lambda <= 0.0
|
|
48
|
+
) {
|
|
49
|
+
return 0.0/0.0; // NaN
|
|
50
|
+
}
|
|
51
|
+
if ( x < 0.0 ) {
|
|
52
|
+
return STDLIB_CONSTANT_FLOAT64_NINF;
|
|
53
|
+
}
|
|
54
|
+
p = -stdlib_base_pow( x / lambda, k );
|
|
55
|
+
return ( p < STDLIB_CONSTANT_FLOAT64_LN_HALF ) ? stdlib_base_log1p( -stdlib_base_exp( p ) ) : stdlib_base_ln( -stdlib_base_expm1( p ) );
|
|
56
|
+
}
|