Skip to content

Commit d01466d

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 a4c70ed commit d01466d

File tree

3 files changed

+228
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)