@stdlib/stats-base-dists-weibull-pdf 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 The Stdlib Authors.
package/README.md CHANGED
@@ -142,21 +142,111 @@ y = mypdf( 5.0 );
142
142
  <!-- eslint no-undef: "error" -->
143
143
 
144
144
  ```javascript
145
- var randu = require( '@stdlib/random-base-randu' );
145
+ var uniform = require( '@stdlib/random-array-uniform' );
146
+ var logEachMap = require( '@stdlib/console-log-each-map' );
146
147
  var pdf = require( '@stdlib/stats-base-dists-weibull-pdf' );
147
148
 
148
- var lambda;
149
- var k;
150
- var x;
151
- var y;
152
- var i;
153
-
154
- for ( i = 0; i < 10; i++ ) {
155
- x = randu() * 10.0;
156
- lambda = randu() * 10.0;
157
- k = randu() * 10.0;
158
- y = pdf( x, lambda, k );
159
- console.log( 'x: %d, k: %d, λ: %d, f(x;k,λ): %d', x.toFixed( 4 ), k.toFixed( 4 ), lambda.toFixed( 4 ), y.toFixed( 4 ) );
149
+ var opts = {
150
+ 'dtype': 'float64'
151
+ };
152
+ var lambda = uniform( 10, 0.0, 10.0, opts );
153
+ var k = uniform( 10, 0.0, 10.0, opts );
154
+ var x = uniform( 10, 0.0, 10.0, opts );
155
+
156
+ logEachMap( 'x: %0.4f, k: %0.4f, λ: %0.4f, f(x;k,λ): %0.4f', x, k, lambda, pdf );
157
+ ```
158
+
159
+ </section>
160
+
161
+ <!-- /.examples -->
162
+
163
+ <!-- C interface documentation. -->
164
+
165
+ * * *
166
+
167
+ <section class="c">
168
+
169
+ ## C APIs
170
+
171
+ <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
172
+
173
+ <section class="intro">
174
+
175
+ </section>
176
+
177
+ <!-- /.intro -->
178
+
179
+ <!-- C usage documentation. -->
180
+
181
+ <section class="usage">
182
+
183
+ ### Usage
184
+
185
+ ```c
186
+ #include "stdlib/stats/base/dists/weibull/pdf.h"
187
+ ```
188
+
189
+ #### stdlib_base_dists_weibull_pdf( x, k, lambda )
190
+
191
+ Evaluates the [probability density function][pdf] (PDF) for a [Weibull][weibull-distribution] distribution with [shape parameter][shape] `k` and [scale parameter][scale] `lambda`.
192
+
193
+ ```c
194
+ double out = stdlib_base_dists_weibull_pdf( 2.0, 1.0, 1.0 );
195
+ // returns ~0.037
196
+ ```
197
+
198
+ The function accepts the following arguments:
199
+
200
+ - **x**: `[in] double` input value.
201
+ - **k**: `[in] double` shape parameter.
202
+ - **lambda**: `[in] double` scale parameter.
203
+
204
+ ```c
205
+ double stdlib_base_dists_weibull_pdf( const double x, const double k, const double lambda );
206
+ ```
207
+
208
+ </section>
209
+
210
+ <!-- /.usage -->
211
+
212
+ <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
213
+
214
+ <section class="notes">
215
+
216
+ </section>
217
+
218
+ <!-- /.notes -->
219
+
220
+ <!-- C API usage examples. -->
221
+
222
+ <section class="examples">
223
+
224
+ ### Examples
225
+
226
+ ```c
227
+ #include "stdlib/stats/base/dists/weibull/pdf.h"
228
+ #include <stdlib.h>
229
+ #include <stdio.h>
230
+
231
+ static double random_uniform( const double min, const double max ) {
232
+ double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
233
+ return min + ( v*(max-min) );
234
+ }
235
+
236
+ int main( void ) {
237
+ double lambda;
238
+ double x;
239
+ double k;
240
+ double y;
241
+ int i;
242
+
243
+ for ( i = 0; i < 25; i++ ) {
244
+ x = random_uniform( 0.0, 10.0 );
245
+ lambda = random_uniform( 0.0, 10.0 );
246
+ k = random_uniform( 0.0, 10.0 );
247
+ y = stdlib_base_dists_weibull_pdf( x, k, lambda );
248
+ printf( "x: %lf, k: %lf, λ: %lf, f(x;k,λ): %lf\n", x, k, lambda, y );
249
+ }
160
250
  }
161
251
  ```
162
252
 
