pyphi.relations.AnalyticalRelations#
- class pyphi.relations.AnalyticalRelations(distinctions)[source]#
Bases:
RelationsA closed-form summary of the relations among a set of distinctions.
Every query (
sum_phi,num_relations, degree spectra, …) is a pure function ofdistinctions, so two instances are equal exactly when theirdistinctionsare equal — regardless of whether either was freshly computed, deserialized, or produced by a separate call. AConcreteRelationsbuilt 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
nnon-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 − 1for a group ofm), 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 returnedRelationSampleyields unbiased estimates with standard errors for any per-relation sum. No burn-in; exact normalization.- Parameters:
- Return type:
- sum_phi_moment(k=2)[source]#
Return Σφ_r^k over all relations, in closed form.
Since
φ_r = |O(S)| · min qand|O(S)|^kcounts the ordered k-tuples of atoms coveringS, the k-th moment decomposes over atom k-tuples, each contributing a sum-of-minimum ofq^kover the distinctions shared by the tuple. Cost isO(N^k)inner sums forNatoms.
- num_relations_of_degree(degree)[source]#
Return the number of relations with exactly
degreerelata, by inclusion-exclusion over shared purview subsets.
- sum_phi_of_degree(degree)[source]#
Return Σφ_r over relations with exactly
degreerelata, as a per-atom sorted dot product with binomial coefficients.
- 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 todistinctions, which defaults to the structure’s own.
- 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
Swith minimum-density memberd*and any other memberd', the pair{d*, d'}has overlap containingO(S)and the same minimum density, so its φ_r is at leastφ_r(S). The scan isO(D^2).- Return type:
- 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
Kyields costO(|D|²)seeding plusO(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 bymaterialize().- 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:
- 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_degreeandmin_phi(tolerant≥) bound it. Self-relations are always included (they have degree 1 and there are at most|D|of them).- Parameters:
- Return type:
- 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 forAatoms, never touching a relation.- Return type:
DataFrame
- phi_histogram()[source]#
Return
{φ_r: count}over all relations, in closed form.φ_r takes at most
A × Ddistinct values, forApurview atoms andDdistinctions (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 tooverlap × densitybuckets. 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 ** AforApurview atoms but is small for structured systems; if it grows pathologically, materialization or sampling are the fallbacks.
- 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: