Skip to main content

Sort sequences with respect to the similarity of consecutive items.

Project description

Sort sequences with respect to the similarity of consecutive items.

Definition

Given a sequence of items \((x_i, y_i)\), where each item is represented by two values \(x, y\), the goal is to sort the sequence such that the following loss is minimal:

\begin{equation*} L = \sum_{i=1}^{N-1} \mu(y_i, x_{i+1}) \end{equation*}

where \(\mu\) denotes a suitable metric for the items’ values.

Example

Given the items

>>> items = [
...     (0.4, 0.6),
...     (0.0, 0.2),
...     (0.8, 1.0),
...     (0.6, 0.8),
...     (0.2, 0.4),
... ]

together with the L1 distance \(\mu: (x, y) \rightarrow |x-y|\), the current loss is

>>> abs(0.6 - 0.0) + abs(0.2 - 0.8) + abs(1.0 - 0.6) + abs(0.8 - 0.2)
2.2

Clearly the optimal sort order which minimizes the loss is

>>> optimal = [
   ...     (0.0, 0.2),
   ...     (0.2, 0.4),
   ...     (0.4, 1.6),
   ...     (0.6, 0.8),
   ...     (0.8, 1.0),
   ... ]

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

dominosort-0.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file dominosort-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dominosort-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 900a921343243985d42d51ff9655442f07ec3757451ce06314806889e354e1c4
MD5 a6500aa2e010a5518ed9fafa92292d0f
BLAKE2b-256 1779fcc54d8b1f9d05a7e7b6792d075a801eb36c553a31caf572b0aadea2bfff

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page