Skip to content

Commit 5bd5162

Browse files
committed
fix: update implementation to include support for x outside of [0,1]
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: passed - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent a4813ba commit 5bd5162

File tree

7 files changed

+58
-48
lines changed

7 files changed

+58
-48
lines changed

lib/node_modules/@stdlib/stats/base/dists/bradford/pdf/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ f(x;c)=\frac{c}{(\ln(1+c)) (1 + cx)}
3939

4040
<!-- </equation> -->
4141

42-
where `c` is the shape parameter of the distribution. The parameters must satisfy `0 <= x <= 1` and `c > 0`.
42+
where `c > 0` is the shape parameter of the distribution.
4343

4444
</section>
4545

@@ -68,33 +68,33 @@ y = pdf( 1.0, 10.0 );
6868
// returns ~0.379
6969
```
7070

71-
If provided `NaN` as any argument, the function returns `NaN`.
71+
If provided a `x` outside the support `[0,1]`, the function returns `0`.
7272

7373
```javascript
74-
var y = pdf( NaN, 1.0 );
75-
// returns NaN
74+
var y = pdf( 2.0, 1.0 );
75+
// returns 0.0
7676

77-
y = pdf( 0.0, NaN );
78-
// returns NaN
77+
y = pdf( -0.5, 1.0 );
78+
// returns 0.0
7979
```
8080

81-
If provided an input value `x` outside of the interval `[0,1]`, the function returns `NaN`.
81+
If provided `NaN` as any argument, the function returns `NaN`.
8282

8383
```javascript
84-
var y = pdf( 2.0, 1.0 );
84+
var y = pdf( NaN, 1.0 );
8585
// returns NaN
8686

87-
y = pdf( -0.5, 1.0 );
87+
y = pdf( 0.0, NaN );
8888
// returns NaN
8989
```
9090

9191
If provided a shape parameter `c <= 0`, the function returns `NaN`.
9292

9393
```javascript
94-
var y = pdf( 0.0, 0.0 );
94+
var y = pdf( 0.5, 0.0 );
9595
// returns NaN
9696

