{"id":27881777,"url":"https://github.com/src-d/seriate","last_synced_at":"2025-05-05T05:05:04.656Z","repository":{"id":46193545,"uuid":"177169303","full_name":"src-d/seriate","owner":"src-d","description":"Optimal ordering of elements in a set given their distance matrix.","archived":false,"fork":false,"pushed_at":"2023-10-02T15:58:29.000Z","size":2457,"stargazers_count":17,"open_issues_count":4,"forks_count":11,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-05T05:04:57.761Z","etag":null,"topics":["python","seriation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/src-d.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-22T15:54:02.000Z","updated_at":"2024-12-17T17:59:11.000Z","dependencies_parsed_at":"2023-02-02T08:02:29.264Z","dependency_job_id":null,"html_url":"https://github.com/src-d/seriate","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/src-d%2Fseriate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/src-d%2Fseriate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/src-d%2Fseriate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/src-d%2Fseriate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/src-d","download_url":"https://codeload.github.com/src-d/seriate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252442485,"owners_count":21748451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","seriation"],"created_at":"2025-05-05T05:05:04.095Z","updated_at":"2025-05-05T05:05:04.640Z","avatar_url":"https://github.com/src-d.png","language":"Python","readme":"# seriate\nOptimal ordering of elements in a set given their distance matrix.\n\n[![Travis build status](https://travis-ci.com/src-d/seriate.svg?branch=master)](https://travis-ci.com/src-d/seriate)\n[![Code coverage](https://codecov.io/github/src-d/seriate/coverage.svg)](https://codecov.io/github/src-d/seriate)\n[![PyPi package status](https://img.shields.io/pypi/v/seriate.svg)](https://pypi.python.org/pypi/seriate)\n![stability: stable](https://svg-badge.appspot.com/badge/stability/stable?color=007ec6)\n[![Apache 2.0 license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\n![example](doc/example.png)\n\n[Overview](#overview) • [How To Use](#how-to-use) • [Contributions](#contributions) • [License](#license)\n\n## Overview\n\nThis is a Python implementation of [Seriation](http://nicolas.kruchten.com/content/2018/02/seriation/)\nalgorithm. Seriation is an approach for ordering elements in a set so that the\nsum of the sequential pairwise distances is minimal. We state this task\nas a Travelling Salesman Problem (TSP) and leverage the powerful [Google's or-tools](https://github.com/google/or-tools)\nto do heavy-lifting. Since TSP is NP-hard, it is not possible to calculate\nthe precise solution for a big number of elements. However, the or-tools'\nheuristics work very well in practice, and they are used in e.g. Google Maps.\n\nAny [`numpy.roll`-ed](https://docs.scipy.org/doc/numpy-1.16.0/reference/generated/numpy.roll.html)\nresult is equivalent.\n\n## How To Use\n\n```python\nimport numpy\nfrom scipy.spatial.distance import pdist\nfrom seriate import seriate\n\nelements = numpy.array([\n    [3, 3, 3],\n    [5, 5, 5],\n    [4, 4, 4],\n    [2, 2, 2],\n    [1, 1, 1]\n])\n\nprint(seriate(pdist(elements)))\n\n# Output: [4, 3, 0, 2, 1]\n```\n\nThe example above shows how we order 5 elements: `[3, 3, 3]`,\n`[5, 5, 5]`, `[4, 4, 4]`, `[2, 2, 2]` and `[1, 1, 1]`. The result\nis expected:\n\n1. `[1, 1, 1]` \n2. `[2, 2, 2]` \n3. `[3, 3, 3]` \n4. `[4, 4, 4]` \n5. `[5, 5, 5]`\n\n`pdist` from [`scipy.spatial.distance`](https://docs.scipy.org/doc/scipy/reference/spatial.distance.html)\nuses Euclidean (L2) dstance metric by default, so the distance between\n`[x, x, x]` and `[x + 1, x + 1, x + 1]` is constant: √3. Any other distance\nis bigger, so the optimal ordering is to list our elements in the increasing\nnorm order.\n\n## Contributions\n\nContributions are very welcome and desired! Please follow the [code of conduct](doc/code_of_conduct.md)\nand read the [contribution guidelines](doc/contributing.md).\n\n## License\n\nApache-2.0, see [LICENSE.md](LICENSE.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrc-d%2Fseriate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrc-d%2Fseriate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrc-d%2Fseriate/lists"}