Skip to content

Commit 8b8478c

Browse files
committed
feat: add implementation
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 2f54879 commit 8b8478c

File tree

3 files changed

+217
-0
lines changed

3 files changed

+217
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 constantFunction = require( '@stdlib/utils/constant-function' );
24+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var log1p = require( '@stdlib/math/base/special/log1p' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns a function for evaluating the cumulative distribution function (CDF) for a Bradford distribution with shape parameter `c`.
32+
*
33+
* @param {number} c - shape parameter
34+
* @returns {Function} CDF
35+
*
36+
* @example
37+
* var cdf = factory( 5.0 );
38+
* var y = cdf( 0.5 );
39+
* // returns ~0.699
40+
*
41+
* y = cdf( 1.0 );
42+
* // returns 1.0
43+
*/
44+
function factory( c ) {
45+
if (
46+
isnan( c ) ||
47+
c <= 0.0
48+
) {
49+
return constantFunction( NaN );
50+
}
51+
return cdf;
52+
53+
/**
54+
* Evaluates the cumulative distribution function (CDF) for a Bradford distribution.
55+
*
56+
* @private
57+
* @param {number} x - input value
58+
* @returns {number} evaluated CDF
59+
*
60+
* @example
61+
* var y = cdf( 0.5 );
62+
* // returns <number>
63+
*/
64+
function cdf( x ) {
65+
if (
66+
isnan( x ) ||
67+
x < 0.0 ||
68+
x > 1.0
69+
) {
70+
return NaN;
71+
}
72+
return log1p( c * x ) / log1p( c );
73+
}
74+
}
75+
76+
77+
// EXPORTS //
78+
79+
module.exports = factory;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
/**
22+
* Bradford distribution cumulative distribution function (CDF).
23+
*
24+
* @module @stdlib/stats/base/dists/bradford/cdf
25+
*
26+
* @example
27+
* var cdf = require( '@stdlib/stats/base/dists/bradford/cdf' );
28+
*
29+
* var y = cdf( 0.5, 5.0 );
30+
* // returns ~0.699
31+
*
32+
* var myPDF = cdf.factory( 5.0 );
33+
* y = myPDF( 0.5 );
34+
* // returns ~0.699
35+
*
36+
* y = myPDF( 1.0 );
37+
* // returns 1.0
38+
*/
39+
40+
// MODULES //
41+
42+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
43+
var main = require( './main.js' );
44+
var factory = require( './factory.js' );
45+
46+
47+
// MAIN //
48+
49+
setReadOnly( main, 'factory', factory );
50+
51+
52+
// EXPORTS //
53+
54+
module.exports = main;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isnan = require( '@stdlib/math/base/assert/is-nan' );
24+
var log1p = require( '@stdlib/math/base/special/log1p' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Returns the cumulative distribution function (CDF) for a Bradford distribution with shape parameter `c` at a value `x`.
31+
*
32+
* @param {number} x - input value
33+
* @param {number} c - shape parameter
34+
* @returns {number} evaluated CDF
35+
*
36+
* @example
37+
* var v = cdf( 0.1, 0.1 );
38+
* // returns ~0.104
39+
*
40+
* @example
41+
* var v = cdf( 0.5, 5.0 );
42+
* // returns ~0.699
43+
*
44+
* @example
45+
* var v = cdf( 1.0, 10.0 );
46+
* // returns 1.0
47+
*
48+
* @example
49+
* var v = cdf( 0.5, 0.0 );
50+
* // returns NaN
51+
*
52+
* @example
53+
* var v = cdf( 2.0, 0.5 );
54+
* // returns NaN
55+
*
56+
* @example
57+
* var v = cdf( -1.0, 0.5 );
58+
* // returns NaN
59+
*
60+
* @example
61+
* var v = cdf( NaN, 1.0 );
62+
* // returns NaN
63+
*
64+
* @example
65+
* var v = cdf( 1.0, NaN );
66+
* // returns NaN
67+
*/
68+
function cdf( x, c ) {
69+
if (
70+
isnan( c ) ||
71+
isnan( x ) ||
72+
c <= 0.0 ||
73+
x < 0.0 ||
74+
x > 1.0
75+
) {
76+
return NaN;
77+
}
78+
return log1p( c * x ) / log1p( c );
79+
}
80+
81+
82+
// EXPORTS //
83+
84+
module.exports = cdf;

0 commit comments

Comments
 (0)