• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

synesenom / ran / 26335051199

23 May 2026 02:19PM UTC coverage: 96.742% (+0.09%) from 96.649%
26335051199

push

github

web-flow
Merge pull request #361 from synesenom/claude/build-135-BYxKZ

Add second parameter cases to 105 single-case distributions

960 of 1041 branches covered (92.22%)

Branch coverage included in aggregate %.

3197 of 3256 relevant lines covered (98.19%)

1363709.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.59
/src/dist/tukey-lambda.js
1
import Distribution from './_distribution'
2
import brent from '../algorithms/brent'
3

4
/**
5
 * Generator for the [Tukey lambda distribution]{@link https://en.wikipedia.org/wiki/Tukey_lambda_distribution}:
6
 *
7
 * $f(x; \lambda) = \frac{1}{Q^{-1}(F(x))},$
8
 *
9
 * where $Q(p) = \frac{p^\lambda - (1 - p)^\lambda}{\lambda}$ and $F(x) = Q^{-1}(x)$. Support: $x \in \[-1/\lambda, 1/\lambda\]$ if $\lambda > 0$, otherwise $x \in \mathbb{R}$.
10
 *
11
 * @class TukeyLambda
12
 * @memberof ran.dist
13
 * @see https://en.wikipedia.org/wiki/Tukey_lambda_distribution
14
 * @constructor
15
 */
16
export default class TukeyLambda extends Distribution {
17
  /**
18
   * @param {number} lambda Shape parameter.
19
   */
20
  constructor (lambda) {
21
    super('continuous', 1)
52✔
22

23
    // Validate parameters
24
    this.p = { lambda }
52✔
25
    Distribution.validate({ lambda }, [])
52✔
26

27
    // Set support
28
    this.s = [{
51✔
29
      value: lambda > 0 ? -1 / lambda : -Infinity,
51✔
30
      closed: lambda > 0
31
    }, {
32
      value: lambda > 0 ? 1 / lambda : Infinity,
51✔
33
      closed: lambda > 0
34
    }]
35
  }
36

37
  _generator () {
38
    // Inverse transform sampling
39
    return this._q(this.r.next())
170,630✔
40
  }
41

42
  _pdf (x) {
43
    if (this.p.lambda === 0) {
54✔
44
      const y = Math.exp(-x)
28✔
45
      return y / Math.pow(1 + y, 2)
28✔
46
    } else {
47
      if (x === 0) {
26!
48
        return Math.pow(2, this.p.lambda) / 4
×
49
      } else {
50
        // f(x) = Q^(-1)[F(x)]
51
        const z = this._cdf(x)
26✔
52
        return 1 / (Math.pow(z, this.p.lambda - 1) + Math.pow(1 - z, this.p.lambda - 1))
26✔
53
      }
54
    }
55
  }
56

57
  _cdf (x) {
58
    // If lambda != 0, F(x) is the inverse of quantile function
59
    return this.p.lambda === 0
90,483✔
60
      ? 1 / (1 + Math.exp(-x))
61
      : brent(
62
        t => (Math.pow(t, this.p.lambda) - Math.pow(1 - t, this.p.lambda)) / this.p.lambda - x,
139,792✔
63
        0, 1
64
      )
65
  }
66

67
  _q (p) {
68
    return this.p.lambda === 0
170,847✔
69
      ? Math.log(p / (1 - p))
70
      : (Math.pow(p, this.p.lambda) - Math.pow(1 - p, this.p.lambda)) / this.p.lambda
71
  }
72
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc