probula

package probula

Members list

Type members

Classlikes

class Bernoulli[T](val name: Name)(p: Prob, success: T, failure: T) extends Dist[T], HasDensity[T]

Attributes

Companion
object
Supertypes
trait HasDensity[T]
trait Dist[T]
trait CanSample[T]
trait Named
class Object
trait Matchable
class Any
Show all
object Bernoulli

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Bernoulli.type
final case class Binned[T]

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Binned

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Binned.type
class Binomial(val name: Name)(n: Int, p: Prob) extends Dist[Int], HasDensity[Int]

Attributes

Companion
object
Supertypes
trait HasDensity[Int]
trait Dist[Int]
trait CanSample[Int]
trait Named
class Object
trait Matchable
class Any
Show all
object Binomial

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Binomial.type
trait CanSample[+T]

A distribution from which we can draw samples

A distribution from which we can draw samples

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Dist[T]
class Bernoulli[T]
class Binomial
class Dirac[T]
trait DistD
class Exponential
class Gaussian
class Laplace
class UniformC
class Poisson
class Uniform[T]
class UniformProb
Show all
object Chain

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Chain.type
object Cloglog extends Link

Attributes

Supertypes
trait Link
class Object
trait Matchable
class Any
Self type
Cloglog.type
class Dirac[T](val name: Name)(val value: T) extends Dist[T], HasDensity[T]

Attributes

Companion
object
Supertypes
trait HasDensity[T]
trait Dist[T]
trait CanSample[T]
trait Named
class Object
trait Matchable
class Any
Show all
object Dirac

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Dirac.type
trait Dist[+T] extends Named, CanSample[T]

A representation of probabilistic models as multivariate distributions, effectively hierarchical Bayesian models.

A representation of probabilistic models as multivariate distributions, effectively hierarchical Bayesian models.

Attributes

Companion
object
Supertypes
trait CanSample[T]
trait Named
class Object
trait Matchable
class Any
Known subtypes
class Bernoulli[T]
class Binomial
class Dirac[T]
trait DistD
class Exponential
class Gaussian
class Laplace
class UniformC
class Poisson
class Uniform[T]
class UniformProb
Show all
Self type
Dist[T]
object Dist

A bit of internal DSL magic

A bit of internal DSL magic

Arity-1 convenience extensions live inside the Dist companion so the given is auto-imported (Scala 3 searches companion objects for given instances). The given wrapper makes NotGiven[T <:< Tuple] resolve during given search (not overload resolution, which ignores using constraints).

Overloaded extension methods do compete with trait methods (apparently then the trait methods are tried only) — for this reason even Dist[T] must use extensions, so that we can support other arities.

Arity-1 extensions cannot be simply extensions on Dist[T] because then they also apply to tuples, which have their own extensions.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Dist.type
trait DistD extends Dist[Double], HasCdf[Double]

Base trait for Dist[Double] primitives backed by a commons-math AbstractRealDistribution. Subclasses supply two factories: one unbound (for density and CDF queries), one wired to a caller's RNG (for sampling).

Base trait for Dist[Double] primitives backed by a commons-math AbstractRealDistribution. Subclasses supply two factories: one unbound (for density and CDF queries), one wired to a caller's RNG (for sampling).

Attributes

Supertypes
trait HasCdf[Double]
trait Dist[Double]
trait CanSample[Double]
trait Named
class Object
trait Matchable
class Any
Show all
Known subtypes
class Exponential
class Gaussian
class Laplace
class UniformC
Self type
class Doubles(val from: Double, val to: Double, val step: Double) extends IndexedSeq[Double]

An inclusive range of Double values with a fixed step.

An inclusive range of Double values with a fixed step.

Usage:

Doubles(0.0 -> 1.0) by 0.1
Doubles(0.0, 1.0) points 100
50 doubles (0.0 -> 1.0)

Attributes

Companion
object
Supertypes
object Doubles

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Doubles.type
class Exponential(val name: Name)(lambda: Double) extends DistD

Exponential distribution

Exponential distribution

Attributes

Companion
object
Supertypes
trait DistD
trait HasCdf[Double]
trait Dist[Double]
trait CanSample[Double]
trait Named
class Object
trait Matchable
class Any
Show all
object Exponential

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
class Gaussian(val name: Name)(mean: Double, stdDev: Double) extends DistD

Attributes

Companion
object
Supertypes
trait DistD
trait HasCdf[Double]
trait Dist[Double]
trait CanSample[Double]
trait Named
class Object
trait Matchable
class Any
Show all
object Gaussian

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Gaussian.type
trait HasCdf[T] extends HasDensity[T]

