MultivariateNormal

MultivariateNormal

Multivariate Normal Distribution N(mean, Σ).

Produced by GaussianProcess.sampleAt(inputs). Stores the Cholesky factor L of the posterior covariance Σ (where Σ = L·Lᵀ). Sampling uses:

z ~ N(0, I) (draw each component via Box-Muller) x = mean + L·z → x ~ N(mean, Σ)

The isSingle flag mirrors the Rust PhantomData<T> mechanism: when the GP was queried at a single point (T = Vec<f64>) the output of mean() and sample() is a number; when queried at multiple points it is a number[].

Port notes:

  • Rust stores cholesky_covariance (already the lower-triangular factor L from nalgebra::Cholesky::unpack()). JS likewise stores only L after decomposing the covariance in the constructor.
  • Cholesky failure → throw (matches Rust .expect("...")).

Constructor

new MultivariateNormal(mean, covariance, isSingle)

Source:
Parameters:
Name Type Description
mean Array.<number>

posterior mean vector (length n)

covariance Array.<Array.<number>>

posterior covariance matrix (n×n), symmetric positive-definite

isSingle boolean

true when the GP input was a single point (number[]); false when multiple points (number[][])

Classes

MultivariateNormal

Members

_L :Array.<Array.<number>>

Description:
  • Lower-triangular Cholesky factor L of the covariance (Σ = L·Lᵀ).

Source:

Lower-triangular Cholesky factor L of the covariance (Σ = L·Lᵀ).

Type:
  • Array.<Array.<number>>

_isSingle :boolean

Source:
Type:
  • boolean

_mean :Array.<number>

Source:
Type:
  • Array.<number>

Methods

mean() → {number|Array.<number>}

Description:
  • Posterior mean.

    Returns a number when isSingle is true (single-point query), or a number[] when false (multi-point query).

Source:
Returns:
Type
number | Array.<number>

sample(rng) → {number|Array.<number>}

Description:
  • Draw one sample from N(mean, Σ).

    Algorithm (PORT_SPEC §8):

    1. z = [standardNormal(rng), …] (one N(0,1) per dimension)
    2. sampleVec = mean + L·z
    3. return fromVector(sampleVec, isSingle)

    rng must be a () => number ∈ [0, 1) function, e.g. the closure returned by mulberry32(seed). The output type mirrors mean().

    Numeric note: the PRNG and Box-Muller implementation differ from Rust's rand/rand_distr, so sample values will not match Rust bit-for-bit. Statistical correctness and reproducibility given a seed are guaranteed.

Source:
Parameters:
Name Type Description
rng
Returns:
Type
number | Array.<number>