partition-lattice
Partition lattice algebra in exact integer arithmetic: meet, join, and logical
entropy. Python bindings for the Rust crate
partition-lattice.
A partition of a finite universe splits it into disjoint blocks. Partitions form a lattice under refinement, and this package exposes that lattice directly — the two operations, the order, and the measures — without going through probabilities or floats where integers will do.
from partition_lattice import Partition
a = Partition([0, 0, 1, 1]) # {0,1}{2,3}
b = Partition([0, 1, 0, 1]) # {0,2}{1,3}
a.meet(b).block_count() # 4 — every element separated
a.join(b).block_count() # 1 — everything merged
a & b == a.meet(b) # True; `|` is join
a.logical_entropy() # 0.5
a.dit_count() # 8 — the exact integer numerator
Block labels carry no information, so equal groupings are equal partitions:
Partition([0, 0, 1, 1]) == Partition([7, 7, 3, 3]) # True
Two conventions worth knowing before you start
Order. a.refines(b) means finer, so Partition.discrete(n) is the least
element and Partition.indiscrete(n) the greatest. <= is that refinement order.
Meet and join. meet is the common refinement, join the common
coarsening. Much of the literature — including Ellerman's papers — uses the
order-dual convention, where join is the refinement. Neither is wrong; they are
opposite conventions on the same structure. When porting a formula, flip meet/join
and the direction of <= together.
The order is partial: a <= b being false does not make a > b true.
Exactness
Distinction counts are integers and stay integers. logical_entropy() is the only
place a division happens, and its numerator is available separately as
dit_count(), so entropies can be compared exactly rather than through floats.
weighted_entropy(weights) and cross_entropy(p, q) return exact
(numerator, denominator) pairs. A weight is a multiplicity, not a probability:
the result equals the ordinary logical entropy of the multiset repeating element u
exactly w[u] times. Note that a non-uniform weight breaks relabelling invariance.
API
| Construction | Partition(ids), Partition.discrete(n), Partition.indiscrete(n), Partition.from_blocks(n, blocks) |
| Structure | block_count(), blocks(), ids(), block_of(e), len(p) |
| Operations | meet(o) / &, join(o) / |, refines(o) / <= |
| Measures | logical_entropy(), dit_count(), distance(o), mutual_information(o), divergence(o), rand_agreement(o), jaccard(o) |
| Exact measures | weighted_entropy(w), cross_entropy(p, q) |
| Module | dit_xor_count(a, b), destr(a, b), creat(a, b) |
Unlike the Rust from_blocks, Partition.from_blocks rejects a partial or
overlapping cover instead of silently reassigning elements.
Install
pip install partition-lattice
Wheels are built against the stable ABI (abi3), so one wheel per platform covers
CPython 3.8 and newer.
License
MIT OR Apache-2.0, at your option.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file partition_lattice-0.1.0.tar.gz.
File metadata
- Download URL: partition_lattice-0.1.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6274ae6a6dff0c0132ff0a274aab65d7dd6b81aeeb4a1b924484c95151a2f561
|
|
| MD5 |
44b2f100740bfe0da5f664e71cbc5aab
|
|
| BLAKE2b-256 |
206b6fc9216ed8fb7597bb9aa36dbb69fa87b9a52c4c2839489851630f7aa3cb
|
File details
Details for the file partition_lattice-0.1.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: partition_lattice-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 342.4 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10d25cb26a8169a9bdea5b361e63cea572861aa9f236f5f47b0591efa984bcb9
|
|
| MD5 |
bfead8f712ee993bf495e235ae1aca25
|
|
| BLAKE2b-256 |
2fca7d0c8b89224515740c94e5a06499f6fe139296f3a2c1da6dac61763f9159
|