distributions

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package distributions provides probability distributions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetSeed

func SetSeed(seed int64)

SetSeed sets the random seed for reproducible results

Types

type Binomial

type Binomial struct {
	N float64 // number of trials
	P float64 // success probability
}

Binomial represents a binomial distribution.

func NewBinomial

func NewBinomial(n int, p float64) *Binomial

NewBinomial creates a new binomial distribution.

func (*Binomial) CDF

func (b *Binomial) CDF(k int) float64

CDF returns the cumulative distribution function at k. P(X <= k)

func (*Binomial) Mean

func (b *Binomial) Mean() float64

Mean returns the mean of the distribution.

func (*Binomial) PMF

func (b *Binomial) PMF(k int) float64

PMF returns the probability mass function at k. P(X = k)

func (*Binomial) Sample

func (b *Binomial) Sample(nSamples int) []int

Sample generates n random samples from the distribution.

func (*Binomial) Variance

func (b *Binomial) Variance() float64

Variance returns the variance of the distribution.

type Normal

type Normal struct {
	Mean float64 // mean (μ)
	Std  float64 // standard deviation (σ)
	// contains filtered or unexported fields
}

Normal represents a normal (Gaussian) distribution.

func NewNormal

func NewNormal(mean, std float64) *Normal

NewNormal creates a new normal distribution.

func StandardNormal

func StandardNormal() *Normal

StandardNormal creates a standard normal distribution (mean=0, std=1).

func (*Normal) CDF

func (n *Normal) CDF(x float64) float64

CDF returns the cumulative distribution function at x. P(X <= x)

func (*Normal) MeanValue

func (n *Normal) MeanValue() float64

Mean returns the mean of the distribution.

func (*Normal) PDF

func (n *Normal) PDF(x float64) float64

PDF returns the probability density function at x.

func (*Normal) PPF

func (n *Normal) PPF(p float64) float64

PPF returns the percent point function (inverse CDF) at p. Also known as the quantile function.

func (*Normal) Sample

func (n *Normal) Sample(nSamples int) []float64

Sample generates n random samples from the distribution.

func (*Normal) Variance

func (n *Normal) Variance() float64

Variance returns the variance of the distribution.

type Uniform

type Uniform struct {
	Low  float64 // lower bound
	High float64 // upper bound
	// contains filtered or unexported fields
}

Uniform represents a continuous uniform distribution.

func NewUniform

func NewUniform(low, high float64) *Uniform

NewUniform creates a new uniform distribution over [low, high].

func (*Uniform) CDF

func (u *Uniform) CDF(x float64) float64

CDF returns the cumulative distribution function at x.

func (*Uniform) Mean

func (u *Uniform) Mean() float64

Mean returns the mean of the distribution.

func (*Uniform) PDF

func (u *Uniform) PDF(x float64) float64

PDF returns the probability density function at x.

func (*Uniform) PPF

func (u *Uniform) PPF(p float64) float64

PPF returns the percent point function (inverse CDF) at p.

func (*Uniform) Sample

func (u *Uniform) Sample(nSamples int) []float64

Sample generates n random samples from the distribution.

func (*Uniform) Variance

func (u *Uniform) Variance() float64

Variance returns the variance of the distribution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL