Documentation
¶
Overview ¶
Package cauchy implements a cauchy continuous random variable
Cauchy distribution is a probability distribution parameterized by two parameters, namely, location and scale.
References:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cauchy ¶
type Cauchy struct {
// contains filtered or unexported fields
}
Cauchy is a continuous random variable for a lognormal probability distribution parameterized by location and scale
Example ¶
Example - Cauchy Distribution
package main
import (
"fmt"
"strings"
"github.com/shivakar/random/distribution/cauchy"
"github.com/shivakar/random/distribution/normal"
"github.com/shivakar/random/prng/xorshift128plus"
)
func main() {
n := normal.New(xorshift128plus.New(20170611), 5.0, 0.5)
l := cauchy.New(xorshift128plus.New(20170611), 5.0, 0.5)
var np [10]int
var lp [10]int
nrolls := 10000
nstars := 100
for i := 0; i < nrolls; i++ {
v := n.Float64()
if v >= 0.0 && v < 10.0 {
np[int(v)]++
}
v = l.Float64()
if v >= 0.0 && v < 10.0 {
lp[int(v)]++
}
}
fmt.Println("Cauchy Distribution: mu=5.0, sigma=0.5")
for i := 0; i < 10; i++ {
v := lp[i] * nstars / nrolls
fmt.Printf("%2d-%2d: %s (%d)\n", i, i+1,
strings.Repeat("*", v), v)
}
fmt.Println("Normal Distribution: mu=5.0, sigma=0.5")
for i := 0; i < 10; i++ {
v := np[i] * nstars / nrolls
fmt.Printf("%2d-%2d: %s (%d)\n", i, i+1,
strings.Repeat("*", v), v)
}
}
Output: Cauchy Distribution: mu=5.0, sigma=0.5 0- 1: (0) 1- 2: * (1) 2- 3: ** (2) 3- 4: ****** (6) 4- 5: *********************************** (35) 5- 6: *********************************** (35) 6- 7: ****** (6) 7- 8: ** (2) 8- 9: * (1) 9-10: (0) Normal Distribution: mu=5.0, sigma=0.5 0- 1: (0) 1- 2: (0) 2- 3: (0) 3- 4: ** (2) 4- 5: *********************************************** (47) 5- 6: *********************************************** (47) 6- 7: ** (2) 7- 8: (0) 8- 9: (0) 9-10: (0)
func (*Cauchy) CDF ¶
CDF or cumulative distribution function returns the probability that a real-valued random variable X of the probability distribution will be found to have a value less than or equal to x
For Cauchy distribution: CDF(x) = 0.5 + 1/pi * arctan((x-location)/scale)
func (*Cauchy) Float64 ¶
Float64 returns the next random number satisfying the underlying probability distribution
For Cauchy distribution, Float64 return a float64 in [-Inf, Inf]
n = location + scale * tan(pi * U(0, 1) - 0.5)
Implemented using an internal Normal Distribution variable and returning exponentiation of the result.