skoro v0.0.0

The normal distribution

skoro's normal is the law of a point moved by normal noise through its space's chart, on every space whose chart is global, with an exact density and sampler, a scale in four forms, roles that estimators read, its tangent among them, and the Gaussian and improper Gaussian replacements of a retirement.

The normal is the distribution most of skoro’s models are written with, and lives in a crate of its own, skoro-normal, built on the core’s public interface alone. It is one distribution on every space it can be exact on: the familiar normal on the real line, vectors and matrices, the log-normal on the positive orthant, and on a curved type, such as a sphere or the rotations, the normal of its tangent chart pushed onto it. This page shows what it is made of: a term, a sampler, and the roles an estimator reads.

The law and its term#

The normal N(μ,Σ)\mathcal N(\mu, \Sigma) on a space is the law of μ⊕ε\mu \oplus \varepsilon, the mean moved by noise ε\varepsilon normal in its tangent coordinates, with mean zero and covariance Σ\Sigma. Its log-density is the Gaussian log-density of x⊖μ\point \ominus \mu, less the log-volume of the chart at μ\mu there, which is what makes it a density against the space’s reference measure:

ℓ(x; μ,W)=−12∣W(x⊖μ)∣2+∑ilog⁡Wii−d2log⁡2π−λμ(x⊖μ), \ell(\point;\, \mu, W) = -\tfrac12 \bigl\lvert W (\point \ominus \mu) \bigr\rvert^2 + \sum_{i} \log W_{ii} - \tfrac{\dimension}{2} \log 2\pi - \lambda_\mu(\point \ominus \mu) ,

where WW, the whitening, is the lower-triangular factor with W⊤W=Σ−1W\transpose W = \Sigma^{-1}, and W(x⊖μ)W (\point \ominus \mu) is the whitened residual. The note on the normal distribution in a chart proves that this is the density of μ⊕ε\mu \oplus \varepsilon, by way of densities in tangent charts, and works out what the mean and the scale mean once the space is curved. A normal is made from its space, its mean and its scale:

crates/skoro-normal/src/normal.rs lines 26–37
/// The normal `𝒩(μ, Σ)` on a space, by its mean and scale: a term to add, or a factor.
///
/// On a curved type the scale is in the coordinates of the chart, and the mean is a mode only
/// while every eigenvalue of `Σ` is below one. Beyond that the mass goes towards the chart's cut,
/// the half-turns from the mean on `Rotation`, so a large scale does not say that nothing is
/// known of a quantity: `skoro_uniform::Uniform` does.
#[derive(Clone, Debug)]
pub struct Normal {
    space: Space,
    mean: QDyn,
    scale: Scale,
}
crates/skoro-normal/src/normal.rs lines 52–65
impl Normal {
    /// The normal on the space `marker` declares.
    pub fn on<T: Declares>(marker: T, mean: Q<T>, scale: Scale) -> Normal {
        Normal::in_space(marker.space(), mean, scale)
    }

