{"id":17043530,"url":"https://github.com/duhaime/lloyd","last_synced_at":"2025-04-12T15:11:20.185Z","repository":{"id":53922072,"uuid":"150890497","full_name":"duhaime/lloyd","owner":"duhaime","description":"Constrained Lloyd Iteration for distributing 2D points","archived":false,"fork":false,"pushed_at":"2021-06-08T01:06:34.000Z","size":3407,"stargazers_count":46,"open_issues_count":4,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T09:45:10.087Z","etag":null,"topics":["data-visualization","geometric-algorithms","lloyd-iteration","scatterplot"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/duhaime.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":"2018-09-29T18:07:34.000Z","updated_at":"2025-03-11T19:43:58.000Z","dependencies_parsed_at":"2022-08-13T04:20:50.101Z","dependency_job_id":null,"html_url":"https://github.com/duhaime/lloyd","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duhaime%2Flloyd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duhaime%2Flloyd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duhaime%2Flloyd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/duhaime%2Flloyd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/duhaime","download_url":"https://codeload.github.com/duhaime/lloyd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586230,"owners_count":21128997,"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":["data-visualization","geometric-algorithms","lloyd-iteration","scatterplot"],"created_at":"2024-10-14T09:29:47.353Z","updated_at":"2025-04-12T15:11:20.163Z","avatar_url":"https://github.com/duhaime.png","language":"Jupyter Notebook","readme":"# Lloyd's Algorithm\n\nThis package offers a Python implementation of Lloyd's algorithm, which can be used to distribute points in space. Using this algorithm, one can slightly rearrange points within a two-dimensional space in order to minimize the number of overlapping points while retaining the overall point distribution, which can greatly improve the usability of data visualizations.\n\n## Background\n\n[Lloyd iteration](https://en.wikipedia.org/wiki/Lloyd%27s_algorithm) is an algorithm for distributing points in a space. During each iteration, the algorithm builds a \u003ca href='https://en.wikipedia.org/wiki/Voronoi_diagram'\u003eVoronoi diagram\u003c/a\u003e that places each point into a distinct cell, then centers each point within its cell. By running several iterations of the algorithm, one can distribute points more and more uniformly in space. The image below shows how Lloyd's algorithm distributes points in space:\n\n\u003cimg src='plots/introduction.gif'\u003e\n\n## Usage\n\nThis package can be installed with pip:\n\n```bash\npip install lloyd\n```\n\nAfter installing the package, one can transform the positions of points within a two-dimensional numpy array by building a model, calling the `lloyd.relax()` method on that model, then calling `lloyd.get_points()` to get the projected point positions:\n\n```python\nfrom lloyd import Field\nimport numpy as np\n\n# generate 2000 observations with 2 dimensions\npoints = np.random.rand(2000, 2)\n\n# create a lloyd model on which one can perform iterations\nfield = Field(points)\n\n# run one iteration of Lloyd relaxation on the field of points\nfield.relax()\n\n# get the resulting point positions\nnew_positions = field.get_points()\n```\n\n`new_positions` will then be a numpy array with the same shape as `points`, only the positions of each point will be shifted slightly so as to minimize the number of overlapping points. To continue pushing points farther from one another, one can simply call the `.relax()` method on the lloyd model.\n\n## Visualizing Voronoi Maps\n\nFor examples of how to visualize the Voronoi maps created during each iteration of the model, see the attached notebook.\n\n## Constrained Lloyd Iteration\n\nLloyd iteration is an unconstrained algorithm. During each iteration, Lloyd's algorithm constructs a new Voronoi diagram and then centers each point within its cell. This means that points near the convex hull (the outside boundary) of a distribution tend towards infinity as one continues to run Lloyd iterations.\n\nTo solve this problem, this module implements internal constraints that ensure points remain within the input point domain after the model iterates. This ensures points near the convex hull do not disappear into the abyss as one continues running iterations.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduhaime%2Flloyd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fduhaime%2Flloyd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fduhaime%2Flloyd/lists"}