Skip to main content

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.

Release files for hiwenet 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hiwenet 0.6.0
File Size Uploaded
hiwenet-0.6.0.tar.gz 17.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hiwenet 0.6.0
File Interpreter ABI Platform
hiwenet-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.2 kB

Release files / hiwenet-0.6.0.tar.gz

Download URL hiwenet-0.6.0.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1676f9ac50989a6c4911ad39fcbebb1058d84d3bbe97ea41d9bf6d3762c03211
BLAKE2b-256 checksum
How to use checksums
0b47b680a349c3cf6587257b6e6f008f9fdb8546ff567ec1c4ddc37ae0431418
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.2 cpython/3.13.1 HTTPX/0.28.1

Release files / hiwenet-0.6.0-py3-none-any.whl

Download URL hiwenet-0.6.0-py3-none-any.whl
Size 21.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
186bb00e93795e6e105ce43baa4e2420239e94365e8183fe71ba26fdf143f32f
BLAKE2b-256 checksum
How to use checksums
38344d9d664639e26b5211d68835fe32ca4faff8bc4b8cf7fe8ac5767b2c8085
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.2 cpython/3.13.1 HTTPX/0.28.1

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.4.5

2 release files

0.4.3

2 release files

0.4.2

1 release file

0.4.1

2 release files

0.4

2 release files

0.3.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page