Skip to main content
mdapy logo

✨ Maximum Dissimilarity Algorithm in Python✨

Code Quality Coverage PyPI Latest Release PyPI Downloads Python License


mdapy-v2 is a maintained fork of IHCantabria/mdapy, developed by the original author. It keeps the legacy mdapy Python import while evolving the public API, correctness checks, examples, and performance of the algorithm.

Installation

mdapy-v2 requires Python 3.12 or newer.

pip install mdapy-v2

The distribution name changed, but the import remains short and familiar:

from mdapy import DataColumn, max_diss_alg

Quick start

Each DataColumn represents one variable. Mark angular variables as directional so that, for example, the distance between 350° and 10° is 20° rather than 340°.

from mdapy import DataColumn, max_diss_alg

tp = [14.93, 10.42, 7.46, 7.63, 12.20, 12.05, 14.49, 8.62]
hs = [1.82, 1.45, 0.26, 0.90, 1.30, 5.71, 1.40, 2.18]
direction = [268, 272, 289, 293, 276, 273, 276, 292]

points, indices = max_diss_alg(
    DataColumn(tp),
    DataColumn(hs),
    DataColumn(direction, directional=True),
    n_clusters=3,
)

points contains the selected observations in selection order and indices contains their positions in the original input. Use seed_index to choose a different initial observation:

points, indices = max_diss_alg(
    DataColumn(tp),
    DataColumn(hs),
    n_clusters=3,
    seed_index=4,
)

How it works

The implementation follows the formulation described in Appendix 1 of Guanche et al. (2013).

The Maximum Dissimilarity Algorithm builds a diverse subset iteratively:

  1. Start with the observation at seed_index (position 0 by default).
  2. Measure every unselected observation against its nearest selected one.
  3. Select the observation whose nearest distance is greatest.
  4. Repeat until n_clusters observations have been selected.

Distances are Euclidean after normalizing each variable by its standard deviation. Directional variables use the shortest angular distance and a circular standard deviation. Exact ties preserve input order.

Examples

Start with the minimal selection, a one-dimensional case small enough to follow in a debugger. The next example animates how the algorithm expands a diverse subset through a two-dimensional sample.

Maximum dissimilarity selection order in a two-dimensional sample

For a focused explanation of circular distances, see the directional variables example. The final example applies the algorithm to select representative sea states from 10,000 directional observations.

Representative sea states selected from directional wave data

Clone the repository and run any example in the project environment:

uv run python examples/1_mda_minimal.py

Legacy tuple API

Projects migrating from the original tuple-based API can use an explicit compatibility import:

from mdapy.legacy import max_diss_alg

points, indices = max_diss_alg(
    (tp, hs, direction),
    3,
    seed_index=0,
    dir_indices=[2],
)

Passing a tuple to mdapy.max_diss_alg raises an error that points to this compatibility module. The published ihc-mdapy==0.1.0 package uses the legacy API; its unpublished v0.1.1 fix remains available in this repository's Git history.

Development

Install the locked development environment and run the project checks:

make install
make format
make lint
make test

Credits and license

Originally developed by Pablo Garcia at IHCantabria and now maintained as the personal mdapy-v2 fork. The historical v0.1.1 fix was contributed by Álvaro Rodríguez, but was never included in the published ihc-mdapy package.

The original IHCantabria copyright notice and MIT terms are preserved in LICENSE.

Reference

Guanche, Y., Guanche, R., Camus, P., Mendez, F. J., & Medina, R. (2013). “A multivariate approach to estimate design loads for offshore wind turbines.” Wind Energy, 16(7), 1091–1106. https://doi.org/10.1002/we.1542

Metadata

Release files for mdapy-v2 2.1.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 mdapy-v2 2.1.0
File Size Uploaded
mdapy_v2-2.1.0.tar.gz 6.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mdapy-v2 2.1.0
File Interpreter ABI Platform
mdapy_v2-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / mdapy_v2-2.1.0.tar.gz

Download URL mdapy_v2-2.1.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a4dad5b1863bcad53ee1617b03ac90b6e5ad98d5d10f4f2cda7d35edffdab5df
BLAKE2b-256 checksum
How to use checksums
7af234568e8bde3b090570ffcfdcc3cd6d585323d4d2e10dc9a72d0d2a3cee92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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}

Release files / mdapy_v2-2.1.0-py3-none-any.whl

Download URL mdapy_v2-2.1.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c660e07cd6cf0a5f21993519aae735670cbb19404ee83fd74ace5c5f09d54a7
BLAKE2b-256 checksum
How to use checksums
29dbdda127916018a14ed55cddea64049ff55abb7c4065cc18290e12ee6bd425
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","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}

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

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