Skip to content

Commit 3088f39

Browse files
feat: add implementation of stats/base/dists/wald/kurtosis
PR-URL: #10216 Ref: #209 Co-authored-by: Philipp Burckhardt <pburckhardt@outlook.com> Reviewed-by: Philipp Burckhardt <pburckhardt@outlook.com> Signed-off-by: Bhargav Dabhade <bhargava2005dabhade@gmail.com> Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 96f2808 commit 3088f39

File tree

27 files changed

+2097
-0
lines changed

27 files changed

+2097
-0
lines changed
Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
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+
# Kurtosis
22+
23+
> [Wald][wald-distribution] distribution [excess kurtosis][kurtosis].
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 [excess kurtosis][kurtosis] for a [Wald][wald-distribution] random variable with mean `μ` and shape parameter `λ > 0` is
30+
31+
<!-- <equation class="equation" label="eq:wald_kurtosis" align="center" raw="\mathop{\mathrm{Kurt}}\left( X \right) = \frac{15\mu}{\lambda}" alt="Excess kurtosis for a Wald distribution."> -->
32+
33+
```math
34+
\mathop{\mathrm{Kurt}}\left( X \right) = \frac{15\mu}{\lambda}
35+
```
36+
37+
<!-- <div class="equation" align="center" data-raw-text="\mathop{\mathrm{Kurt}}\left( X \right) = \frac{15\mu}{\lambda}" data-equation="eq:wald_kurtosis">
38+
</div> -->
39+
40+
<!-- </equation> -->
41+
42+
</section>
43+
44+
<!-- /.intro -->
45+
46+
<!-- Package usage documentation. -->
47+
48+
<section class="usage">
49+
50+
## Usage
51+
52+
```javascript
53+
var kurtosis = require( '@stdlib/stats/base/dists/wald/kurtosis' );
54+
```
55+
56+
#### kurtosis( mu, lambda )
57+
58+
Returns the [excess kurtosis][kurtosis] for a [Wald][wald-distribution] distribution with parameters `mu` (mean) and `lambda` (shape parameter).
59+
60+
```javascript
61+
var y = kurtosis( 2.0, 1.0 );
62+
// returns 30.0
63+
64+
y = kurtosis( 0.0, 1.0 );
65+
// returns NaN
66+
67+
y = kurtosis( -1.0, 4.0 );
68+
// returns NaN
69+
```
70+
71+
If provided `NaN` as any argument, the function returns `NaN`.
72+
73+
```javascript
74+
var y = kurtosis( NaN, 1.0 );
75+
// returns NaN
76+
77+
y = kurtosis( 0.0, NaN );
78+
// returns NaN
79+
```
80+
81+
If provided `mu <= 0` or `lambda <= 0`, the function returns `NaN`.
82+
83+
```javascript
84+
var y = kurtosis( 0.0, 0.0 );
85+
// returns NaN
86+
87+
y = kurtosis( 0.0, -1.0 );
88+
// returns NaN
89+
90+
y = kurtosis( -1.0, 0.0 );
91+
// returns NaN
92+
```
93+
94+
</section>
95+
96+
<!-- /.usage -->
97+
98+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
99+
100+
<section class="notes">
101+
102+
</section>
103+
104+
<!-- /.notes -->
105+
106+
<!-- Package usage examples. -->
107+
108+
<section class="examples">
109+
110+
## Examples
111+
112+
<!-- eslint no-undef: "error" -->
113+
114+
```javascript
115+
var uniform = require( '@stdlib/random/array/uniform' );
116+
var logEachMap = require( '@stdlib/console/log-each-map' );
117+
var EPS = require( '@stdlib/constants/float64/eps' );
118+
var kurtosis = require( '@stdlib/stats/base/dists/wald/kurtosis' );
119+
120+
var opts = {
121+
'dtype': 'float64'
122+
};
123+
var mu = uniform( 10, EPS, 10.0, opts );
124+
var lambda = uniform( 10, EPS, 20.0, opts );
125+
126+
logEachMap( 'µ: %0.4f, λ: %0.4f, Kurtosis(X;µ,λ): %0.4f', mu, lambda, kurtosis );
127+
```
128+
129+
</section>
130+
131+
<!-- /.examples -->
132+
133+
<!-- C interface documentation. -->
134+
135+
* * *
136+
137+
<section class="c">
138+
139+
## C APIs
140+
141+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
142+
143+
<section class="intro">
144+
145+
</section>
146+
147+
<!-- /.intro -->
148+
149+
<!-- C usage documentation. -->
150+
151+
<section class="usage">
152+
153+
### Usage
154+
155+
```c
156+
#include "stdlib/stats/base/dists/wald/kurtosis.h"
157+
```
158+
159+
#### stdlib_base_dists_wald_kurtosis( mu, lambda )
160+
161+
Returns the [excess kurtosis][kurtosis] for a [Wald][wald-distribution] distribution with mean `mu` and shape parameter `lambda`.
162+
163+
```c
164+
double out = stdlib_base_dists_wald_kurtosis( 2.0, 1.0 );
165+
// returns 30.0
166+
```
167+
168+
The function accepts the following arguments:
169+
170+
- **mu**: `[in] double` mean.
171+
- **lambda**: `[in] double` shape parameter.
172+
173+
```c
174+
double stdlib_base_dists_wald_kurtosis( const double mu, const double lambda );
175+
```
176+
177+
</section>
178+
179+
<!-- /.usage -->
180+
181+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
182+
183+
<section class="notes">
184+
185+
</section>
186+
187+
<!-- /.notes -->
188+
189+
<!-- C API usage examples. -->
190+
191+
<section class="examples">
192+
193+
### Examples
194+
195+
```c
196+
#include "stdlib/stats/base/dists/wald/kurtosis.h"
197+
#include <stdlib.h>
198+
#include <stdio.h>
199+
200+
static double random_uniform( const double min, const double max ) {
201+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
202+
return min + ( v*(max-min) );
203+
}
204+
205+
int main( void ) {
206+
double lambda;
207+
double mu;
208+
double y;
209+
int i;
210+
211+
for ( i = 0; i < 10; i++ ) {
212+
mu = random_uniform( 0.1, 5.0 );
213+
lambda = random_uniform( 0.1, 20.0 );
214+
y = stdlib_base_dists_wald_kurtosis( mu, lambda );
215+
printf( "µ: %.4f, λ: %.4f, Kurtosis(X;µ,λ): %.4f\n", mu, lambda, y );
216+
}
217+
}
218+
```
219+
220+
</section>
221+
222+
<!-- /.examples -->
223+
224+
</section>
225+
226+
<!-- /.c -->
227+
228+
<!-- 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. -->
229+
230+
<section class="references">
231+
232+
</section>
233+
234+
<!-- /.references -->
235+
236+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
237+
238+
<section class="related">
239+
240+
</section>
241+
242+
<!-- /.related -->
243+
244+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
245+
246+
<section class="links">
247+
248+
[wald-distribution]: https://en.wikipedia.org/wiki/Inverse_Gaussian_distribution
249+
250+
[kurtosis]: https://en.wikipedia.org/wiki/Kurtosis
251+
252+
</section>
253+
254+
<!-- /.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 kurtosis = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var lambda;
35+
var opts;
36+
var mu;
37+
var y;
38+
var i;
39+
40+
opts = {
41+
'dtype': 'float64'
42+
};
43+
mu = uniform( 100, EPS, 100.0, opts );
44+
lambda = uniform( 100, EPS, 20.0, opts );
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
y = kurtosis( mu[ i % mu.length ], lambda[ i % lambda.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+
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var tryRequire = require( '@stdlib/utils/try-require' );
28+
var format = require( '@stdlib/string/format' );
29+
var EPS = require( '@stdlib/constants/float64/eps' );
30+
var pkg = require( './../package.json' ).name;
31+
32+
33+
// VARIABLES //
34+
35+
var kurtosis = tryRequire( resolve( __dirname, './../lib/native.js' ) );
36+
var opts = {
37+
'skip': ( kurtosis instanceof Error )
38+
};
39+
40+
41+
// MAIN //
42+
43+
bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
44+
var arrayOpts;
45+
var lambda;
46+
var mu;
47+
var y;
48+
var i;
49+
50+
arrayOpts = {
51+
'dtype': 'float64'
52+
};
53+
mu = uniform( 100, EPS, 100.0, arrayOpts );
54+
lambda = uniform( 100, EPS, 20.0, arrayOpts );
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
y = kurtosis( mu[ i % mu.length ], lambda[ i % lambda.length ] );
59+
if ( isnan( y ) ) {
60+
b.fail( 'should not return NaN' );
61+
}
62+
}
63+
b.toc();
64+
if ( isnan( y ) ) {
65+
b.fail( 'should not return NaN' );
66+
}
67+
b.pass( 'benchmark finished' );
68+
b.end();
69+
});

0 commit comments

Comments
 (0)