K-nearest neighbors search of a 2D set of points. Move the slider or scroll to change k.
The algorithm was adapted from this block
# Basic key operators to query the JSON objects : | |
# #> : Get the JSON object at that path (if you need to do something fancy) | |
# -> : Get the JSON object at that path (if you don't) | |
# ->> : Get the JSON object at that path as text | |
# {obj, n} : Get the nth item in that object | |
# https://www.postgresql.org/docs/9.4/functions-json.html#FUNCTIONS-JSONB-OP-TABLE | |
# Date | |
# date before today |
{0: 'tench, Tinca tinca', | |
1: 'goldfish, Carassius auratus', | |
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias', | |
3: 'tiger shark, Galeocerdo cuvieri', | |
4: 'hammerhead, hammerhead shark', | |
5: 'electric ray, crampfish, numbfish, torpedo', | |
6: 'stingray', | |
7: 'cock', | |
8: 'hen', | |
9: 'ostrich, Struthio camelus', |
def lat_lon_hex_mesh(bounds, d=3): | |
"""Creates a hexagonal lat/lon mesh within bounds that has a radial separation of d""" | |
lone, lonw, lats, latn = bounds | |
# heigt of equilatral triangle from radial distance sqrt(r^2 - (r/2)^2) | |
h = np.sqrt(0.75) * d | |
w = d / 2 | |
lat_vals = np.arange(lats, latn, h) |
import matplotlib | |
matplotlib.use('webagg') | |
import numpy as np | |
from scipy.special import binom | |
import matplotlib.pyplot as plt | |
from matplotlib.lines import Line2D |
license: gpl-3.0 | |
border: no | |
scrolling: no | |
height: 500 |
<html> | |
<head> | |
<title> | |
[Visualizing Movement Data with D3.js] | |
</title> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://omid.al/Mova-Viz/MovaViz-v0.1.2.js"></script> | |
<style> | |
* { | |
box-sizing: border-box |
K-nearest neighbors search of a 2D set of points. Move the slider or scroll to change k.
The algorithm was adapted from this block
k-d tree nearest neighbors search (k-NN). The red dots are the 10 nearest neighbors. Orange dots are scanned and not selected.
Compare with this block that implements a k nearest neighbor search using a quadtree instead of a k-d tree.
The algorithm for this search came from this course handout. Note that the "k" in k-d tree need not be the same number as the "k" in
license: gpl-3.0 |
license: mit |