    /// The normal on `space`, for a product or any handle without a declaring marker.
    pub fn in_space(space: Space, mean: impl Into<QDyn>, scale: Scale) -> Normal {
        Normal {
            space,
            mean: mean.into(),
            scale,
        }
    }

Normal::on reads the space from the marker a quantity was made with; Normal::in_space takes the space itself, for a product, whose marker declares none. The term is built from the core’s operations, as any value of a model is: the tangent by the space’s inverse retraction, the residual and the normalizer by composites of the scale’s form, and the log-volume by the core’s:

crates/skoro-normal/src/normal.rs lines 156–182
/// `x ⊖ μ`, `W (x ⊖ μ)` and the Gaussian log-density of `x ⊖ μ`, in the open scope.
#[track_caller]
fn gaussian(&self, x: QDyn) -> (QDyn, QDyn, QDyn) {
    let Some(d) = self.space.dimension() else {
        let failed = refuse(
            Error::NotContinuous {
                space: self.space.clone(),
            },
            &[x],
        );
        return (failed, failed, failed);
    };
    let form = self.scale.form();
    let composites = whiten(form, d).and_then(|w| Ok((w, normalizer(form, d)?)));
    let (whiten, normalizer) = match composites {
        Ok(composites) => composites,
        Err(error) => {
            let failed = refuse(error, &[x]);
            return (failed, failed, failed);
        }
    };
    let tangent = x.local(self.mean);
    let scale = self.scale.value();
    let residual = whiten.call(&[tangent, scale]);
    let gaussian = (residual * residual).sum() * -0.5 + normalizer.call(&[scale]);
    (tangent, residual, gaussian)
}
crates/skoro-normal/src/normal.rs lines 124–140
/// The term's nodes at `x`, added to the model with no term: what `score` scores.
#[track_caller]
pub fn log_density(&self, x: impl Into<QDyn>) -> Parts {
    let x = x.into();
    let (tangent, residual, gaussian) = self.gaussian(x);
    let log_volume = (!euclidean(&self.space)).then(|| self.mean.log_volume(tangent));
    let log_density = match log_volume {
        Some(lambda) => gaussian - lambda,
        None => gaussian,
    };
    Parts {
        tangent: tangent.narrow(),
        residual: residual.narrow(),
        log_volume: log_volume.map(QDyn::narrow),
        log_density: log_density.narrow(),
    }
}

On a Euclidean space the log-volume is identically zero and left out. On the positive orthant it is ∑ilog⁡xi\sum_i \log \point_i, so the normal there is the log-normal with median μ\mu, offered under the normal’s name. On a curved type it is the one the type declares. Every step has derivatives of both orders, so the term has them too, and a query differentiates it like any other.

A measurement of a curved quantity is a normal with a computed mean: z=h(x)⊕εz = h(\point) \oplus \varepsilon is Normal::on(marker, h, scale).score(z), and zz is a quantity, observed in one query and drawn in another.

Scoring a quantity#

score adds the term, an exact sampler, and the roles:

crates/skoro-normal/src/normal.rs lines 79–122
/// Scores `x`: the term, its exact sampler and its roles. Refuses a space without a measure
/// (`NoVolume`), a discrete one (`NotContinuous`) and one whose chart is not global
/// (`SpaceMismatch` of `skoro.normal`), recording the refusal at the caller's line.
/// [`sample`](skoro_core::scope::sample) declares a quantity and scores it by a normal in one
/// call.
#[track_caller]
pub fn score(&self, x: impl Into<QDyn>) -> TermHandle {
    let x = x.into();
    let form = self.scale.form();
    let d = self.space.dimension().unwrap_or(0);
    let sample = match self.space.domain() {
        Ok(Domain::Global) => NormalSample::new(self.space.clone(), form, d)
            .and_then(|sample| Ok((sample, root(form, d)?))),
        Ok(Domain::Within(_)) => Err(Error::SpaceMismatch {
            operation: "skoro.normal",
            inputs: vec![self.space.clone()],
        }),
        Err(error) => Err(error),
    };
    let (sample, root) = match sample {
        Ok(parts) => parts,
        Err(error) => {
            let failed = refuse(error, &[x]);
            return score(failed.narrow::<Scored>(), failed.narrow());
        }
    };
    let parts = self.log_density(x);
    let scale = self.scale.value();
    let mut term = score(x.narrow::<Scored>(), parts.log_density)
        .sampler(Sampler {
            sample: Arc::new(sample),
            inputs: vec![self.mean, scale],
            log_density: None,
        })
        .bind(&roles::RESIDUAL, parts.residual)
        .bind(&roles::MEAN, self.mean)
        .bind(&roles::TANGENT, parts.tangent)
        .bind(roles::scale(form), scale)
        .bind(&roles::INFORMATION_ROOT, root.call(&[scale]));
    if let Some(log_volume) = parts.log_volume {
        term = term.bind(&roles::LOG_VOLUME, log_volume);
    }
    term
}

It refuses what it cannot be exact on, at the caller’s line, with the core’s own errors: a discrete space, a space without a reference measure, and a space whose chart is not global.

A normal is a Distribution by this score, so the core’s sample makes a quantity and scores it by a normal in one call, sample("x", Real, normal), building what quantity("x", Real) and normal.score(x) build:

crates/skoro-normal/src/normal.rs lines 185–191
/// The normal's term, by [`Normal::score`].
impl Distribution for Normal {
    #[track_caller]
    fn score(&self, x: QDyn) -> TermHandle {
        Normal::score(self, x)
    }
}

The scale#

The scale is given in whichever of four forms a model has it, and each is read through WW:

crates/skoro-normal/src/scale.rs lines 8–19
/// Which of the four forms of the scale a value is, read through `W` in every one.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum Form {
    /// `σ ∈ ℝ>0`, `Σ = σ²I`: a `Positive(1)`.
    Isotropic,
    /// `σ ∈ ℝ>0^d`, `Σ = diag(σ)²`: a `Positive(d)`.
    Diagonal,
    /// `L` with `Σ = LLᵀ`: a `triangular(d)`.
    CovarianceFactor,
    /// `W` with `Λ = WᵀW`: a `triangular(d)`.
    Whitening,
}