A density with a cumulative distribution function. Carries the canonical truncated operation as a default-implemented method, derivable from cdf.

A density with a cumulative distribution function. Carries the canonical truncated operation as a default-implemented method, derivable from cdf.

Composed densities from _flatMap, dep variants, and likelihood stay at HasDensity[T] (no CDF), so the type system blocks truncated on receivers where CDF does not compose cleanly.

Attributes

Supertypes
trait HasDensity[T]
class Object
trait Matchable
class Any
Known subtypes
trait DistD
class Exponential
class Gaussian
class Laplace
class UniformC
class UniformProb
Show all
Self type
Dist[T]
trait HasDensity[-T]

A distribution with a computable unnormalized density function

A distribution with a computable unnormalized density function

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Bernoulli[T]
class Binomial
class Dirac[T]
trait HasCdf[T]
trait DistD
class Exponential
class Gaussian
class Laplace
class UniformC
class UniformProb
class Poisson
class Uniform[T]
Show all
class IData[+T](val name: Name, val chain: Chain[T]) extends Named

Representation of Inference Data. The intention is to make it compatible with the inference data in the Python world (one day...)

Representation of Inference Data. The intention is to make it compatible with the inference data in the Python world (one day...)

Attributes

Supertypes
trait Named
class Object
trait Matchable
class Any
class Laplace(val name: Name)(mean: Double, scale: Double) extends DistD

Laplace (double-exponential) distribution on the real line. Heavier-tailed than Gaussian, with a sharp peak at mean. scale is the canonical Laplace scale parameter b — not the standard deviation (Laplace stdDev = √2·scale).

Laplace (double-exponential) distribution on the real line. Heavier-tailed than Gaussian, with a sharp peak at mean. scale is the canonical Laplace scale parameter b — not the standard deviation (Laplace stdDev = √2·scale).

Attributes

Companion
object
Supertypes
trait DistD
trait HasCdf[Double]
trait Dist[Double]
trait CanSample[Double]
trait Named
class Object
trait Matchable
class Any
Show all
object Laplace

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Laplace.type
trait Link

A link function for a GLM: a monotone bijection between the mean scale (a probability) and the linear-predictor scale (the real line).

A link function for a GLM: a monotone bijection between the mean scale (a probability) and the linear-predictor scale (the real line).

Implementations must satisfy, up to floating-point error: inverse(apply(μ)) == μ for μ in (0, 1) apply(inverse(η)) == η for finite η

The endpoints map to ±∞ and do not round-trip.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Cloglog
object Logit
object Probit
object LogScore

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
LogScore.type
object Logit extends Link

Attributes

Supertypes
trait Link
class Object
trait Matchable
class Any
Self type
Logit.type
enum Name

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
trait Named

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Dist[T]
class Bernoulli[T]
class Binomial
class Dirac[T]
trait DistD
class Exponential
class Gaussian
class Laplace
class UniformC
class Poisson
class Uniform[T]
class UniformProb
class IData[T]
Show all

Witness that all components of T can be decomposed into Doubles. Works for bare numeric scalars (via Numeric) and tuples of numerics (recursively).

Witness that all components of T can be decomposed into Doubles. Works for bare numeric scalars (via Numeric) and tuples of numerics (recursively).

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
class Poisson(val name: Name)(lambda: Double) extends Dist[Int], HasDensity[Int]

Attributes

Companion
object
Supertypes
trait HasDensity[Int]
trait Dist[Int]
trait CanSample[Int]
trait Named
class Object
trait Matchable
class Any
Show all
object Poisson

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Poisson.type
object Prob

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Prob.type
object Probit extends Link

Attributes

Supertypes
trait Link
class Object
trait Matchable
class Any
Self type
Probit.type
object Probula

The Probula object is used as an entry point to the framework. One starts building a probula probabilistic model by using factory methods from this object. Once the model is initiated (the first variable is created), one can use the model methods (@see probula.Dist) to add more new variables, hierarchical dependencies, and observations.

The Probula object is used as an entry point to the framework. One starts building a probula probabilistic model by using factory methods from this object. Once the model is initiated (the first variable is created), one can use the model methods (@see probula.Dist) to add more new variables, hierarchical dependencies, and observations.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Probula.type
object Scored

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Scored.type
trait TupleModel[H, L]

The TupleModel trait is used to hide the model structure for typed functional programming (for instance if the internal type is a tuple, and the shape is manipulated in an iteration, like a fold)

The TupleModel trait is used to hide the model structure for typed functional programming (for instance if the internal type is a tuple, and the shape is manipulated in an iteration, like a fold)

