Skip to main content

Hamming-distance metric for Swarmauri with raw mismatch counts, batched comparisons, and metric-axiom helpers.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_metric_hamming Discord

Swarmauri Metric Hamming

swarmauri_metric_hamming is the Swarmauri metric implementation for Hamming distance. It compares equal-length sequences and returns the count of positions that differ, while also exposing batched distance helpers and metric-axiom checks for downstream validation workflows.

Why Use Swarmauri Metric Hamming

  • Measure discrete sequence differences inside Swarmauri retrieval, coding, validation, or comparison workflows.
  • Compare binary vectors, strings, NumPy arrays, and Swarmauri vector or matrix surfaces through one metric component.
  • Reuse a metric implementation that also exposes symmetry, identity, and triangle-inequality checks.
  • Build exact distance-based workflows for error-correcting codes, bitstring analysis, and symbolic comparison.

FAQ

What does distance() return?
A float equal to the number of differing positions between two equal-length inputs.

What input types are supported?
Strings, bytes, dictionaries, NumPy arrays, generic sequences, and Swarmauri matrix/vector interfaces.

Does it normalize the distance?
No. The current implementation returns the raw count of mismatched positions.

Can it compare batches of vectors?
Yes. Use distances() to generate pairwise distance rows across collections.

Features

  • Raw Hamming distance for equal-length sequences.
  • Pairwise distances() support for collections of vectors.
  • Input normalization for strings, bytes, dicts, arrays, matrices, and vectors.
  • Metric-axiom helpers: non-negativity, symmetry, identity of indiscernibles, and triangle inequality.
  • Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.

Installation

uv add swarmauri_metric_hamming
pip install swarmauri_metric_hamming

Usage

from swarmauri_metric_hamming import HammingMetric

metric = HammingMetric()
codeword = [1, 0, 1, 1, 0, 0, 1]
received = [1, 1, 1, 1, 0, 0, 1]

print(metric.distance(codeword, received))

Examples

Compare binary vectors

from swarmauri_metric_hamming import HammingMetric

metric = HammingMetric()
print(metric.distance([1, 0, 1, 1], [1, 1, 0, 1]))

Compare strings and arrays

import numpy as np
from swarmauri_metric_hamming import HammingMetric

metric = HammingMetric()
left = "1011001"
right = np.array([1, 0, 1, 0, 0, 0, 1])

print(metric.distance(left, right))

Compute pairwise distances across collections

from swarmauri_metric_hamming import HammingMetric

metric = HammingMetric()
left = [[0, 0, 0], [1, 1, 1]]
right = [[0, 0, 1], [1, 0, 1]]

print(metric.distances(left, right))

Verify metric axioms

from swarmauri_metric_hamming import HammingMetric

metric = HammingMetric()
x = [0, 1, 0, 1]
y = [0, 0, 1, 1]
z = [1, 0, 1, 0]

assert metric.check_non_negativity(x, y)
assert metric.check_symmetry(x, y)
assert metric.check_triangle_inequality(x, y, z)

Related Packages

Swarmauri Foundations

More Documentation

Best Practices

  • Validate equal-length inputs before calling distance() in external pipelines.
  • Use raw Hamming counts when exact mismatch positions matter more than a normalized ratio.
  • Normalize heterogeneous input types consistently before comparing large collections.
  • Pair this metric with domain-specific encoders when comparing symbolic or categorical data.

License

This project is licensed under the Apache-2.0 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_metric_hamming-0.11.0.dev1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file swarmauri_metric_hamming-0.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_metric_hamming-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_metric_hamming-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 856d3745103fa5ed9a8f94b8d301f24db18c885674ce18bbb2f594c0abe76e87
MD5 39053c38100c6947b4d06ad2057f5393
BLAKE2b-256 d1ed7f4150286d4e3fc9d3104f344a91633adb2fb9647bdf128b839b85efdd27

See more details on using hashes here.

File details

Details for the file swarmauri_metric_hamming-0.11.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_metric_hamming-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_metric_hamming-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5404473737f516f61a081581213368a8c326af9a43ecb0e9710473aaed855b4
MD5 6213ad832878c09365ad648c33ccc85c
BLAKE2b-256 36b86707a19f4238f3b172352878ddc9b1c7d952db5208fdaca67761826c4dc8

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 Pingdom Monitoring Sentry Error logging StatusPage Status page