Skip to content

Distributions

Probability distributions with a uniform sample / log_pdf API, used as return types of the StateSpaceModel distribution-level interface.

quantflow.dists.Distribution pydantic-model

Bases: BaseModel, ABC

Base class for distributions.

sample abstractmethod

sample(size=1)

Draw random samples from the distribution.

PARAMETER DESCRIPTION
size

Number of samples to draw.

TYPE: int DEFAULT: 1

Source code in quantflow/dists/base.py
@abstractmethod
def sample(
    self,
    size: Annotated[int, Doc("Number of samples to draw.")] = 1,
) -> FloatArray:
    """Draw random samples from the distribution."""
    ...

log_pdf abstractmethod

log_pdf(x)

Log probability density at \(x\).

PARAMETER DESCRIPTION
x

Point at which to evaluate the log-density.

TYPE: FloatArray

Source code in quantflow/dists/base.py
@abstractmethod
def log_pdf(
    self,
    x: Annotated[FloatArray, Doc("Point at which to evaluate the log-density.")],
) -> FloatArray:
    """Log probability density at $x$."""
    ...

mean_and_cov abstractmethod

mean_and_cov()

Mean vector and covariance matrix of the distribution.

Source code in quantflow/dists/base.py
@abstractmethod
def mean_and_cov(self) -> MeanAndCov:
    """Mean vector and covariance matrix of the distribution."""
    ...

quantflow.dists.MvNormal pydantic-model

Bases: Distribution

Multivariate normal distribution \(\mathcal{N}(\mu, \Sigma)\).

Fields:

mean pydantic-field

mean

cov pydantic-field

cov

sample

sample(size=1)
Source code in quantflow/dists/mv_normal.py
def sample(self, size: int = 1) -> FloatArray:
    return np.asarray(
        multivariate_normal(mean=self.mean, cov=self.cov).rvs(size=size)
    )

log_pdf

log_pdf(x)
Source code in quantflow/dists/mv_normal.py
def log_pdf(self, x: FloatArray) -> FloatArray:
    return np.asarray(multivariate_normal(mean=self.mean, cov=self.cov).logpdf(x))

mean_and_cov

mean_and_cov()
Source code in quantflow/dists/mv_normal.py
def mean_and_cov(self) -> MeanAndCov:
    return MeanAndCov(self.mean, self.cov)