{"id":19982641,"url":"https://github.com/zabuzard/closy","last_synced_at":"2025-05-04T05:32:27.532Z","repository":{"id":57735417,"uuid":"219062715","full_name":"Zabuzard/Closy","owner":"Zabuzard","description":"Closy is a library that provides fast and generic solutions for nearest neighbor search (NNS)","archived":false,"fork":false,"pushed_at":"2021-02-13T00:21:57.000Z","size":63,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-04T09:30:59.428Z","etag":null,"topics":["api","knearest-neighbor-algorithm","library","nearest-neighbor-search","nearest-neighbors","nns","nnsearch"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zabuzard.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-11-01T21:06:25.000Z","updated_at":"2023-10-19T03:54:03.000Z","dependencies_parsed_at":"2022-08-23T15:21:51.865Z","dependency_job_id":null,"html_url":"https://github.com/Zabuzard/Closy","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zabuzard%2FClosy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zabuzard%2FClosy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zabuzard%2FClosy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zabuzard%2FClosy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zabuzard","download_url":"https://codeload.github.com/Zabuzard/Closy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252293082,"owners_count":21724960,"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":["api","knearest-neighbor-algorithm","library","nearest-neighbor-search","nearest-neighbors","nns","nnsearch"],"created_at":"2024-11-13T04:12:25.075Z","updated_at":"2025-05-04T05:32:27.231Z","avatar_url":"https://github.com/Zabuzard.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Closy\n[![codefactor](https://img.shields.io/codefactor/grade/github/Zabuzard/Closy)](https://www.codefactor.io/repository/github/zabuzard/closy)\n[![maven-central](https://img.shields.io/maven-central/v/io.github.zabuzard.closy/closy)](https://search.maven.org/search?q=g:io.github.zabuzard.closy)\n[![javadoc](https://javadoc.io/badge2/io.github.zabuzard.closy/closy/javadoc.svg?style=flat\u0026color=AA82FF)](https://javadoc.io/doc/io.github.zabuzard.closy/closy)\n![Java](https://img.shields.io/badge/Java-9%2B-ff696c)\n[![license](https://img.shields.io/github/license/Zabuzard/Closy)](https://github.com/Zabuzard/Closy/blob/master/LICENSE)\n\nClosy is a simple library for efficient **nearest neighbor computations**. It is designed generic and can be used\nwith **any class** that defines a [metric](https://en.wikipedia.org/wiki/Metric_(mathematics)).\n\nIt is able to compute the nearest neighbor to a given point, as well as retrieving the k-nearest neighbors and also all\nneighbors within a given range. The corresponding methods are:\n\n* `Optional\u003cE\u003e getNearestNeighbor(E point)`\n* `Collection\u003cE\u003e getKNearestNeighbors(E point, int k)`\n* `Collection\u003cE\u003e getNeighborhood(E point, double range)`\n\n# Requirements\n\n* Requires at least **Java 9**\n\n# Download\n\nMaven:\n\n```xml\n\u003cdependency\u003e\n   \u003cgroupId\u003eio.github.zabuzard.closy\u003c/groupId\u003e\n   \u003cartifactId\u003eclosy\u003c/artifactId\u003e\n   \u003cversion\u003e1.2.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nJar downloads are available from the [release section](https://github.com/ZabuzaW/Closy/releases).\n\n# Documentation\n\n* [API Javadoc](https://javadoc.io/doc/io.github.zabuzard.closy/closy) or alternatively from the [release section](https://github.com/ZabuzaW/Closy/releases)\n\n# Getting started\n\n1. Integrate **Closy** into your project. The API is contained in the module `io.github.zabuzard.closy`.\n2. Create an implementation of `Metric\u003cE\u003e` for your custom `E` objects\n3. Create an algorithm using `NearestNeighborComputations#of(Metric\u003cE\u003e)`\n4. Add your objects to the algorithm using `NearestNeighborComputation#add(E)`\n5. Execute nearest neighbor computations using the methods offered by `NearestNeighborComputation`\n\n# Example\n\nConsider the following simple class for points in a 2-dimensional space\n\n```java\nclass Point {\n    private final int x;\n    private final int y;\n\n    // constructor, getter, equals, hashCode and toString omitted\n}\n```\n\nAs first step, we need to define a `Metric` that operates on `Point`. We decide for\nthe [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance):\n\n```java\nclass EuclideanDistance implements Metric\u003cPoint\u003e {\n\t@Override\n\tpublic double distance(final Point a, final Point b) {\n\t\treturn Math.sqrt(Math.pow(b.getX() - a.getX(), 2) + Math.pow(b.getY() - a.getY(), 2));\n\t}\n}\n```\n\nNext, we create an algorithm using this metric and then add some points to it:\n\n```java\nvar metric = new EuclideanDistance();\nvar algo = NearestNeighborComputations.of(metric);\n\nalgo.add(Point.of(1, 2));\nalgo.add(Point.of(5, 7));\nalgo.add(Point.of(-10, 4));\nalgo.add(Point.of(9, 8));\nalgo.add(Point.of(3, 3));\n```\n\nFinally, we use the methods provided by `NearestNeighborComputation`\nto compute some nearest neighbors:\n\n```java\nvar point = Point.of(4, 2);\nOptional\u003cPoint\u003e neighbor = algo.getNearestNeighbor(point);          // (3, 3)\nCollection\u003cPoint\u003e neighbors = algo.getKNearestNeighbors(point, 3);  // [(3, 3), (1, 2), (5, 7)]\nCollection\u003cPoint\u003e neighborhood = algo.getNeighborhood(point, 3.5);  // [(1, 2), (3, 3)]\n```\n\n***\n\n# Background\n\nThe current implementation uses [Cover Trees](https://en.wikipedia.org/wiki/Cover_tree), based on the implementation\ndescribed in [Cover Trees for  Nearest Neighbor](https://dl.acm.org/citation.cfm?id=1143857) (_Beygelzimer et al. in\nICML '06_).\n\nA detailed description and benchmark can be found\nin [Multi-Modal Route Planning in Road and Transit Networks](https://arxiv.org/abs/1809.05481) (_Daniel Tischner '18_).\n\nThe following is a benchmark of [Closy version 1.0](https://github.com/Zabuzard/Cobweb). The experiment consists of\ncontinuous insertion of nodes, for each of three road networks respectively, and then measuring random nearest neighbor\nqueries, i.e. the execution time of the algorithm. Measurements are done for tree sizes of 1, 10000 and then in steps of\n\n10000. Each measurement is averaged over 1000 queries using randomly selected nodes.\n\n![Close version 1.0 benchmark](https://i.imgur.com/8qWYBG7.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzabuzard%2Fclosy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzabuzard%2Fclosy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzabuzard%2Fclosy/lists"}