Skip to content

Commit 9b92935

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 9f7dd5e commit 9b92935

File tree

7 files changed

+108
-55
lines changed

7 files changed

+108
-55
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ F(x;c)=\frac{\ln(1+cx)}{\ln(1+c)}
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

@@ -66,6 +66,12 @@ y = cdf( 0.5, 5.0 );
6666

6767
y = cdf( 1.0, 10.0 );
6868
// returns 1.0
69+
70+
y = cdf( -0.5, 1.0 );
71+
// returns 0.0
72+
73+
y = cdf( 2.0, 1.0 );
74+
// returns 1.0
6975
```
7076

7177
If provided `NaN` as any argument, the function returns `NaN`.
@@ -78,23 +84,13 @@ y = cdf( 0.0, NaN );
7884
// returns NaN
7985
```
8086

81-
If provided an input value `x` outside of the interval `[0,1]`, the function returns `NaN`.
82-
83-
```javascript
84-
var y = cdf( 2.0, 1.0 );
85-
// returns NaN
86-
87-
y = cdf( -0.5, 1.0 );
88-
// returns NaN
89-
```
90-
9187
If provided a shape parameter `c <= 0`, the function returns `NaN`.
9288

9389
```javascript
9490
var y = cdf( 0.0, 0.0 );
9591
// returns NaN
9692

97-
y = cdf( 0.5, -1.0 );
93+
y = cdf( 0.5, -5.0 );
9894
// returns NaN
9995
```
10096

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

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

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

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

1311
Parameters
@@ -31,12 +29,16 @@
3129
~0.699
3230
> y = {{alias}}( 1.0, 10.0 )
3331
1.0
34-
> y = {{alias}}( 0.5, 0.0 )
35-
NaN
32+
> y = {{alias}}( -1.0, 0.5 )
33+
0.0
3634
> y = {{alias}}( 2.0, 0.5 )
35+
1.0
36+
37+
> y = {{alias}}( 0.5, 0.0 )
3738
NaN
38-
> y = {{alias}}( -1.0, 0.5 )
39+
> y = {{alias}}( 0.5, -5.0 )
3940
NaN
41+
4042
> y = {{alias}}( NaN, 1.0 )
4143
NaN
4244
> y = {{alias}}( 1.0, NaN )

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ interface CDF {
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 CDF {
5755
* // returns 1.0
5856
*
5957
* @example
60-
* var y = cdf( 0.5, 0.0 );
61-
* // returns NaN
58+
* var y = cdf( -1.0, 0.5 );
59+
* // returns 0.0
6260
*
6361
* @example
6462
* var y = cdf( 2.0, 0.5 );
63+
* // returns 1.0
64+
*
65+
* @example
66+
* var y = cdf( 0.5, 0.0 );
6567
* // returns NaN
6668
*
6769
* @example
68-
* var y = cdf( -1.0, 0.5 );
70+
* var y = cdf( 0.5, -5.0 );
6971
* // returns NaN
7072
*
7173
* @example

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

Lines changed: 9 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 cumulative distribution function (CDF) for a Bradford distribution with shape parameter `c`.
3232
*
33-
* @param {number} c - shape parameter
33+
* @param {PositiveNumber} c - shape parameter
3434
* @returns {Function} CDF
3535
*
3636
* @example
@@ -55,20 +55,24 @@ function factory( c ) {
5555
*
5656
* @private
5757
* @param {number} x - input value
58-
* @returns {number} evaluated CDF
58+
* @returns {Probability} evaluated CDF
5959
*
6060
* @example
6161
* var y = cdf( 0.5 );
6262
* // returns <number>
6363
*/
6464
function cdf( x ) {
6565
if (
66-
isnan( x ) ||
67-
x < 0.0 ||
68-
x > 1.0
66+
isnan( x )
6967
) {
7068
return NaN;
7169
}
70+
if ( x <= 0.0 ) {
71+
return 0.0;
72+
}
73+
if ( x >= 1.0 ) {
74+
return 1.0;
75+
}
7276
return log1p( c * x ) / log1p( c );
7377
}
7478
}

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ var log1p = require( '@stdlib/math/base/special/log1p' );
3030
* Returns the cumulative distribution function (CDF) 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 CDF
33+
* @param {PositiveNumber} c - shape parameter
34+
* @returns {Probability} evaluated CDF
3535
*
3636
* @example
3737
* var v = cdf( 0.1, 0.1 );
@@ -46,15 +46,19 @@ var log1p = require( '@stdlib/math/base/special/log1p' );
4646
* // returns 1.0
4747
*
4848
* @example
49-
* var v = cdf( 0.5, 0.0 );
50-
* // returns NaN
49+
* var v = cdf( -1.0, 0.5 );
50+
* // returns 0.0
5151
*
5252
* @example
5353
* var v = cdf( 2.0, 0.5 );
54+
* // returns 1.0
55+
*
56+
* @example
57+
* var v = cdf( 0.5, 0.0 );
5458
* // returns NaN
5559
*
5660
* @example
57-
* var v = cdf( -1.0, 0.5 );
61+
* var v = cdf( 0.5, -5.0 );
5862
* // returns NaN
5963
*
6064
* @example
@@ -69,12 +73,16 @@ function cdf( x, c ) {
6973
if (
7074
isnan( c ) ||
7175
isnan( x ) ||
72-
c <= 0.0 ||
73-
x < 0.0 ||
74-
x > 1.0
76+
c <= 0.0
7577
) {
7678
return NaN;
7779
}
80+
if ( x <= 0.0 ) {
81+
return 0.0;
82+
}
83+
if ( x >= 1.0 ) {
84+
return 1.0;
85+
}
7886
return log1p( c * x ) / log1p( c );
7987
}
8088

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,38 @@ 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 greater than or equal to one for `x` and a finite `c`, the function returns `1`', function test( t ) {
7575
var y;
7676

77-
y = cdf( 2.0, 1.0 );
78-
t.equal( isnan( y ), true, 'returns expected value' );
77+
y = cdf( PINF, 0.5 );
78+
t.equal( y, 1.0, 'returns 1' );
7979

80-
y = cdf( -0.5, 1.0 );
81-
t.equal( isnan( y ), true, 'returns expected value' );
80+
y = cdf( 100.0, 0.5 );
81+
t.equal( y, 1.0, 'returns 1' );
8282

83-
y = cdf( NINF, 1.0 );
84-
t.equal( isnan( y ), true, 'returns expected value' );
83+
y = cdf( 10.0, 0.5 );
84+
t.equal( y, 1.0, 'returns 1' );
8585

86-
y = cdf( PINF, 1.0 );
87-
t.equal( isnan( y ), true, 'returns expected value' );
86+
y = cdf( 1.0, 0.5 );
87+
t.equal( y, 1.0, 'returns 1' );
88+
89+
t.end();
90+
});
91+
92+
tape( 'if provided a number less than or equal to zero for `x` and a finite `c`, the function returns `0`', function test( t ) {
93+
var y;
94+
95+
y = cdf( NINF, 0.5 );
96+
t.equal( y, 0.0, 'returns 0' );
97+
98+
y = cdf( -100.0, 0.5 );
99+
t.equal( y, 0.0, 'returns 0' );
100+
101+
y = cdf( -1.0, 0.5 );
102+
t.equal( y, 0.0, 'returns 0' );
103+
104+
y = cdf( 0.0, 0.5 );
105+
t.equal( y, 0.0, 'returns 0' );
88106

89107
t.end();
90108
});

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

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var abs = require( '@stdlib/math/base/special/abs' );
26+
var PINF = require( '@stdlib/constants/float64/pinf' );
27+
var NINF = require( '@stdlib/constants/float64/ninf' );
2628
var EPS = require( '@stdlib/constants/float64/eps' );
2729
var factory = require( './../lib/factory.js' );
2830

