-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MarcusGitAccount
committed
Feb 22, 2019
1 parent
28384ef
commit 6095ecc
Showing
7 changed files
with
171 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: Current File (Integrated Terminal)", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "integratedTerminal" | ||
}, | ||
{ | ||
"name": "Python: Remote Attach", | ||
"type": "python", | ||
"request": "attach", | ||
"port": 5678, | ||
"host": "localhost", | ||
"pathMappings": [ | ||
{ | ||
"localRoot": "${workspaceFolder}", | ||
"remoteRoot": "." | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Python: Module", | ||
"type": "python", | ||
"request": "launch", | ||
"module": "enter-your-module-name-here", | ||
"console": "integratedTerminal" | ||
}, | ||
{ | ||
"name": "Python: Django", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${workspaceFolder}/manage.py", | ||
"console": "integratedTerminal", | ||
"args": [ | ||
"runserver", | ||
"--noreload", | ||
"--nothreading" | ||
], | ||
"django": true | ||
}, | ||
{ | ||
"name": "Python: Flask", | ||
"type": "python", | ||
"request": "launch", | ||
"module": "flask", | ||
"env": { | ||
"FLASK_APP": "app.py" | ||
}, | ||
"args": [ | ||
"run", | ||
"--no-debugger", | ||
"--no-reload" | ||
], | ||
"jinja": true | ||
}, | ||
{ | ||
"name": "Python: Current File (External Terminal)", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "externalTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.pythonPath": "C:\\Users\\pop_m\\Anaconda3\\python.exe" | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
from functools import cmp_to_key | ||
from heap import Heap | ||
from ball_tree import BallTree, euclid_metric | ||
|
||
if __name__ == '__main__': | ||
plt.title = 'KNN search.' | ||
points = np.random.randint(100, size=(20, 2)) | ||
|
||
plt.rcParams["font.size"] = 1 | ||
x = points[:, 0] | ||
y = points[:, 1] | ||
plt.scatter(x, y) | ||
|
||
tree = BallTree(points, euclid_metric) | ||
point = np.random.randint(0, 100, 2) | ||
x_, y_ = point | ||
plt.plot(x_, y_, 'bo', color='red') | ||
|
||
distances = sorted([euclid_metric(point, candidate) for candidate in points]) | ||
s = set(distances) | ||
|
||
k = 10 | ||
cmp = lambda a, b: a[1] > b[1] | ||
heap = Heap(cmp) | ||
for candidate in points: | ||
distance = euclid_metric(point, candidate) | ||
if len(heap) < k or distance < heap[0][1]: | ||
heap.push((candidate, distance)) | ||
if len(heap) > k: | ||
heap.pop() | ||
for candidate in heap: | ||
print(candidate) | ||
x_, y_ = candidate[0] | ||
plt.plot(x_, y_, 'bo', color='pink') | ||
|
||
print(distances[:k]) | ||
all = True | ||
for candidate in heap: | ||
if not candidate[1] in s: | ||
all = False | ||
break | ||
print('All? %s' % all) | ||
plt.show() |