Value parameters

H

The type of the first component of the model

L

The type of the last (most recently appended) component of the model

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object TupleModel

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
TupleModel.type
abstract class Uniform[T](val name: Name) extends Dist[T], HasDensity[T]

Attributes

Companion
object
Supertypes
trait HasDensity[T]
trait Dist[T]
trait CanSample[T]
trait Named
class Object
trait Matchable
class Any
Show all
object Uniform

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
Uniform.type
class UniformC(val name: Name)(lo: Double, hi: Double) extends DistD

Attributes

Companion
object
Supertypes
trait DistD
trait HasCdf[Double]
trait Dist[Double]
trait CanSample[Double]
trait Named
class Object
trait Matchable
class Any
Show all
object UniformC

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
UniformC.type
class UniformProb(val name: Name)(lo: Prob, hi: Prob) extends Dist[Prob], HasCdf[Prob]

A UniformC(0.0, 1.0) retyped as Dist[Prob]. Lets a model's probability parameters stay in the Prob opaque type rather than being lifted from Double at every use.

A UniformC(0.0, 1.0) retyped as Dist[Prob]. Lets a model's probability parameters stay in the Prob opaque type rather than being lifted from Double at every use.

Attributes

Companion
object
Supertypes
trait HasCdf[Prob]
trait HasDensity[Prob]
trait Dist[Prob]
trait CanSample[Prob]
trait Named
class Object
trait Matchable
class Any
Show all
object UniformProb

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type

Types

opaque type Chain[+T]
opaque type LogScore
opaque type Prob
type RNG = Generator
type RNG1 = RandomGenerator

Commons-Math-flavoured view of RNG. Distributions that delegate to commons-math samplers consume this type.

Commons-Math-flavoured view of RNG. Distributions that delegate to commons-math samplers consume this type.

FIXME: when spire is dropped, RNG becomes org.apache.commons.math3.random.RandomGenerator. This alias is then renamed to RNG and toRNG1 is deleted.

Attributes

opaque type SampleSize
opaque type Scored[+T]

Value members

Concrete methods

def chain[T](l: Seq[Scored[T]]): Chain[T]
def scored[T](value: T, logScore: LogScore): Scored[T]
def unScored[T](value: T): Scored[T]

Extensions

Extensions

extension [T](b: Binned[Scored[T]])
extension (idata: IData[_])
def csv: String

Export inference data as a CSV string. Columns: sample, one per variable, log_weight. Variable names are derived from this IData's Name.

Export inference data as a CSV string. Columns: sample, one per variable, log_weight. Variable names are derived from this IData's Name.

Attributes

extension (n: SampleSize)
infix def *(m: Int): SampleSize
def toInt: Int
extension (n: Int)
extension (n: Int)
infix def doubles(range: (Double, Double)): Doubles

50 doubles (0.0 -> 1.0)

50 doubles (0.0 -> 1.0)

Attributes

extension (names: (Name, Name))
def toName: Name
extension (names: (Name, Name, Name))
def toName: Name
extension (p: Double)
infix def -(q: Prob): Prob
infix def <=(q: Prob): Boolean
def pr: Prob

Note that this.p has to be a log probability mass, not a density

Note that this.p has to be a log probability mass, not a density

Attributes

extension (s: String)
def toName: Name
extension [S, T](self: Dist[(S, T)])
def _1: Dist[S]
def _2: Dist[T]
extension [T](self: Chain[T])
def expectedValue[S >: T : Numeric]: Double

Same as mean.

Same as mean.

Attributes

def mean[S >: T](using num: Numeric[S]): Double

Compute a mean for a numeric sample. A numerically stable way to compute this, similar to LogSumExp, but exploiting that max cancels out in the numerator and denominator.

Compute a mean for a numeric sample. A numerically stable way to compute this, similar to LogSumExp, but exploiting that max cancels out in the numerator and denominator.

Attributes

def median[S >: T : Ordering]: S

Compute a median of a sample with a defined Ordering.

Compute a median of a sample with a defined Ordering.

For simplicity we drop one element if the sample is of even length. Typically to be used on a univariate sample of numbers (then the ordering exists).

It requires that the chain is finite! Otherwise it will crash.

Attributes

def percentile[S >: T](q: Double)(using num: Numeric[S]): Double

Compute a weighted percentile for a numeric sample. Returns the value below which fraction q of the weighted mass falls. Linearly interpolates between the two bracketing values when the threshold falls between samples.

