mixle.represent.graph module

Structured / graph encoding – message passing over a structure’s elements, so edges actually matter.

A molecule, a knowledge graph, a fossil section’s co-occurrence network, a protein contact map: these are structures, not bags. SetSegmenter gives their elements’ features but throws the edges away. GraphEmbedding keeps them – a small message-passing net (GCN-style) embeds each element and then mixes it with its neighbours over layers rounds, so an atom’s vector reflects its bonds and a node’s reflects its graph context. The output is one (n_elements, dim) block in the same shared space as every other modality, so a molecule composes with text/images/signals in one HeterogeneousEncoder.

A graph-modality record value is (node_features (n, f), adjacency (n, n)); GraphEncoder is a ModalityEncoder you drop into the registry via register_encoder. Trains end to end like any encoder.

class GraphEmbedding(in_features, dim, *, layers=2, name=None)[source]

Bases: object

A message-passing embedding: (node_features, adjacency) -> (n_nodes, dim) with layers GCN rounds.

Parameters:
  • in_features (int)

  • dim (int)

  • layers (int)

  • name (str | None)

module()[source]

Build or return the Torch graph-embedding module.

Return type:

Any

class GraphEncoder(embedding)[source]

Bases: ModalityEncoder

A structure modality: raw = (node_features (n, f), adjacency (n, n)) -> per-node vectors in shared R^dim.

Parameters:

embedding (GraphEmbedding)

encode(raw)[source]

Encode graph nodes and adjacency into Torch embeddings.

Parameters:

raw (Any)

Return type:

Any

encode_numpy(raw)[source]

Encode a graph and return NumPy embeddings.

Parameters:

raw (Any)

Return type:

ndarray