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.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.

Examples

Four demos, runnable as-is — python examples/<name>.py. Each has a Rust twin in the crate.

what it shows
functional_dependencies X -> Y is the refinement order, so finding dependencies needs no dependency-checking algorithm. Composite determinants are one refine.
clustering_comparison A scalar index says how much two clusterings differ; coarsen / refine / destr / creat say in what way, and keep the direction a single number discards.
dfa_minimisation Moore's algorithm is refine in a loop, and its fixed point is an exact integer comparison — no epsilon.
graph_components Folding edges with coarsen gives connected components. The join is the union-find.

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.3.0.tar.gz (27.1 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.3.0-cp38-abi3-win_amd64.whl (286.7 kB view details)

Uploaded CPython 3.8+Windows x86-64

partition_lattice-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (421.7 kB view details)

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

partition_lattice-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (395.1 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

partition_lattice-0.3.0-cp38-abi3-macosx_11_0_arm64.whl (341.9 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

partition_lattice-0.3.0-cp38-abi3-macosx_10_12_x86_64.whl (358.2 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: partition_lattice-0.3.0.tar.gz
  • Upload date:
  • Size: 27.1 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.3.0.tar.gz
Algorithm Hash digest
SHA256 a1b0d7dac791e0ed31754fbcdfe868e0edb792b169b38542819fbb5626b957d7
MD5 1fd3e487c08113a15b6de94fd5ac5eed
BLAKE2b-256 7b534df5e74a876512ae8dcaf1a0149b8eb5365961d3b23c8effaa6e0e633267

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for partition_lattice-0.3.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 81b6d5cac203a4017b0a21d7931ef2ddc84ff3972fb46f1184f46297517ba985
MD5 cb89d381196e2f4bfc9236b2243511de
BLAKE2b-256 4f47a34bc6446e3bc39afbbb521eaf503b1b032d960272e8be06e54a5d3b668f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for partition_lattice-0.3.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9095d44f8650f2fbe0ff968699011eddd43f6fed3281235b1d51696166411a05
MD5 1b92de632e5dfd74a63b575e228c54e0
BLAKE2b-256 5ee8721fdacad849b3f22939d233e400aa5e24c6c88cf68179df5f3630db1bc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for partition_lattice-0.3.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 479baa761986d160131bcea2b2d10c8f1062f58817180eac0c124cd31f9893d7
MD5 b5b06f4990bca0949364c0c638405882
BLAKE2b-256 7265492fd8fd16b916393a481961107b471655261b14704435e4d49e8d02c12d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for partition_lattice-0.3.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 99d0c4d843bfa3d7f45171c322be10964cabf0fb709986dc06fb716bf5b51431
MD5 7d49120c31545a5083b9e130e8fc210e
BLAKE2b-256 ff9b9d1d1c5e7eda3d31c40b3d3d2a507f7f0eb4bd0a59a07336c877139802a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for partition_lattice-0.3.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f125bf83d3171fa8d3a509059a43eccea59ea2f387c1f4bb8c5cf07e7f86f532
MD5 e5bee9f0cee6fca54857e7969d5523aa
BLAKE2b-256 35399dad8f035d9f7c8efc44c882cc86e05e0a0e802300f391378dd3f387bed0

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