mixle.represent.modality module

Deterministic modality vectorization helpers.

vectorize() maps a raw item to a fixed-length vector that can be used by structure-learning and heterogeneous Bayesian-network workflows:

  • text / record -> the learned embedding (mixle.represent.fit_embedder());

  • image (a 2-D or 3-D numeric array) -> grid-pooled intensities (a coarse, deterministic, torch-free descriptor that captures brightness / spatial layout);

  • signal (a 1-D numeric array) -> per-window statistics (mean, energy, range) across the trace.

The image and signal descriptors are deterministic and dependency-free. They are intended as a baseline vectorization layer; learned encoders can be placed behind the same vectorize surface when a workflow needs richer features.

image_features(img, dim=16, *, grid=None)[source]

A fixed dim descriptor of an image: mean intensity over a g x g grid of cells.

img is (H, W) or (H, W, C); channels are averaged. The grid side g is chosen so g*g covers dim (then truncated/padded to exactly dim), giving a coarse spatial-layout vector – enough for an image field to correlate with structured fields in a discovered graph.

Parameters:
Return type:

ndarray

signal_features(sig, dim=16, *, windows=None)[source]

A fixed dim descriptor of a 1-D signal: (mean, energy, range) over evenly-spaced windows.

Parameters:
Return type:

ndarray

vectorize(item, kind, *, dim=16, embedder=None)[source]

Map a raw item of modality kind to a fixed dim vector (see module docstring).

Parameters:
  • item (Any) – the raw item (a string, a record, an image array, a signal array).

  • kind (str) – 'text' | 'record' | 'image' | 'signal'.

  • dim (int) – output vector dimension.

  • embedder (Any) – for text/record, a fitted Embedder to reuse (else a small one is fit on the single item – pass one for consistency across a corpus).

Return type:

ndarray

vectorize_all(items, kind, *, dim=16)[source]

Vectorize a sequence of same-modality items to an (n, dim) array (one shared embedder for text).

Parameters:
Return type:

ndarray