mixle.utils.hvis.goals module¶
Embedding goals: declarative objectives layered onto an HViS embedding.
The data term (t-SNE row-KL / UMAP cross-entropy) says “preserve the model’s neighborhood structure”; a goal says what else the layout is FOR. Goals steer the same optimization – they are not a post-hoc warp of a finished layout, which would break exactly the neighborhood structure the embedding exists to show.
Rate semantics (the stability contract). A goal’s gradient(Y) returns a bounded
per-iteration DISPLACEMENT, applied as Y -= gradient once per optimizer iteration – decoupled
from the data optimizer’s learning rate and adaptive gains on purpose. t-SNE’s data gradient lives
on probability scale and is driven with eta ~ n/12 and delta-bar-delta gains; a raw quadratic
penalty routed through that machinery is amplified by orders of magnitude and diverges. Under rate
semantics every goal’s weight is a fraction-per-step in (0, 1], contraction-stable by
construction regardless of the optimizer it rides along with.
Three goals, and two headline features are special cases:
Anchor– ANCHORING: pin chosen points to given coordinates. Hard (weight=None) is an exact projection every step; soft (weightin(0, 1]) closes that fraction of the remaining gap per step – unconditionally stable exponential relaxation. Anchors fix the translational gauge, so the optimizers skip their usual mean-centering (they would fight).LabelCohesion– PARTIAL LABELING: labels for any subset of points (None= unlabeled). Labeled points move toward their label centroid atweightper step; an optionalmarginhinge pushes centroid pairs apart. Unlabeled points are shaped only by the data term – semi-supervision, not relabeling.AxisAlign– a layout GOAL: a per-point scalar (time, depth, severity, …) should run along a chosen embedding axis, ascending the Pearson correlation along its scale-normalized direction (translation/scale invariant, so it orders the axis without dictating layout scale).
- class Anchor(indices, coordinates, weight=None)[source]
Bases:
objectPin
indicestocoordinates: hard whenweightis None (exact projection each step), soft forweightin(0, 1](close that fraction of the remaining gap per step).
- class AxisAlign(values, axis=0, weight=0.5)[source]
Bases:
objectA per-point scalar should run along embedding axis
axis: each step ascends the Pearson correlationr(y[:, axis], values)along its scale-normalized direction (bounded norm <= 2, soweight– recommended at most ~1 – is a stable per-step rate in embedding units). Pass-valuesto reverse direction.
- class LabelCohesion(labels, weight=0.1, margin=None)[source]
Bases:
objectPartial labels shape the layout: each labeled point moves toward its label’s centroid at
weight(a per-step fraction in(0, 1]); withmargin, centroid pairs closer thanmarginare pushed apart (every member displaced alike, which moves the centroid by exactly the intended amount).labelshas one entry per point;Nonemarks a point unlabeled.
- apply_projections(goals, y, velocity=None)[source]
Apply anchor projections/relaxations after a step; zero the velocity of hard-pinned rows so momentum cannot accumulate against the pin.
- goals_fix_gauge(goals)[source]
True when any goal pins absolute coordinates – the optimizers must then skip mean-centering (centering re-translates the cloud every step, which would fight the pins).