A standard deviation or a vector of them needs no linear algebra; a covariance factor LL is what a user with a full covariance writes, and its residual is solved by forward substitution; a whitening WW is what a precision, and a retirement’s replacement, arrive in. When a scale is estimated, a triangular factor is a quantity of the core’s product of its positive diagonal and the entries below it, column by column:

crates/skoro-normal/src/scale.rs lines 40–53
/// The space of a lower-triangular factor of side `d` with a positive diagonal: the diagonal, then
/// the entries strictly below it column by column, `Product([Positive(d), Vector(d(d-1)/2)])`, and
/// `Product([Positive(1)])` when `d = 1`.
pub fn triangular(d: usize) -> Space {
    let diagonal = Space::Positive(d);
    let lower = d * d.saturating_sub(1) / 2;
    let factors = if lower == 0 {
        vec![diagonal]
    } else {
        vec![diagonal, Space::Vector(lower)]
    };
    // Neither factor is discrete, so the product is never refused.
    Space::Product(factors.into())
}

Constant scales have helpers, which factor a covariance or a precision on the host:

crates/skoro-normal/src/scale.rs lines 88–114
/// The constant isotropic scale `σ`.
#[track_caller]
pub fn sd(sigma: f64) -> Scale {
    Scale::isotropic(constant(Positive::<1>, [sigma]))
}

/// The constant diagonal scale `σ`.
#[track_caller]
pub fn sds(sigma: &[f64]) -> Scale {
    Scale::diagonal(constant(PositiveDyn(sigma.len()), sigma))
}

/// The covariance `Σ`, `d × d` row by row, as the constant Cholesky factor `L` with
/// `Σ = LLᵀ`; a matrix that is not symmetric positive definite is refused (`ValueShape`).
#[track_caller]
pub fn covariance(sigma: &[f64], d: usize) -> Scale {
    let factor = symmetric(sigma, d).and_then(|sigma| cholesky(&sigma, d));
    Scale::covariance_factor(triangular_constant(factor, d))
}

/// The precision `Λ`, `d × d` row by row, as the constant lower-triangular `W` with
/// `Λ = WᵀW`; a matrix that is not symmetric positive definite is refused (`ValueShape`).
#[track_caller]
pub fn precision(lambda: &[f64], d: usize) -> Scale {
    let factor = symmetric(lambda, d).and_then(|lambda| whitening_factor(&lambda, d));
    Scale::whitening(triangular_constant(factor, d))
}

The composites that read the scale are defined once per form and dimension:

crates/skoro-normal/src/composites.rs lines 80–105
Part::Whiten => {
    let matrix = match form {
        Form::Whitening => Some(matrix(d)?),
        _ => None,
    };
    Composite::define(
        "skoro.normal.whiten",
        params,
        &[Space::Vector(d), scale],
        |q| match (form, &matrix) {
            (Form::Isotropic, _) => q[1].recip().as_real().sum() * q[0],
            (Form::Diagonal, _) => q[1].recip().as_real() * q[0],
            (Form::Whitening, Some(matrix)) => matrix.call(&[q[1]]).matmul(q[0]),
            _ => forward_substitution(q[1], q[0], d),
        },
    )
}
Part::Normalizer => Composite::define("skoro.normal.normalizer", params, &[scale], |q| {
    let log_diagonal = match form {
        Form::Isotropic => q[0].log().sum() * -(d as f64),
        Form::Diagonal => -q[0].log().sum(),
        Form::CovarianceFactor => -q[0].factor(0).log().sum(),
        Form::Whitening => q[0].factor(0).log().sum(),
    };
    log_diagonal + -0.5 * d as f64 * (2.0 * PI).ln()
}),

The sampler#

The normal draws μ⊕L Φ−1(u)\mu \oplus L\, \Phi^{-1}(u), with L=W−1L = W^{-1} and uu the d\dimension uniform variates of the quantity’s random key, on the host in double precision. It moves the mean by the space’s own retraction, compiled for the host when the term is added, so that one sampler serves every space:

crates/skoro-normal/src/sample.rs lines 88–122
    fn draw(&self, inputs: &[Value], keys: &[Key], target: &Target) -> Value {
        let (rows, d, n) = (keys.len(), self.dimension, self.space.storage());
        let mean = rows_of(&inputs[0], rows);
        let scale = rows_of(&inputs[1], rows);
        let width = scale.len() / rows.max(1);
        let tangents: Vec<f64> = keys
            .iter()
            .enumerate()
            .flat_map(|(row, key)| {
                let zeta: Vec<f64> = key.uniforms(d).into_iter().map(quantile).collect();
                self.tangent(&scale[row * width..(row + 1) * width], &zeta)
            })
            .collect();
        let host = Target::host();
        let free = self.retraction.free();
        let at = Values::new()
            .with(
                free[0].node,
                Value::Continuous(Points::from_host(&mean, rows, n, &host)),
            )
            .with(
                free[1].node,
                Value::Continuous(Points::from_host(&tangents, rows, d, &host)),
            );
        let moved = self
            .retraction
            .forward(&at)
            .ok()
            .and_then(|out| out.get(self.retraction.targets()[0]).cloned());
        let Some(Value::Continuous(moved)) = moved else {
            unreachable!("the retraction compiled for the host runs on host values of its spaces")
        };
        Value::Continuous(Points::from_host(&moved.to_host(), rows, n, target))
    }
}

Since the chart is global, the draw has exactly the term’s density, and the sampler is exact: it leaves the importance weight to the likelihoods.

A large scale on a curved type#

On a curved type the scale is in the coordinates of the chart, which on the rotations are radians to first order, and a large one does not say that little is known. The density of a normal against the type’s reference measure is the Gaussian of the chart coordinate times e−λe^{-\lambda}, and on the Cayley chart of the rotations e−λ=(1+∣v∣2/4)2e^{-\lambda} = (1 + \lvert \tangent \rvert^2 / 4)^2 grows with the coordinate. The mean is a mode only while every eigenvalue of Σ\Sigma is below one; beyond that the density rises away from the mean, and as the scale grows the mass goes towards the chart’s cut, the half-turns from the mean, where a term is not finite. The median angle between a draw and the mean is 2arctan⁡(σ m/2)2 \arctan(\sigma\, m / 2), with m≈1.538m \approx 1.538 the median length of a standard normal vector of R3\R^3:

σ\sigma0.50.51133101010010010001000uniform
median angle, rad0.730.731.311.312.322.322.882.883.123.123.143.142.312.31