97-
y = pdf( 0.5, -1.0 );
97+
y = pdf( 0.5, -5.0 );
9898
// returns NaN
9999
```
100100

lib/node_modules/@stdlib/stats/base/dists/bradford/pdf/docs/repl.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
If provided `NaN` as any argument, the function returns `NaN`.
77

8-
If `x < 0` or `x > 1`, the function returns `NaN`.
9-
108
If provided `c <= 0`, the function returns `NaN`.
119

1210
Parameters
@@ -30,12 +28,16 @@
3028
~0.797
3129
> y = {{alias}}( 1.0, 10.0 )
3230
~0.379
33-
> y = {{alias}}( 0.5, 0.0 )
34-
NaN
3531
> y = {{alias}}( 2.0, 0.5 )
36-
NaN
32+
0.0
3733
> y = {{alias}}( -1.0, 0.5 )
34+
0.0
35+
36+
> y = {{alias}}( 0.5, 0.0 )
3837
NaN
38+
> y = {{alias}}( 0.5, -5.0 )
39+
NaN
40+
3941
> y = {{alias}}( NaN, 1.0 )
4042
NaN
4143
> y = {{alias}}( 1.0, NaN )

lib/node_modules/@stdlib/stats/base/dists/bradford/pdf/docs/types/index.d.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ interface PDF {
3636
*
3737
* ## Notes
3838
*
39-
* - If `x < 0` or `x > 1`, the function returns `NaN`.
40-
*
4139
* - If provided `c <= 0`, the function returns `NaN`.
4240
*
4341
* @param x - input value
@@ -57,15 +55,19 @@ interface PDF {
5755
* // returns ~0.379
5856
*
5957
* @example
60-
* var y = pdf( 0.5, 0.0 );
61-
* // returns NaN
58+
* var y = pdf( 2.0, 0.5 );
59+
* // returns 0.0
6260
*
6361
* @example
64-
* var y = pdf( 2.0, 0.5 );
62+
* var y = pdf( -1.0, 0.5 );
63+
* // returns 0.0
64+
*
65+
* @example
66+
* var y = pdf( 0.5, 0.0 );
6567
* // returns NaN
6668
*
6769
* @example
68-
* var y = pdf( -1.0, 0.5 );
70+
* var y = pdf( 0.5, -5.0 );
6971
* // returns NaN
7072
*
7173
* @example

lib/node_modules/@stdlib/stats/base/dists/bradford/pdf/lib/factory.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var log1p = require( '@stdlib/math/base/special/log1p' );
3030
/**
3131
* Returns a function for evaluating the probability density function (PDF) for a Bradford distribution with shape parameter `c`.
3232
*
33-
* @param {number} c - shape parameter
33+
* @param {PositiveNumber} c - shape parameter
3434
* @returns {Function} PDF
3535
*
3636
* @example
@@ -55,7 +55,7 @@ function factory( c ) {
5555
*
5656
* @private
5757
* @param {number} x - input value
58-
* @returns {number} evaluated PDF
58+
* @returns {Probability} evaluated PDF
5959
*
6060
* @example
6161
* var y = pdf( 0.5 );
@@ -64,12 +64,14 @@ function factory( c ) {
6464
function pdf( x ) {
6565
var k;
6666
if (
67-
isnan( x ) ||
68-
x < 0.0 ||
69-
x > 1.0
67+
isnan( x )
7068
) {
7169
return NaN;
7270
}
71+
if ( x < 0.0 || x > 1.0 ) {
72+
// Support of the Bradford distribution: [0,1]
73+
return 0.0;
74+
}
7375
k = log1p( c );
7476
return c / ( ( 1.0 + ( c * x ) ) * k );
7577
}

lib/node_modules/@stdlib/stats/base/dists/bradford/pdf/lib/main.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ var log1p = require( '@stdlib/math/base/special/log1p' );
3030
* Returns the probability density function (PDF) for a Bradford distribution with shape parameter `c` at a value `x`.
3131
*
3232
* @param {number} x - input value
33-
* @param {number} c - shape parameter
34-
* @returns {number} evaluated PDF
33+
* @param {PositiveNumber} c - shape parameter
34+
* @returns {Probability} evaluated PDF
3535
*
3636
* @example
3737
* var v = pdf( 0.1, 0.1 );
@@ -46,15 +46,19 @@ var log1p = require( '@stdlib/math/base/special/log1p' );
4646
* // returns ~0.379
4747
*
4848
* @example
49-
* var v = pdf( 0.5, 0.0 );
50-
* // returns NaN
49+
* var v = pdf( 2.0, 0.5 );
50+
* // returns 0.0
5151
*
5252
* @example
53-
* var v = pdf( 2.0, 0.5 );
53+
* var v = pdf( -1.0, 0.5 );
54+
* // returns 0.0
55+
*
56+
* @example
57+
* var v = pdf( 0.5, 0.0 );
5458
* // returns NaN
5559
*
5660
* @example
57-
* var v = pdf( -1.0, 0.5 );
61+
* var v = pdf( 0.5, -5.0 );
5862
* // returns NaN
5963
*
6064
* @example
@@ -70,12 +74,14 @@ function pdf( x, c ) {
7074
if (
7175
isnan( c ) ||
7276
isnan( x ) ||
73-
c <= 0.0 ||
74-
x < 0.0 ||
75-
x > 1.0
77+
c <= 0.0
7678
) {
7779
return NaN;
7880
}
81+
if ( x < 0.0 || x > 1.0 ) {
82+
// Support of the Bradford distribution: [0,1]
83+
return 0.0;
84+
}
7985
k = log1p( c );
8086
return c / ( ( 1.0 + ( c * x ) ) * k );
8187
}

lib/node_modules/@stdlib/stats/base/dists/bradford/pdf/test/test.factory.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ tape( 'if provided `c <= 0`, the created function always returns `NaN`', functio
7272
var y;
7373

7474
pdf = factory( -1.0 );
75-
7675
y = pdf( 1.0 );
7776
t.equal( isnan( y ), true, 'returns expected value' );
7877

@@ -85,23 +84,22 @@ tape( 'if provided `c <= 0`, the created function always returns `NaN`', functio
8584
t.end();
8685
});
8786

88-
tape( 'if provided a `x` outside of `[0,1]`, the created function always returns `NaN`', function test( t ) {
87+
tape( 'if provided a valid `c`, the function returns a function which returns `0` when provided a number outside [0,1] for `x`', function test( t ) {
8988
var pdf;
9089
var y;
9190

9291
pdf = factory( 1.0 );
93-
9492
y = pdf( -1.0 );
95-
t.equal( isnan( y ), true, 'returns expected value' );
93+
t.equal( y, 0.0, 'returns expected value' );
9694

9795
y = pdf( -0.5 );
98-
t.equal( isnan( y ), true, 'returns expected value' );
96+
t.equal( y, 0.0, 'returns expected value' );
9997

10098
y = pdf( 1.5 );
101-
t.equal( isnan( y ), true, 'returns expected value' );
99+
t.equal( y, 0.0, 'returns expected value' );
102100

103101
y = pdf( 10.0 );
104-
t.equal( isnan( y ), true, 'returns expected value' );
102+
t.equal( y, 0.0, 'returns expected value' );
105103

106104
t.end();
107105
});

lib/node_modules/@stdlib/stats/base/dists/bradford/pdf/test/test.pdf.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,20 @@ tape( 'if provided `c <= 0`, the function returns `NaN`', function test( t ) {
7171
t.end();
7272
});
7373

74-
tape( 'if provided a `x` outside of `[0,1]`, the created function always returns `NaN`', function test( t ) {
74+
tape( 'if provided a number outside [0,1] for `x` and a valid `c`, the function returns `0`', function test( t ) {
7575
var y;
7676

7777
y = pdf( 2.0, 1.0 );
78-
t.equal( isnan( y ), true, 'returns expected value' );
78+
t.equal( y, 0.0, 'returns expected value' );
7979

8080
y = pdf( -0.5, 1.0 );
81-
t.equal( isnan( y ), true, 'returns expected value' );
81+
t.equal( y, 0.0, 'returns expected value' );
8282

8383
y = pdf( NINF, 1.0 );
84-
t.equal( isnan( y ), true, 'returns expected value' );
84+
t.equal( y, 0.0, 'returns expected value' );
8585

8686
y = pdf( PINF, 1.0 );
87-
t.equal( isnan( y ), true, 'returns expected value' );
87+
t.equal( y, 0.0, 'returns expected value' );
8888

8989
t.end();
9090
});

0 commit comments

Comments
 (0)