pykappa.mixture

Functions

neighborhood(agents, radius)

Get all agents within a distance radius of the given agents.

Classes

Mixture([patterns, track_components])

A collection of agents and their connections.

class pykappa.mixture.Mixture(patterns=None, track_components=False)[source]

A collection of agents and their connections.

Optionally tracks connected components, enabled via enable_component_tracking().

Parameters:
  • patterns (Iterable[Pattern] | None)

  • track_components (bool)

classmethod from_kappa(patterns)[source]

Create a mixture from Kappa pattern strings and counts.

Parameters:

patterns (dict[str, int]) – Dictionary mapping pattern strings to copy counts.

Return type:

Self

agents: IndexedSet[Agent]
property kappa_str: str

The mixture in Kappa format with %init declarations.

property component_tracking: bool

Whether connected components are being tracked.

property components: IndexedSet[Component]
enable_component_tracking()[source]

Turn on connected-component tracking for this mixture.

Return type:

None

add(pattern, n_copies=1)[source]

Add instances of a pattern or component to the mixture.

Raises:

AssertionError – If pattern is underspecified.

Parameters:
Return type:

None

remove(component)[source]

Remove a component from the mixture.

Parameters:

component (Component)

Return type:

None

embeddings(component)[source]

Get embeddings of a tracked component (not accounting for symmetries).

Raises:

KeyError – If component is not being tracked.

Parameters:

component (Component)

Return type:

IndexedSet[Embedding]

embeddings_in_component(match_pattern, mixture_component)[source]

Get embeddings of a pattern within a specific component.

Parameters:
Return type:

IndexedSet[Embedding]

pykappa.mixture.neighborhood(agents, radius)[source]

Get all agents within a distance radius of the given agents.

Parameters:
  • agents (Iterable[Agent])

  • radius (int)

Return type:

set[Agent]