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.refine(b).block_count() # 4 — every element separated
a.coarsen(b).block_count() # 1 — everything merged
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.
The operations are refine and coarsen, not meet and join. Much of the
literature — including Ellerman's papers — calls the common refinement join; other
sources call it meet. Both are standard, and they are opposite conventions on the
same structure, so a name like meet cannot be read without first knowing which
convention is in force. refine and coarsen say what the operation does, so they
read the same either way.
meet, join, &, | and the order comparisons <= < >= > were removed in
0.2.0. They would have kept working while meaning the opposite thing to a reader
coming from the other convention — a silent wrong answer. They now raise, and
refines() covers the order:
a.refines(b) # is a finer than b? (same reading under either convention)
a == b # equality was never convention-dependent, and is unchanged
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 | refine(o), coarsen(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 Distributions
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.2.0.tar.gz.
File metadata
- Download URL: partition_lattice-0.2.0.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13c9b6f20a7bfde10863a632b736a9a8ea5e219cf02eaf1549eab07391edbae3
|
|
| MD5 |
b1d10d1edc8b14b354f2f2cecc2af512
|
|
| BLAKE2b-256 |
07236d3d7b6cd8c2763050e366670ead006653116fb60286bd3ce3c0008e0342
|
File details
Details for the file partition_lattice-0.2.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: partition_lattice-0.2.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 286.2 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
505098fcc1f4996d78bf891640a685499626b57a483a562d80bd81ae1430fa4b
|
|
| MD5 |
8c0795c1efc6e110e197195f2bb06000
|
|
| BLAKE2b-256 |
d06f75c34f319ba22df87a901c147d575220dfb48a61aa9d7d41d5a55e4f09ef
|
File details
Details for the file partition_lattice-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: partition_lattice-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 421.2 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67ed05149aebb8b8938d11df292e779d5ff663ca35530a721a4e09cbe925ba74
|
|
| MD5 |
904da9f20adc517426e8b241104bfbf8
|
|
| BLAKE2b-256 |
e753e802240a31c53f531d53d322326f0f5c1d88bdb2065dcf51800d56fb7cf4
|
File details
Details for the file partition_lattice-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: partition_lattice-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 394.6 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d5dfe72959babe5f825083ea8cbbb18305dff54df7f40c14b97816264549d99
|
|
| MD5 |
4c9f3d0ca4eec76d90dd1371dc680e2c
|
|
| BLAKE2b-256 |
842be7cf79d4c9e58cbad619f1613ff588cb96058db591b7d84dd49e9e225576
|
File details
Details for the file partition_lattice-0.2.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: partition_lattice-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 341.5 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 |
eb9ad6ab4187a5b10c3aaa7feac7f317208c0873c5ecf16509e86b1af963d37b
|
|
| MD5 |
13f5fa4b6a58d7e27f40bfbe154ab001
|
|
| BLAKE2b-256 |
415fcdd8ce1bf0bf4292ce59a50f18c12d992f5d45ac2dd365984032650ba878
|
File details
Details for the file partition_lattice-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: partition_lattice-0.2.0-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 357.7 kB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bc79561034ab71957147972b63364759ef462714adb717b4b15863af89ae86d
|
|
| MD5 |
6eed67ccd42f73d169b04dbb3f715796
|
|
| BLAKE2b-256 |
4b92e5936cfeb0468cb79e74c54a95448b6a696d039b8c5899d458f2b8aad39a
|