{"id":23920495,"url":"https://github.com/justinshenk/closely","last_synced_at":"2025-02-23T21:25:57.324Z","repository":{"id":60721975,"uuid":"187990744","full_name":"JustinShenk/closely","owner":"JustinShenk","description":"Python library for finding the closest pairs in an array","archived":false,"fork":false,"pushed_at":"2019-06-17T15:34:44.000Z","size":266,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-05T16:04:59.401Z","etag":null,"topics":["closest-pair-of-points","neighbors","points","similarity"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JustinShenk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-22T07:56:03.000Z","updated_at":"2023-03-09T00:50:28.000Z","dependencies_parsed_at":"2022-10-03T20:31:22.562Z","dependency_job_id":null,"html_url":"https://github.com/JustinShenk/closely","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustinShenk%2Fclosely","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustinShenk%2Fclosely/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustinShenk%2Fclosely/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustinShenk%2Fclosely/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JustinShenk","download_url":"https://codeload.github.com/JustinShenk/closely/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240381396,"owners_count":19792452,"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":["closest-pair-of-points","neighbors","points","similarity"],"created_at":"2025-01-05T15:49:39.469Z","updated_at":"2025-02-23T21:25:57.291Z","avatar_url":"https://github.com/JustinShenk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :triangular_ruler: Closely \n [![PyPI version](https://badge.fury.io/py/closely.svg)](https://badge.fury.io/py/closely) [![Build Status](https://travis-ci.com/justinshenk/closely.svg?branch=master)](https://travis-ci.com/justinshenk/closely) [![DOI](https://zenodo.org/badge/187990744.svg)](https://zenodo.org/badge/latestdoi/187990744)\n\n\n\nFind the closest pairs in an array. \n\nClosely compares distances of arrays/embeddings and sorts them.\n\n### Getting Started\n\n```bash\npip install closely\n```\n\nor install from source:\n\n```bash\ngit clone https://github.com/justinshenk/closely\ncd closely\npip install .\n```\n\n### How to use\n\n```python\nimport closely\n\n# X is an n x m numpy array\npairs, distances = closely.solve(X, n=1)\n```\n\nYou can specify how many pairs you want to identify with `n`.\n\n#### Distance Metric\n\nThe distance metric can be changed from the default `euclidean` to any supported by [`scipy.spatial.distance.cdist`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cdist.html), eg, `cosine`, `hamming`, etc:\n\n```python\nclosely.solve(X, metric='cosine`)\n```\n\n### Example\n```python\nimport closely\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Create dataset\nX = np.random.random((100,2))\npairs, distances = closely.solve(X, n=1)\n\n# Plot points\nz, y = np.split(X, 2, axis=1)\nfig, ax = plt.subplots()\nax.scatter(z, y) \n\nfor i, txt in enumerate(X): \n    if i in pairs: \n        ax.annotate(i, (z[i], y[i]), color='red') \n    else: \n        ax.annotate(i, (z[i], y[i]))\n\nplt.show() \n```\n\nCheck `pairs`:\n```ipython\nIn [10]: pairs                                                                                                                                \nOut[10]: \narray([[ 7, 16],\n       [96, 50]])\n\n```\n\nOutput:\n![example_plot](example_plot.png)\n\n### Credit and Explanation\n\nPython code for ordering distance matrices modified from [Andriy Lazorenko](https://medium.com/@andriylazorenko/closest-pair-of-points-in-python-79e2409fc0b2), packaged and made useful for \u003e2 features by Justin Shenk.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinshenk%2Fclosely","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustinshenk%2Fclosely","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustinshenk%2Fclosely/lists"}