@@ -72,7 +74,6 @@ tape( 'if provided `c <= 0`, the created function always returns `NaN`', functio
7274
var y;
7375

7476
cdf = factory( -1.0 );
75-
7677
y = cdf( 1.0 );
7778
t.equal( isnan( y ), true, 'returns expected value' );
7879

@@ -85,23 +86,45 @@ tape( 'if provided `c <= 0`, the created function always returns `NaN`', functio
8586
t.end();
8687
});
8788

88-
tape( 'if provided a `x` outside of `[0,1]`, the created function always returns `NaN`', function test( t ) {
89+
tape( 'if provided a finite `c`, the function returns a function which returns `1` when provided a number greater than or equal to one for `x`', function test( t ) {
8990
var cdf;
9091
var y;
9192

92-
cdf = factory( 1.0 );
93+
cdf = factory( 0.5 );
94+
y = cdf( PINF );
95+
t.equal( y, 1.0, 'returns 1' );
9396

94-
y = cdf( -1.0 );
95-
t.equal( isnan( y ), true, 'returns expected value' );
97+
y = cdf( 100.0 );
98+
t.equal( y, 1.0, 'returns 1' );
9699

97-
y = cdf( -0.5 );
98-
t.equal( isnan( y ), true, 'returns expected value' );
100+
y = cdf( 10.0 );
101+
t.equal( y, 1.0, 'returns 1' );
99102

100-
y = cdf( 1.5 );
101-
t.equal( isnan( y ), true, 'returns expected value' );
103+
y = cdf( 1.0 );
104+
t.equal( y, 1.0, 'returns 1' );
102105

103-
y = cdf( 10.0 );
104-
t.equal( isnan( y ), true, 'returns expected value' );
106+
t.end();
107+
});
108+
109+
tape( 'if provided a finite `c`, the function returns a function which returns `0` when provided a number smaller than or equal to zero for `x`', function test( t ) {
110+
var cdf;
111+
var y;
112+
113+
cdf = factory( 0.5 );
114+
y = cdf( NINF );
115+
t.equal( y, 0.0, 'returns 0' );
116+
117+
y = cdf( -100.0 );
118+
t.equal( y, 0.0, 'returns 0' );
119+
120+
y = cdf( -10.0 );
121+
t.equal( y, 0.0, 'returns 0' );
122+
123+
y = cdf( -1.0 );
124+
t.equal( y, 0.0, 'returns 0' );
125+
126+
y = cdf( 0.0 );
127+
t.equal( y, 0.0, 'returns 0' );
105128

106129
t.end();
107130
});

0 commit comments

Comments
 (0)