At σ=100\sigma = 100 a draw is within 0.10.1 rad of a half-turn with probability 0.980.98, where the uniform distribution puts 0.0640.064. The law is exact at every scale, in its term and in its draws, and a test draws the medians above up to σ=100\sigma = 100 from the normal’s own sampler. A quantity of which nothing is known is given the uniform distribution, which no normal is near, as the doc comment of Normal says.

The roles#

A term binds the nodes an estimator needs, under roles a reader in another crate, such as skoro-linearize, looks up by name:

crates/skoro-normal/src/roles.rs lines 11–31
/// The whitened residual: `W (x ⊖ μ)` of a normal's term, `W (z ⊖ μ)` of its factor, and
/// `A δ - b` of an improper factor, of any number of components.
pub const RESIDUAL: Role<ExactlyOne> = Role::new("skoro.residual");
/// The mean `μ`.
pub const MEAN: Role<ExactlyOne> = Role::new("skoro.normal.mean");
/// The scale given as `σ`, with `Σ = σ²I`.
pub const ISOTROPIC: Role<AtMostOne> = Role::new("skoro.normal.scale.isotropic");
/// The scale given as `σ`, with `Σ = diag(σ)²`.
pub const DIAGONAL: Role<AtMostOne> = Role::new("skoro.normal.scale.diagonal");
/// The scale given as `L`, with `Σ = LLᵀ`.
pub const COVARIANCE_FACTOR: Role<AtMostOne> = Role::new("skoro.normal.scale.covariance_factor");
/// The scale given as `W`, with `Λ = WᵀW`.
pub const WHITENING: Role<AtMostOne> = Role::new("skoro.normal.scale.whitening");
/// The varying part of a term's remainder: what is left of its log-density after the squares of
/// its residual and a normalizer constant in its free quantities, where that is not identically
/// zero. On a normal it is the chart's log-volume `λ_μ(x ⊖ μ)`, and on an improper factor its
/// linear part `ηᵀδ`. It is not the volume of a chart: a reader that needs a quantity's chart
/// volume reads it from the quantity's type.
pub const LOG_VOLUME: Role<AtMostOne> = Role::new("skoro.log_volume");
/// The root `C` of the expected information, on a term that scores a quantity.
pub const INFORMATION_ROOT: Role<AtMostOne> = Role::new("skoro.information_root");

and, on a term that scores a quantity, its tangent at the mean:

crates/skoro-normal/src/roles.rs lines 43–46
/// The tangent `s = x ⊖ μ` of a normal's term, which scores a quantity: its residual is `W s`,
/// with `W` the whitening of the bound scale, and its log-volume, where it binds one, is
/// `λ_μ(s)`, the chart's log-volume of the scored quantity's space at `μ`.
pub const TANGENT: Role<AtMostOne> = Role::new("skoro.normal.tangent");

The scale is bound under the role of its form, so a reader learns the form from which is bound. The tangent says how the residual and the log-volume are made of it, which is what lets the linearization fold a curved type’s log-volume into its rows, and what the Fisher rows of a free scale read their Jacobian from. The root CC of the expected information has C⊤CC\transpose C equal to the expected negative Hessian of the term over (x,μ,θ)(\point, \mu, \theta), exact on the core’s spaces. On a curved type it is exact in the scale’s block and holds to second order in the dispersion elsewhere. The log-volume’s role lets a least-squares reader add its gradient, and so reach the model’s own mode rather than that of the residuals alone.

What such a reader takes from the log-volume’s role is the varying part of the term’s remainder, what is left of its log-density after the squares of its residual and a normalizer: on a normal it is the chart’s log-volume, and on the improper factor below its linear part.

As a likelihood factor#

factor_at(z) adds the Gaussian part at a value zz as a likelihood factor, scoring nothing. It needs no reference measure and no global chart, which is how a measurement is held on a type without either. The stacked tangent builds the form of a retirement’s Gaussian replacement, a normal on RD\R^D at the tangents of the blanket’s quantities at constant anchors:

