pyphi.relations.AnalyticalRelations#

class pyphi.relations.AnalyticalRelations(distinctions)[source]#

Bases: Relations

A closed-form summary of the relations among a set of distinctions.

Every query (sum_phi, num_relations, degree spectra, …) is a pure function of distinctions, so two instances are equal exactly when their distinctions are equal — regardless of whether either was freshly computed, deserialized, or produced by a separate call. A ConcreteRelations built from the same distinctions is never equal to one: the two are distinct representations, and comparing them would require materializing one into the other’s form.

sample(n, *, seed)[source]#

Draw n non-self relations, coverage-weighted, i.i.d.

Sampling walks the atom incidence: an atom is drawn with probability proportional to the number of relations inside its distinction group (2**m − m − 1 for a group of m), then a subset of size ≥ 2 of that group is drawn uniformly. The resulting relation is drawn with probability proportional to its overlap size |O(S)|, which is known per sample, so the returned RelationSample yields unbiased estimates with standard errors for any per-relation sum. No burn-in; exact normalization.

Parameters:
  • n (int) – The number of draws (with replacement).

  • seed (int) – Seed for the isolated random generator. Required.

Return type:

RelationSample

sum_phi_moment(k=2)[source]#

Return Σφ_r^k over all relations, in closed form.

Since φ_r = |O(S)| · min q and |O(S)|^k counts the ordered k-tuples of atoms covering S, the k-th moment decomposes over atom k-tuples, each contributing a sum-of-minimum of q^k over the distinctions shared by the tuple. Cost is O(N^k) inner sums for N atoms.

Parameters:

k (int)

Return type:

float

num_relations_of_degree(degree)[source]#

Return the number of relations with exactly degree relata, by inclusion-exclusion over shared purview subsets.

Parameters:

degree (int)

Return type:

int

sum_phi_of_degree(degree)[source]#

Return Σφ_r over relations with exactly degree relata, as a per-atom sorted dot product with binomial coefficients.

Parameters:

degree (int)

Return type:

float

degree_spectrum()[source]#

Return {degree: (count, Σφ_r)}, in closed form per degree.

Return type:

dict[int, tuple[int, float]]

sum_phi_by_distinction(distinctions=None)[source]#

Return each distinction’s incident Σφ_r in closed form.

A relation either contains a given distinction or does not, so its incident Σφ_r is total − Σφ_r(relations avoiding it): the full total differenced against the total over the remaining distinctions. No relations are enumerated. The result is parallel to distinctions, which defaults to the structure’s own.

Return type:

tuple[float, …]

max_phi()[source]#

Return the maximum φ_r, scanning only pairs and self-relations.

Notes

The maximum over relations of degree ≥ 2 is always attained at degree 2: for any relation S with minimum-density member d* and any other member d', the pair {d*, d'} has overlap containing O(S) and the same minimum density, so its φ_r is at least φ_r(S). The scan is O(D^2).

Return type:

float

strongest(k=None, min_phi=None, max_degree=None)[source]#

Yield relations in descending φ_r order, lazily.

Best-first search over the subset lattice: φ_r never increases when a relatum is added (the overlap shrinks and the minimum density can only fall), so seeding a max-heap with all valid pairs and the self-relations, and expanding each popped combination by larger-index distinctions only, yields relations in exact descending order. The first K yields cost O(|D|²) seeding plus O(K·|D|) heap pushes, independent of the total relation count.

Ties in φ_r yield in an unspecified but deterministic order. The heap can grow to O(yielded · |D|) entries when the stream is consumed deeply; full enumeration is better served by materialize().

Parameters:
  • k (int, optional) – Yield at most this many relations. If None, yield all.

  • min_phi (float, optional) – Stop once φ_r falls below this threshold (compared tolerantly at the configured precision). Sound as an early exit because the stream is globally descending.

  • max_degree (int, optional) – Do not yield or expand relations with more than this many relata.

Return type:

Iterator[Relation]

materialize(max_degree=None, min_phi=None)[source]#

Enumerate the relations as an explicit ConcreteRelations.

The output is exponential in the number of distinctions, so max_degree and min_phi (tolerant ≥) bound it. Self-relations are always included (they have degree 1 and there are at most |D| of them).

Parameters:
  • max_degree (int | None)

  • min_phi (float | None)

Return type:

ConcreteRelations

binding_matrix()[source]#

Return the atom-pair binding matrix, in closed form.

Each entry is one sum-of-minimum over the distinctions shared by the atom pair — O(A²) sorted dot products for A atoms, never touching a relation.

Return type:

DataFrame

phi_histogram()[source]#

Return {φ_r: count} over all relations, in closed form.

φ_r takes at most A × D distinct values, for A purview atoms and D distinctions (overlap size times minimum density). The histogram is computed by sweeping density thresholds from high to low: at each threshold, relations among the distinctions at or above it are counted by exact overlap size via Möbius inversion over the intersection closure of their purview-unions; differencing consecutive sweeps assigns counts to overlap × density buckets. Distinctions are grouped by density at the configured precision (pyphi.numerics.round_to_precision()), so mathematically equal densities that differ by float noise share a threshold, and each bucket key is rounded to that same precision.

Notes

The intersection closure is bounded by 2 ** A for A purview atoms but is small for structured systems; if it grows pathologically, materialization or sampling are the fallbacks.

Return type:

dict[float, int]

num_faces()[source]#

Return the total number of faces across all relations, in closed form.

A face is a set of two or more causes/effects (one per direction choice per relatum) with nonempty state-tagged overlap, so the total face count is the same subfamily count that num_relations() computes over distinctions, run instead over the individual causes and effects — Möbius inversion over the intersection closure of the per-side purviews. Faces of self-relations (a distinction’s cause paired with its own effect) are included, matching enumeration.

Return type:

int