from scipy.spatial import Delaunay, ConvexHull
import networkx as nx
points = [ [0,0],[0,50],[50,50],[50,0],[0,400],[0,450],[50,400],[50,450],[700,300],[700,350],[750,300],[750,350],
[900,600],[950,650],[950,600],[900,650]
]
def concave(points,alpha_x=150,alpha_y=250):
points = [(i[0],i[1]) if type(i) <> tuple else i for i in points]
de = Delaunay(points)
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 sklearn.metrics import euclidean_distances | |
#Re-implementation of bisect functions of bisect module to suit the application | |
def bisect_left(a, x): | |
lo = 0 | |
hi = len(a) | |
while lo < hi: | |
mid = (lo+hi)//2 | |
if a[mid] < x: |
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
# (C) Mathieu Blondel, November 2013 | |
# License: BSD 3 clause | |
import numpy as np | |
def ranking_precision_score(y_true, y_score, k=10): | |
"""Precision at rank k | |
Parameters |
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
# (C) Mathieu Blondel, November 2013 | |
# License: BSD 3 clause | |
import numpy as np | |
from scipy.linalg import svd | |
def frequent_directions(A, ell, verbose=False): | |
""" | |
Return the sketch of matrix A. |
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
#!/usr/bin/python | |
""" | |
Author: Jeremy M. Stober | |
Program: GP.PY | |
Date: Thursday, July 17 2008 | |
Description: Example of Gaussian Process Regression. | |
""" | |
from numpy import * | |
import pylab |
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 table is useful for rough statistics based on gender | |
-- Don't consider it scientific in any way. | |
-- | |
-- Example use: | |
-- select COALESCE( | |
-- (SELECT gender | |
-- FROM gender_types | |
-- WHERE name=users.first_name | |
-- LIMIT 1), | |
-- 'U') gender_type, count(*) |
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
#First tweet on 21 Mar 2006 at 20:50:14.000 GMT (in ms) | |
TWEPOCH = 1288834974657 | |
#High 42 bytes are timestamp, low 22 are worker, datacenter and sequence bits | |
SHIFT = 22 | |
# Give it a snowflake id, it tells you what time it was created | |
# Will fail for very high ids because Ruby Time can only represent up to | |
# Jan 18, 2038 at 19:14:07 UTC (max signed int in seconds since unix epoch) | |
def what_time?(id) |
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
# Chan's Convex Hull O(n log h) - Tom Switzer <thomas.switzer@gmail.com> | |
TURN_LEFT, TURN_RIGHT, TURN_NONE = (1, -1, 0) | |
def turn(p, q, r): | |
"""Returns -1, 0, 1 if p,q,r forms a right, straight, or left turn.""" | |
return cmp((q[0] - p[0])*(r[1] - p[1]) - (r[0] - p[0])*(q[1] - p[1]), 0) | |
def _keep_left(hull, r): | |
while len(hull) > 1 and turn(hull[-2], hull[-1], r) != TURN_LEFT: |