Skip to main content

Histogram-weighted pairwise distances for node-wise feature data.

Project description

Histogram-weighted Networks (hiwenet)

status

hiwenet computes pairwise distances between groups of node-wise feature values. Its main role today is as the numerical engine behind graynet, but it can also be used directly whenever you need histogram-based or original-distribution-based distances between groups.

Given:

  • a 1D array of feature values
  • a matching 1D array of group labels
  • a distance metric

hiwenet returns either:

  • a pairwise distance matrix
  • an in-memory NetworkX graph with the same edge weights

This release is intentionally programmatic and does not provide a CLI.

illustration

Installation

pip install -U hiwenet

Quick Start

import numpy as np

from hiwenet import extract

features = np.array([0.2, 0.1, 0.3, 1.0, 1.2, 0.9])
groups = np.array([0, 0, 0, 1, 1, 1])

edge_weights = extract(
    features,
    groups,
    weight_method="manhattan",
)

The default output matches what graynet expects: a square NumPy array whose upper triangle stores the pairwise edge weights.

API

extract

extract() is the main entry point.

from hiwenet import extract

edge_weights = extract(
    features,
    groups,
    weight_method="manhattan",
    num_bins=25,
    edge_range=None,
    trim_outliers=True,
    trim_percentile=5,
    use_original_distribution=False,
    relative_to_all=False,
    asymmetric=False,
    return_networkx_graph=False,
)

ExtractConfig

If you prefer a validated configuration object:

from hiwenet import ExtractConfig, extract_with_config

config = ExtractConfig(
    weight_method="manhattan",
    num_bins=25,
)

edge_weights = extract_with_config(features, groups, config)

Metrics

hiwenet supports both histogram-based distances and distances that operate on the original values in each group.

Histogram-based metrics include:

  • manhattan
  • euclidean
  • chebyshev
  • braycurtis
  • canberra
  • cosine
  • correlation
  • emd
  • kl_divergence
  • js_divergence

Original-distribution metrics include:

  • diff_medians
  • diff_medians_abs
  • diff_means
  • diff_means_abs
  • exp_diff_means_norm_std
  • ranksum_statistic

Custom callables are also supported.

Relative-To-All

relative_to_all=True remains available for workflows that compare each group against the pooled distribution from all groups.

Scientific Notes

  • Explicit edge_range values are useful when you need consistent histogram support across subjects.
  • Built-in non-histogram metrics operate on the original values in each group.
  • Degenerate histogram cases are handled deterministically in this release instead of relying on runtime-warning-driven NaN outputs.

Development

pytest -q
hatch build

Citation

If hiwenet is useful in your work, please cite the JOSS paper linked above.

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

hiwenet-0.6.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

hiwenet-0.6.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file hiwenet-0.6.0.tar.gz.

File metadata

  • Download URL: hiwenet-0.6.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.2 cpython/3.13.1 HTTPX/0.28.1

File hashes

Hashes for hiwenet-0.6.0.tar.gz
Algorithm Hash digest
SHA256 1676f9ac50989a6c4911ad39fcbebb1058d84d3bbe97ea41d9bf6d3762c03211
MD5 8956ba22ef2949eb6c2bc4f0298c4332
BLAKE2b-256 0b47b680a349c3cf6587257b6e6f008f9fdb8546ff567ec1c4ddc37ae0431418

See more details on using hashes here.

File details

Details for the file hiwenet-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: hiwenet-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.2 cpython/3.13.1 HTTPX/0.28.1

File hashes

Hashes for hiwenet-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 186bb00e93795e6e105ce43baa4e2420239e94365e8183fe71ba26fdf143f32f
MD5 36fc94694bea3e65ee20204aea9df3a0
BLAKE2b-256 38344d9d664639e26b5211d68835fe32ca4faff8bc4b8cf7fe8ac5767b2c8085

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