Giter Site home page Giter Site logo

paulnorthrop / donut Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 1.15 MB

Nearest Neighbour Search with Variables on a Torus

Home Page: https://paulnorthrop.github.io/donut/

R 96.47% TeX 3.53%
nearest-neighbours torus donut degrees periodicity wrap edges rann nabor nearest-neighbor-search

donut's Introduction

donut

AppVeyor Build Status R-CMD-check Coverage Status CRAN_Status_Badge Downloads (monthly) Downloads (total)

Nearest Neighbour Search with Variables on a Torus

What does donut do?

There are several R packages, such as RANN and nabor that find the $k$ nearest neighbours in a dataset of specified query points, based on some metric, such as L2 or L1. The donut package considers the situation where one or more of the variables in the dataset is periodic on a finite interval. For example, direction is periodic on the interval $(0, 360)$ degrees. In the small dataset ${10, 90, 350}$ degrees 350 is closer to 10 than is 90: 10 and 350 are separated by 20 degrees, 10 and 90 by 80 degrees.

The function nnt() finds the $k$ nearest neighbours of each of a set of points of interest, wrapping periodic variables on a torus so that this periodicity is reflected. The user chooses the function to use to find the nearest neighbours. The nearest neighbour functions from the aforementioned packages are used as examples.

An example

We use a simple example from the RANN:nn2() documentation. We suppose that both variables should be wrapped, on the ranges $(0, 2\pi)$ and $(0, 3)$ respectively. We choose the query points of interest to illustrate the wrapping of the variables. In the plot, query points are indicated with colour-coded crosses and the 8 nearest neighbours of each point are shaded in the same colour. By default nnt() uses the function RANN::nn2() (based on the L2 metric) to find the nearest neighbours.

library(donut)
set.seed(20092019)
x1 <- runif(100, 0, 2 * pi)
x2 <- runif(100, 0, 3)
DATA <- data.frame(x1, x2)
ranges <- rbind(c(0, 2 * pi), c(0, 3))
query <- rbind(c(6, 1.3), c(2 * pi, 3), c(3, 1.5), c(4, 0))
library(RANN)
#> Warning: package 'RANN' was built under R version 4.2.3
res2 <- nnt(DATA, query, k = 8, torus = 1:2, ranges = ranges)
plot(res2)

Installation

To get the current released version from CRAN:

install.packages("donut")

Vignette

See vignette("donut-vignette", package = "donut") for an overview of the package.

donut's People

Contributors

paulnorthrop avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.