Skip to content

Commit e443b63

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 e443b63

File tree

3 files changed

+221
-0
lines changed

3 files changed

+221
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 ln = require( '@stdlib/math/base/special/ln' );
26+
27+
28+
// MAIN //
29+
30+
/**
31+
* Returns a function for evaluating the probability density function (PDF) for a bradford distribution with shape parameter `c`.
32+
*
33+
* @param {number} c - shape parameter
34+
* @returns {Function} PDF
35+
*
36+
* @example
37+
* var pdf = factory( 5.0 );
38+
* var y = pdf( 0.5 );
39+
* // returns ~0.797
40+
*
41+
* y = pdf( 1.0 );
42+
* // returns ~0.465
43+
*/
44+
function factory( c ) {
45+
if (
46+
isnan( c ) ||
47+
c <= 0.0
48+
) {
49+
return constantFunction( NaN );
50+
}
51+
return pdf;
52+
53+
/**
54+
* Evaluates the probability density function (PDF) for a bradford distribution.
55+
*
56+
* @private
57+
* @param {number} x - input value
58+
* @returns {number} evaluated PDF
59+
*
60+
* @example
61+
* var y = pdf( 0.5 );
62+
* // returns <number>
63+
*/
64+
function pdf( x ) {
65+
var k;
66+
if (
67+
isnan( x ) ||
68+
x < 0.0 ||
69+
x > 1.0
70+
) {
71+
return NaN;
72+
}
73+
k = ln( 1.0 + c );
74+
return c / ( ( 1.0 + ( c * x ) ) * k );
75+
}
76+
}
77+
78+
79+
// EXPORTS //
80+
81+
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 probability density function (PDF).
23+
*
24+
* @module @stdlib/stats/base/dists/bradford/pdf
25+
*
26+
* @example
27+
* var pdf = require( '@stdlib/stats/base/dists/bradford/pdf' );
28+
*
29+
* var y = pdf( 0.5, 5.0 );
30+
* // returns ~0.797
31+
*
32+
* var myPDF = pdf.factory( 5.0 );
33+
* y = myPDF( 0.5 );
34+
* // returns ~0.797
35+
*
36+
* y = myPDF( 1.0 );
37+
* // returns ~0.465
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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 ln = require( '@stdlib/math/base/special/ln' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Returns the probability density function (PDF) 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 PDF
35+
*
36+
* @example
37+
* var v = pdf( 0.1, 0.1 );
38+
* // returns ~1.039
39+
*
40+
* @example
41+
* var v = pdf( 0.5, 5.0 );
42+
* // returns ~0.797
43+
*
44+
* @example
45+
* var v = pdf( 1.0, 10.0 );
46+
* // returns ~0.379
47+
*
48+
* @example
49+
* var v = pdf( 0.5, 0.0 );
50+
* // returns NaN
51+
*
52+
* @example
53+
* var v = pdf( 2.0, 0.5 );
54+
* // returns NaN
55+
*
56+
* @example
57+
* var v = pdf( -1.0, 0.5 );
58+
* // returns NaN
59+
*
60+
* @example
61+
* var v = pdf( NaN, 1.0 );
62+
* // returns NaN
63+
*
64+
* @example
65+
* var v = pdf( 1.0, NaN );
66+
* // returns NaN
67+
*/
68+
function pdf( x, c ) {
69+
var k;
70+
if (
71+
isnan( c ) ||
72+
isnan( x ) ||
73+
c <= 0.0 ||
74+
x < 0.0 ||
75+
x > 1.0
76+
) {
77+
return NaN;
78+
}
79+
k = ln( 1.0 + c );
80+
return c / ( ( 1.0 + ( c * x ) ) * k );
81+
}
82+
83+
84+
// EXPORTS //
85+
86+
module.exports = pdf;

0 commit comments

Comments
 (0)