@@ -164,6 +254,10 @@ for ( i = 0; i < 10; i++ ) {
164
254
 
165
255
  <!-- /.examples -->
166
256
 
257
+ </section>
258
+
259
+ <!-- /.c -->
260
+
167
261
  <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
168
262
 
169
263
  <section class="related">
@@ -198,7 +292,7 @@ See [LICENSE][stdlib-license].
198
292
 
199
293
  ## Copyright
200
294
 
201
- Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
295
+ Copyright &copy; 2016-2026. The Stdlib [Authors][stdlib-authors].
202
296
 
203
297
  </section>
204
298
 
@@ -211,8 +305,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
211
305
  [npm-image]: http://img.shields.io/npm/v/@stdlib/stats-base-dists-weibull-pdf.svg
212
306
  [npm-url]: https://npmjs.org/package/@stdlib/stats-base-dists-weibull-pdf
213
307
 
214
- [test-image]: https://github.com/stdlib-js/stats-base-dists-weibull-pdf/actions/workflows/test.yml/badge.svg?branch=v0.2.2
215
- [test-url]: https://github.com/stdlib-js/stats-base-dists-weibull-pdf/actions/workflows/test.yml?query=branch:v0.2.2
308
+ [test-image]: https://github.com/stdlib-js/stats-base-dists-weibull-pdf/actions/workflows/test.yml/badge.svg?branch=v0.3.0
309
+ [test-url]: https://github.com/stdlib-js/stats-base-dists-weibull-pdf/actions/workflows/test.yml?query=branch:v0.3.0
216
310
 
217
311
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/stats-base-dists-weibull-pdf/main.svg
218
312
  [coverage-url]: https://codecov.io/github/stdlib-js/stats-base-dists-weibull-pdf?branch=main
@@ -224,8 +318,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
224
318
 
225
319
  -->
226
320
 
227
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
228
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
321
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
322
+ [chat-url]: https://stdlib.zulipchat.com
229
323
 
230
324
  [stdlib]: https://github.com/stdlib-js/stdlib
231
325
 
@@ -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_PDF_H
20
+ #define STDLIB_STATS_BASE_DISTS_WEIBULL_PDF_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 probability density function (PDF) for a Weibull distribution with shape parameter `k` and scale parameter `lambda` at a value `x`.
31
+ */
32
+ double stdlib_base_dists_weibull_pdf( const double x, const double k, const double lambda );
33
+
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+ #endif // !STDLIB_STATS_BASE_DISTS_WEIBULL_PDF_H
package/lib/native.js ADDED
@@ -0,0 +1,72 @@
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 probability density function (PDF) 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} evaluated probability density function
36
+ *
37
+ * @example
38
+ * var y = pdf( 2.0, 1.0, 0.5 );
39
+ * // returns ~0.037
40
+ *
41
+ * @example
42
+ * var y = pdf( 0.1, 1.0, 1.0 );
43
+ * // returns ~0.905
44
+ *
45
+ * @example
46
+ * var y = pdf( -1.0, 4.0, 2.0 );
47
+ * // returns 0.0
48
+ *
49
+ * @example
50
+ * var y = pdf( NaN, 0.6, 1.0 );
51
+ * // returns NaN
52
+ *
53
+ * @example
54
+ * var y = pdf( 0.0, NaN, 1.0 );
55
+ * // returns NaN
56
+ *
57
+ * @example
58
+ * var y = pdf( 0.0, 0.0, NaN );
59
+ * // returns NaN
60
+ *
61
+ * @example
62
+ * var y = pdf( 2.0, 0.0, -1.0 );
63
+ * // returns NaN
64
+ */
65
+ function pdf( x, k, lambda ) {
66
+ return addon( x, k, lambda );
67
+ }
68
+
69
+
70
+ // EXPORTS //
71
+
72
+ module.exports = pdf;
package/manifest.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "options": {
3
+ "task": "build",
4
+ "wasm": false
5
+ },
6
+ "fields": [
7
+ {
8
+ "field": "src",
9
+ "resolve": true,
10
+ "relative": true
11
+ },
12
+ {
13
+ "field": "include",
14
+ "resolve": true,
15
+ "relative": true
16
+ },
17
+ {
18
+ "field": "libraries",
19
+ "resolve": false,
20
+ "relative": false
21
+ },
22
+ {
23
+ "field": "libpath",
24
+ "resolve": true,
25
+ "relative": false
26
+ }
27
+ ],
28
+ "confs": [
29
+ {
30
+ "task": "build",
31
+ "wasm": false,
32
+ "src": [
33
+ "./src/main.c"
34
+ ],
35
+ "include": [
36
+ "./include"
37
+ ],
38
+ "libraries": [],
39
+ "libpath": [],
40
+ "dependencies": [
41
+ "@stdlib/math-base-napi-ternary",
42
+ "@stdlib/math-base-assert-is-nan",
43
+ "@stdlib/math-base-special-pow",
44
+ "@stdlib/math-base-special-exp",
45
+ "@stdlib/constants-float64-pinf",
46
+ "@stdlib/constants-float64-ninf"
47
+ ]
48
+ },
49
+ {
50
+ "task": "benchmark",
51
+ "wasm": false,
52
+ "src": [
53
+ "./src/main.c"
54
+ ],
55
+ "include": [
56
+ "./include"
57
+ ],
58
+ "libraries": [],
59
+ "libpath": [],
60
+ "dependencies": [
61
+ "@stdlib/constants-float64-eps",
62
+ "@stdlib/math-base-assert-is-nan",
63
+ "@stdlib/math-base-special-pow",
64
+ "@stdlib/math-base-special-exp",
65
+ "@stdlib/constants-float64-pinf",
66
+ "@stdlib/constants-float64-ninf"
67
+ ]
68
+ },
69
+ {
70
+ "task": "examples",
71
+ "wasm": false,
72
+ "src": [
73
+ "./src/main.c"
74
+ ],
75
+ "include": [
76
+ "./include"
77
+ ],
78
+ "libraries": [],
79
+ "libpath": [],
80
+ "dependencies": [
81
+ "@stdlib/math-base-assert-is-nan",
82
+ "@stdlib/math-base-special-pow",
83
+ "@stdlib/math-base-special-exp",
84
+ "@stdlib/constants-float64-pinf",
85
+ "@stdlib/constants-float64-ninf"
86
+ ]
87
+ }
88
+ ]
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/stats-base-dists-weibull-pdf",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Weibull distribution probability density function (PDF).",
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,10 +36,12 @@
33
36
  "@stdlib/constants-float64-ninf": "^0.2.2",
