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
#define _GNU_SOURCE | |
#include <sched.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <signal.h> |
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
import numpy as np | |
from scipy.spatial import KDTree | |
def minkowski_distance_p(x, y, p=2): | |
""" | |
Compute the p-th power of the L**p distance between two arrays. | |
For efficiency, this function computes the L**p distance but does | |
not extract the pth root. If `p` is 1 or infinity, this is equal to | |
the actual L**p distance. |
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
import numpy as np | |
import networkx as nx | |
import heapq | |
from collections import defaultdict | |
def distance(u, v): | |
return np.sum((u - v)**2) | |
class KDTree(object): |
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
def choose(n,k): | |
"efficient calculation of nCr using sets" | |
if n < k: | |
raise ValueError('n < k') | |
n_set, k_set = set(range(1,n+1)), set(range(1,k+1)) | |
n_min_k_set = set(range(1,(n-k)+1)) | |
if len(n_min_k_set) < len(k_set): |