Compute a weighted percentile for a numeric sample. Returns the value below which fraction q of the weighted mass falls. Linearly interpolates between the two bracketing values when the threshold falls between samples.

Uses the same weighted cumulative mass approach as median, generalized to an arbitrary threshold.

Value parameters

q

the quantile in [0, 1] (e.g. 0.5 for the median, 0.055 for the 5.5th percentile)

Attributes

def stdDev[S >: T : Numeric]: Double

Compute the standard deviation for a numeric sample. This is the square root of the variance.

Compute the standard deviation for a numeric sample. This is the square root of the variance.

Attributes

def variance[S >: T](using num: Numeric[S]): Double

Compute a sample variance for a numeric sample. Uses the unbiased weighted estimator (a generalization of Bessel's correction for weighted samples, for example see reliability weights in https://en.wikipedia.org/wiki/Weighted_arithmetic_mean #Related_concepts): Var = sum wi(xi - mu)^2 * V1 / (V1^2 - V2) where V1 = sum wi, V2 = sum wi^2. For uniform weights this reduces to sum(xi - mu)^2/(n-1). Uses the max-subtraction trick (as in mean) for numerical stability when log-scores are very negative.

Compute a sample variance for a numeric sample. Uses the unbiased weighted estimator (a generalization of Bessel's correction for weighted samples, for example see reliability weights in https://en.wikipedia.org/wiki/Weighted_arithmetic_mean #Related_concepts): Var = sum wi(xi - mu)^2 * V1 / (V1^2 - V2) where V1 = sum wi, V2 = sum wi^2. For uniform weights this reduces to sum(xi - mu)^2/(n-1). Uses the max-subtraction trick (as in mean) for numerical stability when log-scores are very negative.

Attributes

extension [T](self: Seq[Dist[T]])
def sequence: Dist[Seq[T]]
extension [T1, T2, T3](self: Dist[(T1, T2, T3)])
def _1: Dist[T1]
def _2: Dist[T2]
def _3: Dist[T3]
extension [T](self: Seq[T])
def plate[U](name: Name)(f: T => Dist[U]): Dist[Seq[U]]

The plate members are named name0...nameN, where N = self.size - 1. The list node is named name.

The plate members are named name0...nameN, where N = self.size - 1. The list node is named name.

Attributes

def plate[U](name: String)(f: T => Dist[U]): Dist[Seq[U]]

The plate members are named name0...nameN, where N = self.size - 1. The list node is named name.

The plate members are named name0...nameN, where N = self.size - 1. The list node is named name.

Attributes

def plate[U](f: T => Dist[U]): Dist[Seq[U]]

Neither the plate or its members are named.

Neither the plate or its members are named.

Attributes

def plate[U](name: Name)(f: (T, Int) => Dist[U]): Dist[Seq[U]]

You need to name your plate members yourself. Name name is given to the overall Dist[Seq[U]] node

You need to name your plate members yourself. Name name is given to the overall Dist[Seq[U]] node

Attributes

def plate[U](name: String)(f: (T, Int) => Dist[U]): Dist[Seq[U]]

You need to name your plate members yourself. Name name is given to the overall Dist[Seq[U]] node

You need to name your plate members yourself. Name name is given to the overall Dist[Seq[U]] node

Attributes

def plate[U](f: (T, Int) => Dist[U]): Dist[Seq[U]]

You need to name your plate members yourself. The overall node is not named.

You need to name your plate members yourself. The overall node is not named.

Attributes

def traverse[U](f: T => Dist[U]): Dist[Seq[U]]
extension [T1, T2, T3, T4](self: Dist[(T1, T2, T3, T4)])
def _1: Dist[T1]
def _2: Dist[T2]
def _3: Dist[T3]
def _4: Dist[T4]
extension [T <: NonEmptyTuple](self: Dist[T])
def last: Dist[Last[T]]
extension [S, T](self: IData[(S, T)])
def _1: IData[S]
def _2: IData[T]
extension [T1, T2, T3](self: IData[(T1, T2, T3)])
def _1: IData[T1]
def _2: IData[T2]
def _3: IData[T3]
extension [T](self: Seq[Dist[T] & HasDensity[T]])
def sequence: Dist[Seq[T]] & HasDensity[Seq[T]]
extension [T1, T2, T3, T4](self: IData[(T1, T2, T3, T4)])
def _1: IData[T1]
def _2: IData[T2]
def _3: IData[T3]
def _4: IData[T4]
extension [T](self: Seq[T])
def plateD[U](name: Name)(f: T => Dist[U] & HasDensity[U]): Dist[Seq[U]] & HasDensity[Seq[U]]

The plate members are named name0...nameN, where N = self.size - 1. The list node is named name.

The plate members are named name0...nameN, where N = self.size - 1. The list node is named name.

Attributes

def plateD[U](name: String)(f: T => Dist[U] & HasDensity[U]): Dist[Seq[U]] & HasDensity[Seq[U]]

The plate members are named name0...nameN, where N = self.size - 1. The list node is named name.

The plate members are named name0...nameN, where N = self.size - 1. The list node is named name.

Attributes

def plateD[U](f: T => Dist[U] & HasDensity[U]): Dist[Seq[U]] & HasDensity[Seq[U]]

Neither the plate or its members are named.

Neither the plate or its members are named.

Attributes

def plateD[U](name: Name)(f: (T, Int) => Dist[U] & HasDensity[U]): Dist[Seq[U]] & HasDensity[Seq[U]]

You need to name your plate members yourself. Name name is given to the overall Dist[Seq[U]] node

You need to name your plate members yourself. Name name is given to the overall Dist[Seq[U]] node

Attributes

def plateD[U](name: String)(f: (T, Int) => Dist[U] & HasDensity[U]): Dist[Seq[U]] & HasDensity[Seq[U]]

You need to name your plate members yourself. Name name is given to the overall Dist[Seq[U]] node

You need to name your plate members yourself. Name name is given to the overall Dist[Seq[U]] node

Attributes

def plateD[U](f: (T, Int) => Dist[U] & HasDensity[U]): Dist[Seq[U]] & HasDensity[Seq[U]]

You need to name your plate members yourself. The overall node is not named.

You need to name your plate members yourself. The overall node is not named.

Attributes

def traverseD[U](f: T => Dist[U] & HasDensity[U]): Dist[Seq[U]] & HasDensity[Seq[U]]

Unfortunately, these methods cannot be called traverse/plate, etc., as resolution based on argument's return type is very brittle. Does not work if they are in the same type hierarchy Dist[U] & HasDensity[U] <: Dist[U]. We get a conflict with the non-density traverse.

Unfortunately, these methods cannot be called traverse/plate, etc., as resolution based on argument's return type is very brittle. Does not work if they are in the same type hierarchy Dist[U] & HasDensity[U] <: Dist[U]. We get a conflict with the non-density traverse.

Attributes

extension [S, T <: Tuple](self: IData[S *: T])
def _1: IData[S]
extension [T](self: IData[T])
def expectedValue[S >: T : Numeric]: Double

Same as mean.

Same as mean.

Attributes

def mean[S >: T : Numeric]: Double

Delegator to Chain.mean.

Delegator to Chain.mean.

Attributes

def median[S >: T : Ordering]: S

Delegator to Chain.median.

Delegator to Chain.median.

Attributes

def percentile[S >: T : Numeric](q: Double): Double

Delegator to Chain.percentile.

Delegator to Chain.percentile.

Attributes

def stdDev[S >: T : Numeric]: Double

Delegator to Chain.stdDev.

Delegator to Chain.stdDev.

Attributes

def variance[S >: T : Numeric]: Double

Delegator to Chain.variance.

Delegator to Chain.variance.

Attributes

extension [T](self: Chain[T])(using nd: NumericDecomposition[T])
def project(i: Int): Chain[Double]

Extract the i-th numeric variable as a Chain[Double], preserving log-scores.

Extract the i-th numeric variable as a Chain[Double], preserving log-scores.

Attributes

extension [T](self: IData[T])
def precis(histogram: Boolean)(using nd: NumericDecomposition[T]): String

A summary table of the posterior, showing mean, standard deviation, the 89% percentile interval (5.5% to 94.5%), and a sparkline histogram for each variable. Inspired by McElreath's precis.

A summary table of the posterior, showing mean, standard deviation, the 89% percentile interval (5.5% to 94.5%), and a sparkline histogram for each variable. Inspired by McElreath's precis.

Value parameters

histogram

whether to include a sparkline histogram column (default: true)

Attributes

extension [T](t: T)(using ord: Ordering[T])
def clamp(lo: T, hi: T): T

Clamps to [lo, hi]: returns lo below the range, hi above it.

Clamps to [lo, hi]: returns lo below the range, hi above it.

Attributes

extension [T](xs: IterableOnce[T])
def binBy(num: Int, lo: Double, hi: Double)(f: T => Double): Binned[T]
def binBy(num: Int)(f: T => Double): Binned[T]
extension (xs: IterableOnce[Double])
def binned(num: Int, lo: Double, hi: Double): Binned[Double]
def binned(num: Int): Binned[Double]