Skip to content

Commit 8c67445

Browse files
committed
feat: add stats/base/dists/log-logistic/mean
1 parent 33b4e79 commit 8c67445

File tree

28 files changed

+2167
-0
lines changed

28 files changed

+2167
-0
lines changed
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# Mean
22+
23+
> [Log-logistic][log-logistic-distribution] distribution [mean][mean].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
The [mean][mean] for a [log-logistic][log-logistic-distribution] random variable with scale `α > 0` and shape `β > 1` is
30+
31+
<!-- <equation class="equation" label="eq:log-logistic_mean" align="center" raw="\mathbb{E}[X] = \frac{\alpha \pi/\beta}{\sin(\pi/\beta)}" alt="Mean for a log-logistic distribution."> -->
32+
33+
```math
34+
\mathbb{E}[X] = \frac{\alpha \pi/\beta}{\sin(\pi/\beta)}
35+
```
36+
37+
<!-- <div class="equation" align="center" data-raw-text="\mathbb{E}[X] = \frac{\alpha \pi/\beta}{\sin(\pi/\beta)}" data-equation="eq:log-logistic_mean">
38+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/log-logistic/mean/docs/img/equation_log_logistic_mean.svg" alt="Mean for a log-logistic distribution.">
39+
<br>
40+
</div> -->
41+
42+
<!-- </equation> -->
43+
44+
</section>
45+
46+
<!-- /.intro -->
47+
48+
<!-- Package usage documentation. -->
49+
50+
<section class="usage">
51+
52+
## Usage
53+
54+
```javascript
55+
var mean = require( '@stdlib/stats/base/dists/log-logistic/mean' );
56+
```
57+
58+
#### mean( alpha, beta )
59+
60+
Returns the [mean][mean] for a [log-logistic][log-logistic-distribution] distribution with scale parameter `alpha` and shape parameter `beta`.
61+
62+
```javascript
63+
var y = mean( 1.0, 2.0 );
64+
// returns ~1.571
65+
66+
y = mean( 4.0, 3.0 );
67+
// returns ~4.837
68+
69+
y = mean( 2.0, 5.0 );
70+
// returns ~2.138
71+
```
72+
73+
If provided `NaN` as any argument, the function returns `NaN`.
74+
75+
```javascript
76+
var y = mean( NaN, 2.0 );
77+
// returns NaN
78+
79+
y = mean( 1.0, NaN );
80+
// returns NaN
81+
```
82+
83+
If provided `alpha <= 0`, the function returns `NaN`.
84+
85+
```javascript
86+
var y = mean( 0.0, 2.0 );
87+
// returns NaN
88+
89+
y = mean( -1.0, 2.0 );
90+
// returns NaN
91+
```
92+
93+
If provided `beta <= 0`, the function returns `NaN`.
94+
95+
```javascript
96+
var y = mean( 2.0, 0.0 );
97+
// returns NaN
98+
99+
y = mean( 2.0, -1.0 );
100+
// returns NaN
101+
```
102+
103+
If provided `beta <= 1`, the function returns `NaN`.
104+
105+
```javascript
106+
var y = mean( 2.0, 1.0 );
107+
// returns NaN
108+
109+
y = mean( 2.0, 0.5 );
110+
// returns NaN
111+
```
112+
113+
</section>
114+
115+
<!-- /.usage -->
116+
117+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
118+
119+
<section class="notes">
120+
121+
</section>
122+
123+
<!-- /.notes -->
124+
125+
<!-- Package usage examples. -->
126+
127+
<section class="examples">
128+
129+
## Examples
130+
131+
<!-- eslint no-undef: "error" -->
132+
133+
```javascript
134+
var uniform = require( '@stdlib/random/array/uniform' );
135+
var logEachMap = require( '@stdlib/console/log-each-map' );
136+
var mean = require( '@stdlib/stats/base/dists/log-logistic/mean' );
137+
138+
var opts = {
139+
'dtype': 'float64'
140+
};
141+
var alpha = uniform( 10, 0.1, 10.0, opts );
142+
var beta = uniform( 10, 1.1, 10.0, opts );
143+
144+
logEachMap( 'alpha: %0.4f, beta: %0.4f, Mean(X;alpha,beta): %0.4f', alpha, beta, mean );
145+
```
146+
147+
</section>
148+
149+
<!-- /.examples -->
150+
151+
<!-- C interface documentation. -->
152+
153+
* * *
154+
155+
<section class="c">
156+
157+
## C APIs
158+
159+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
160+
161+
<section class="intro">
162+
163+
</section>
164+
165+
<!-- /.intro -->
166+
167+
<!-- C usage documentation. -->
168+
169+
<section class="usage">
170+
171+
### Usage
172+
173+
```c
174+
#include "stdlib/stats/base/dists/log-logistic/mean.h"
175+
```
176+
177+
#### stdlib_base_dists_log_logistic_mean( alpha, beta )
178+
179+
Returns the mean for a log-logistic distribution with scale `alpha` and shape `beta`.
180+
181+
```c
182+
double out = stdlib_base_dists_log_logistic_mean( 1.0, 2.0 );
183+
// returns ~1.571
184+
```
185+
186+
The function accepts the following arguments:
187+
188+
- **alpha**: `[in] double` scale parameter.
189+
- **beta**: `[in] double` shape parameter.
190+
191+
```c
192+
double stdlib_base_dists_log_logistic_mean( const double alpha, const double beta );
193+
```
194+
195+
</section>
196+
197+
<!-- /.usage -->
198+
199+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
200+
201+
<section class="notes">
202+
203+
</section>
204+
205+
<!-- /.notes -->
206+
207+
<!-- C API usage examples. -->
208+
209+
<section class="examples">
210+
211+
### Examples
212+
213+
```c
214+
#include "stdlib/stats/base/dists/log-logistic/mean.h"
215+
#include <stdlib.h>
216+
#include <stdio.h>
217+
218+
static double random_uniform( const double min, const double max ) {
219+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
220+
return min + ( v*(max-min) );
221+
}
222+
223+
int main( void ) {
224+
double alpha;
225+
double beta;
226+
double v;
227+
int i;
228+
229+
for ( i = 0; i < 25; i++ ) {
230+
alpha = random_uniform( 0.1, 10.0 );
231+
beta = random_uniform( 1.1, 10.0 );
232+
v = stdlib_base_dists_log_logistic_mean( alpha, beta );
233+
printf( "alpha: %lf, beta: %lf, Mean(X;alpha,beta): %lf\n", alpha, beta, v );
234+
}
235+
}
236+
```
237+
238+
</section>
239+
240+
<!-- /.examples -->
241+
242+
</section>
243+
244+
<!-- /.c -->
245+
246+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
247+
248+
<section class="references">
249+
250+
</section>
251+
252+
<!-- /.references -->
253+
254+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
255+
256+
<section class="related">
257+
258+
</section>
259+
260+
<!-- /.related -->
261+
262+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
263+
264+
<section class="links">
265+
266+
[log-logistic-distribution]: https://en.wikipedia.org/wiki/Log-logistic_distribution
267+
268+
[mean]: https://en.wikipedia.org/wiki/Mean
269+
270+
</section>
271+
272+
<!-- /.links -->
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var EPS = require( '@stdlib/constants/float64/eps' );
27+
var pkg = require( './../package.json' ).name;
28+
var mean = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var alpha;
35+
var beta;
36+
var opts;
37+
var y;
38+
var i;
39+
40+
opts = {
41+
'dtype': 'float64'
42+
};
43+
alpha = uniform( 100, EPS, 10.0, opts );
44+
beta = uniform( 100, 1.1, 10.0, opts );
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
y = mean( alpha[ i % alpha.length ], beta[ i % beta.length ] );
49+
if ( isnan( y ) ) {
50+
b.fail( 'should not return NaN' );
51+
}
52+
}
53+
b.toc();
54+
if ( isnan( y ) ) {
55+
b.fail( 'should not return NaN' );
56+
}
57+
b.pass( 'benchmark finished' );
58+
b.end();
59+
});

0 commit comments

Comments
 (0)