Empirical

vecxt_re.Empirical
See theEmpirical companion object
case class Empirical(values: IArray[Double], weights: IArray[Double]) extends DiscreteDistr[Double], HasMean[Double], HasVariance[Double], HasCdf[Double], HasInverseCdf

Empirical distribution (JVM only).

This is a nonparametric distribution built directly from observed samples. It supports positive weights $w_i$.

The distribution is represented as a discrete measure on the (possibly repeated) sample values: $$\mathbb{P}(X = x) = \sum_{i: x_i = x} \frac{w_i}{\sum_k w_k}.$$

Consequently, the CDF is a right-continuous step function $$F(t) = \mathbb{P}(X \le t) = \sum_{x \le t} \mathbb{P}(X=x).$$

Sampling is performed by inverse-transform sampling on the cumulative weights.

Note: Since this is an empirical (atomic) distribution, a density/PDF in the usual continuous sense is not defined. The plot method instead displays a (weighted) histogram density estimate.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait HasCdf[Double]
trait HasVariance[Double]
trait HasMean[Double]
trait DiscreteDistr[Double]
trait Rand[Double]
trait Density[Double]
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def cdf(x: Double): Double

CDF $F(t)=P(X\le t)$ (right-continuous).

CDF $F(t)=P(X\le t)$ (right-continuous).

Attributes

def draw: Double

Draw a sample using inverse CDF sampling over the atomic masses.

Draw a sample using inverse CDF sampling over the atomic masses.

Attributes

def inverseCdf(p: Double): Double

Inverse CDF (quantile function): returns the smallest x with F(x) >= p.

Inverse CDF (quantile function): returns the smallest x with F(x) >= p.

Attributes

def mean: Double
def plot(using LowPriorityPlotTarget): VizReturn

Plot a (weighted) histogram density estimate.

Plot a (weighted) histogram density estimate.

Attributes

def plot(mods: Seq[SpecMod])(using LowPriorityPlotTarget): VizReturn

As plot, applying mods (e.g. Plots.fixedSize) to the spec after the built-in modifications.

As plot, applying mods (e.g. Plots.fixedSize) to the spec after the built-in modifications.

Attributes

def plotCdf(using LowPriorityPlotTarget): VizReturn

Plot the empirical CDF (step function).

Plot the empirical CDF (step function).

Attributes

def plotCdf(mods: Seq[SpecMod])(using LowPriorityPlotTarget): VizReturn

As plotCdf, applying mods (e.g. Plots.fixedSize) to the spec after the built-in modifications.

As plotCdf, applying mods (e.g. Plots.fixedSize) to the spec after the built-in modifications.

Attributes

def probability(x: Double, y: Double): Double

Probability that $x < X \le y$.

Probability that $x < X \le y$.

Attributes

def probabilityOf(x: Double): Double

Probability mass at exactly x (sums weights for duplicates).

Probability mass at exactly x (sums weights for duplicates).

Attributes

def variance: Double

Inherited methods

def apply(x: Double): Double

Returns the unnormalized value of the measure

Returns the unnormalized value of the measure

Attributes

Inherited from:
DiscreteDistr
def drawOpt: Option[Double]

Overridden by filter/map/flatmap for monadic invocations. Basically, rejection samplers will return None here

Overridden by filter/map/flatmap for monadic invocations. Basically, rejection samplers will return None here

Attributes

Inherited from:
Rand
def flatMap[E](f: Double => Rand[E]): Rand[E]

Attributes

Inherited from:
Rand
inline def get: Double

Attributes

Inherited from:
Rand
override def logApply(x: Double): Double

Returns the log unnormalized value of the measure

Returns the log unnormalized value of the measure

Attributes

Definition Classes
Inherited from:
DiscreteDistr
def logProbabilityOf(x: Double): Double

Attributes

Inherited from:
DiscreteDistr
def map[E](f: Double => E): Rand[E]

Converts a random sampler of one type to a random sampler of another type. Examples: uniform.map(_2) gives a Rand[Double] in the range [0,2] Equivalently, for(x <- uniform) yield 2x

Converts a random sampler of one type to a random sampler of another type. Examples: uniform.map(_2) gives a Rand[Double] in the range [0,2] Equivalently, for(x <- uniform) yield 2x

Value parameters

f

the transform to apply to the sampled value.

Attributes

Inherited from:
Rand
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
inline def sample(n: Int): IndexedSeq[Double]

Gets n samples from the distribution.

Gets n samples from the distribution.

Attributes

Inherited from:
Rand
inline def sample: Double

Gets one sample from the distribution. Equivalent to get

Gets one sample from the distribution. Equivalent to get

Attributes

Inherited from:
Rand
def sampleTo[C](n: Int)(using factory: Factory[Double, C]): C

Gets n samples from the distribution into a specified collection type.

Gets n samples from the distribution into a specified collection type.

Attributes

Inherited from:
Rand
inline def samples: Iterator[Double]

An infinitely long iterator that samples repeatedly from the Rand

An infinitely long iterator that samples repeatedly from the Rand

Attributes

Returns

an iterator that repeatedly samples

Inherited from:
Rand
def unnormalizedLogProbabilityOf(x: Double): Double

Attributes

Inherited from:
DiscreteDistr
def unnormalizedProbabilityOf(x: Double): Double

Returns the probability of that draw up to a constant

Returns the probability of that draw up to a constant

Attributes

Inherited from:
DiscreteDistr
def withFilter(p: Double => Boolean): Rand[Double]

Attributes

Inherited from:
Rand