Skip to main content

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

partition_lattice-0.1.1.tar.gz (19.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

partition_lattice-0.1.1-cp38-abi3-win_amd64.whl (287.6 kB view details)

Uploaded CPython 3.8+Windows x86-64

partition_lattice-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (421.9 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

partition_lattice-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (395.4 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

partition_lattice-0.1.1-cp38-abi3-macosx_11_0_arm64.whl (342.3 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

partition_lattice-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl (358.6 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file partition_lattice-0.1.1.tar.gz.

File metadata

  • Download URL: partition_lattice-0.1.1.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for partition_lattice-0.1.1.tar.gz
Algorithm Hash digest
SHA256 eab85a7dab3cee084479d35e3ee2d86715780cfda1dbacab690c3c468aa21bc8
MD5 84d0b7931bed719cd5f8cc83f92d38db
BLAKE2b-256 a3e27650cc8473ed23fb6ac94eeffd115b29c76a1ab3069f0c1159802a5ec297

See more details on using hashes here.

File details

Details for the file partition_lattice-0.1.1-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for partition_lattice-0.1.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 810c1840612c08ad0fce74b09396b8384d231c23756bc42eadf5f5e8fe83d173
MD5 bb25192f53a6faf615bf515462f986f2
BLAKE2b-256 964b9ffb8ec007968df9f5674dbc73177555ac26b9367dc3a6472f029bc7aef8

See more details on using hashes here.

File details

Details for the file partition_lattice-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for partition_lattice-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 df659d4cedff2c901a5ce62eecafc4ce0174cd6927d22f757ecb399a59249fae
MD5 8ffb747b9d0aab40026d0f6d5d813d3f
BLAKE2b-256 4ad955b689b8fe855749ed81df02f443304e9001374bd76b52d6aceb734e3eaa

See more details on using hashes here.

File details

Details for the file partition_lattice-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for partition_lattice-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1014f4f8e4dbe7636e27cd4810b8517bd3a6d01e56467017cfeb518b241ca1c4
MD5 7f42a3bcc1ff713a8425b08f935ff6bb
BLAKE2b-256 109e37b57dcc1e8ace7869b84ac7e52443c350c5206cdb908b9417f6cdc13e3e

See more details on using hashes here.

File details

Details for the file partition_lattice-0.1.1-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for partition_lattice-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fd1b2f10b9173b92263634fa5a6e778ecdfc8c89fd2bbe2c2b8d62808f5523dc
MD5 cbce80e28a20c4a3f6be96e6791a7083
BLAKE2b-256 665d948c6db4cb1b9551ebc826d2f312e8ec028009e6d02a073325a8f3e33100

See more details on using hashes here.

File details

Details for the file partition_lattice-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for partition_lattice-0.1.1-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 41c1f8572d076057eabf1fbc18475fcb098d3e891ac9a56acf01074ac8b41d90
MD5 070dfdb82f4418d7850a87df9e35e125
BLAKE2b-256 c5fac8667cdad63642505d0ed204520eebc61f93a3cfbda086d36a6301838baf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page