34
37
  "@stdlib/constants-float64-pinf": "^0.2.2",
35
38
  "@stdlib/math-base-assert-is-nan": "^0.2.2",
36
- "@stdlib/math-base-special-exp": "^0.2.3",
39
+ "@stdlib/math-base-napi-ternary": "^0.3.1",
40
+ "@stdlib/math-base-special-exp": "^0.2.4",
37
41
  "@stdlib/math-base-special-pow": "^0.3.0",
38
42
  "@stdlib/utils-constant-function": "^0.2.2",
39
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2"
43
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
44
+ "@stdlib/utils-library-manifest": "^0.2.3"
40
45
  },
41
46
  "devDependencies": {},
42
47
  "engines": {
package/src/addon.c ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ #include "stdlib/stats/base/dists/weibull/pdf.h"
20
+ #include "stdlib/math/base/napi/ternary.h"
21
+
22
+ STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_weibull_pdf )
package/src/main.c ADDED
@@ -0,0 +1,58 @@
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/pdf.h"
20
+ #include "stdlib/math/base/assert/is_nan.h"
21
+ #include "stdlib/math/base/special/exp.h"
22
+ #include "stdlib/math/base/special/pow.h"
23
+ #include "stdlib/constants/float64/pinf.h"
24
+ #include "stdlib/constants/float64/ninf.h"
25
+
26
+ /**
27
+ * Evaluates the probability density function (PDF) for a Weibull distribution with shape parameter `k` and scale parameter `lambda` at a value `x`.
28
+ *
29
+ * @param x input value
30
+ * @param k shape parameter
31
+ * @param lambda scale parameter
32
+ * @return evaluated PDF
33
+ *
34
+ * @example
35
+ * double y = stdlib_base_dists_weibull_pdf( 2.0, 1.0, 1.0 );
36
+ * // returns ~0.037
37
+ */
38
+ double stdlib_base_dists_weibull_pdf( const double x, const double k, const double lambda ) {
39
+ double xol;
40
+ double z;
41
+ if (
42
+ stdlib_base_is_nan( k ) ||
43
+ stdlib_base_is_nan( lambda ) ||
44
+ k <= 0.0 ||
45
+ lambda <= 0.0
46
+ ) {
47
+ return 0.0/0.0; // NaN
48
+ }
49
+ if ( x < 0.0 ) {
50
+ return 0.0;
51
+ }
52
+ if ( x == STDLIB_CONSTANT_FLOAT64_PINF || x == STDLIB_CONSTANT_FLOAT64_NINF ){
53
+ return ( k == 0.0 ) ? k/lambda : 0.0;
54
+ }
55
+ xol = x / lambda;
56
+ z = stdlib_base_pow( xol, k - 1.0 );
57
+ return ( k / lambda ) * z * stdlib_base_exp( - stdlib_base_pow( xol, k ) );
58
+ }