crates/skoro-normal/src/stacked.rs lines 25–40
/// Appends `x ⊖ p`, `p` the constant `anchor` of `marker`'s space. A discrete space is
/// refused (`NotContinuous`, by the core's inverse retraction). A quantity of a product type
/// is given factor by factor, `x.factor(i)` with each factor's marker.
#[track_caller]
pub fn block<T: Declares>(
    mut self,
    x: Q<T>,
    marker: T,
    anchor: impl IntoHostValue<T>,
) -> Stacked {
    let dimension = marker.space().dimension().unwrap_or(0);
    let anchor = constant(marker, anchor);
    self.blocks.push(x.untyped().local(anchor.untyped()));
    self.dimension += dimension;
    self
}

A retirement adds its replacement as a likelihood factor itself, and the replacement carries the roles that factor binds, as a term in a scope does:

crates/skoro-core/src/retire.rs lines 86–103
/// What the caller builds: the replacement `ℓ_B`, a likelihood factor over the blanket,
/// proposals for the quantities the retirement leaves to be drawn by one, and the nodes the
/// factor binds to roles, as `TermHandle::bind` binds them on a term.
pub struct Replacement {
    pub log_density: Q<Real>,
    pub proposals: Vec<(QDyn, Proposal)>,
    /// Each a role's name and the node bound to it.
    pub bindings: Vec<(&'static str, QDyn)>,
}

impl Replacement {
    /// Binds `node` to `role` on the factor the retirement adds: a node reached from no quantity
    /// outside the factor's, which `Retirement::replace` checks (`BindingOutsideTerm`).
    pub fn bind<M: Multiplicity>(mut self, role: &Role<M>, node: impl Into<QDyn>) -> Replacement {
        self.bindings.push((role.name(), node.into()));
        self
    }
}

Stacked::replacement gives a retirement that replacement whole, its residual, mean and scale bound under the normal’s roles exactly as Stacked::factor binds them on a factor, through one helper; the retirement checks each node and binds it to the factor it adds, in the snapshot it publishes, so that a reader finds the residual of a retired window as it finds any other:

crates/skoro-normal/src/stacked.rs lines 60–72
/// `ℓ_N(δ; m, W) + c` as a retirement's `Replacement`, with no proposals and its residual,
/// mean and scale bound as [`factor`](Stacked::factor) binds them, which the retirement checks
/// and binds to the factor it adds. A caller adds proposals, or further bindings, to it.
#[track_caller]
pub fn replacement(&self, mean: &[f64], scale: Scale, constant: f64) -> Replacement {
    let (log_density, residual, mean) = self.gaussian(mean, scale, constant);
    let replacement = Replacement {
        log_density,
        proposals: Vec::new(),
        bindings: Vec::new(),
    };
    with_roles(replacement, residual, mean, scale)
}
crates/skoro-normal/src/stacked.rs lines 111–119
/// `target` with the residual, the mean and the scale bound under the normal's roles, the same for
/// a factor and a replacement.
#[track_caller]
fn with_roles<B: Binds>(target: B, residual: QDyn, mean: QDyn, scale: Scale) -> B {
    target
        .bind_role(&roles::RESIDUAL, residual)
        .bind_role(&roles::MEAN, mean)
        .bind_role(roles::scale(scale.form()), scale.value())
}

An improper factor#

A Stacked replacement is a normal, so it determines every direction of the blanket. A retirement whose terms do not, such as a landmark seen by bearing from a single pose, which says in which direction the landmark lies and nothing of how far, has as its replacement an improper Gaussian factor in the same stacked tangent δ\delta: a sum of squared affine rows of any number, a linear part and a constant,

ℓ(xB)=−12∣Aδ−b∣2−η⊤δ+c, \logterm(\point_B) = -\tfrac12 \lvert A \delta - b \rvert^2 - \eta\transpose \delta + c ,

which no normalization need make a density of δ\delta, and a likelihood factor never needed one. Where its rows have full rank it is a normal, and its value is a Stacked replacement’s; where they do not, it keeps exactly what the retired terms said and nothing more. Stacked::improper builds it from its rows, right-hand side and constant, each a constant of the model and each shared or given row by row of a batch, and linear gives it a linear part:

crates/skoro-normal/src/improper.rs lines 25–71
impl Stacked {
    /// The improper Gaussian factor over `δ` with `rows` rows: `a` the `rows × D` matrix `A`,
    /// **column by column** as a `MatrixDyn` is stored, `b` the right-hand side, a `Vector(rows)`,
    /// and `c` the constant, and no linear part. Each may be shared or given per row of a batch
    /// with `Rows`. Any number of rows is a factor, none included; the rows are kept as given, and
    /// none is added or removed.
    ///
    /// **The order of the blocks is load-bearing.** The columns of `A`, and the entries of `η`,
    /// follow the order of the `block` calls, factor by factor, each over its quantity's tangent
    /// coordinates. Nothing checks that correspondence, because nothing can: a matrix of the right
    /// width is the rows of a factor in any order.
    ///
    /// Numbers that do not fit their spaces are refused with `ValueShape` at the caller's line,
    /// and a stacked tangent of no blocks by the core's concatenation (`SpaceMismatch`).
    #[track_caller]
    pub fn improper(
        &self,
        rows: usize,
        a: impl IntoHostValue<MatrixDyn>,
        b: impl IntoHostValue<VectorDyn>,
        c: impl IntoHostValue<Real>,
    ) -> Improper {
        let tangent = self.tangent();
        let a = constant(MatrixDyn(rows, self.dimension()), a);
        let b = constant(VectorDyn(rows), b);
        Improper {
            tangent,
            dimension: self.dimension(),
            residual: a.matmul(tangent) - b,
            linear: None,
            constant: constant(Real, c),
        }
    }
}

impl Improper {
    /// The same factor with the linear part `ηᵀδ`, `eta` a `Vector(D)`, shared or per row.
    /// Whether a factor has one is a matter of its shape, the same for every row of a batch: an
    /// `eta` of zeros is still bound.
    #[track_caller]
    pub fn linear(self, eta: impl IntoHostValue<VectorDyn>) -> Improper {
        let eta = constant(VectorDyn(self.dimension), eta);
        Improper {
            linear: Some((eta * self.tangent).sum()),
            ..self
        }
    }

Like Stacked, it gives a log-density alone, a retirement’s Replacement, or a likelihood factor, the last two binding its roles through one helper: the residual Aδ−bA \delta - b, of any number of components, none included, and, where a linear part is given, η⊤δ\eta\transpose \delta under the log-volume role. It binds no mean and no scale, which a factor of lower rank does not have.

crates/skoro-normal/src/improper.rs lines 118–127
/// `target` with the residual bound, and the linear part under the log-volume role when there
/// is one: the same for a factor and a replacement.
#[track_caller]
fn with_roles<B: Binds>(&self, target: B) -> B {
    let target = target.bind_role(&roles::RESIDUAL, self.residual.untyped());
    match self.linear {
        Some(linear) => target.bind_role(&roles::LOG_VOLUME, linear.untyped()),
        None => target,
    }
}

A blanket quantity the factor leaves undetermined is scored by no term after the retirement, and is a parameter: generation draws it from a proposal given with the replacement, and refuses it otherwise. Factors over the same quantity accumulate as terms of their own, and the model reads them as their sum: once the bearings of two poses have been retired, along different directions, the landmark is determined, at the point where the two lines cross. The linearization computes such a replacement from the retired terms themselves. The mathematics, its forms and its examples are in the note on the improper Gaussian factor.

How this came to be

The development behind this page, newest first:

Built on by