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
extension UIBezierPath { | |
// creates an arrow shaped path with middle of base as start point and pointed end as end point | |
class func arrowPath(tailLength: CGFloat, tailWidth: CGFloat, headWidth: CGFloat) -> UIBezierPath { | |
let midY: CGFloat = tailWidth / 2 | |
var polygonPath = UIBezierPath() | |
polygonPath.moveToPoint(CGPointMake(0, 0)) | |
polygonPath.addLineToPoint(CGPointMake( 0, -midY)) |
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
// haversin(θ) function | |
func hsin(theta float64) float64 { | |
return math.Pow(math.Sin(theta/2), 2) | |
} | |
// Distance function returns the distance (in meters) between two points of | |
// a given longitude and latitude relatively accurately (using a spherical | |
// approximation of the Earth) through the Haversin Distance Formula for | |
// great arc distance on a sphere with accuracy for small distances | |
// |
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 is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit |
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 | |
def whiten(X): | |
'''whiten | |
Takes a data matrix X in R^{n\times p} and returns a matrix | |
Y with zero column mean and identity covariance. Assumes | |
your data has full column rank. For speed, if n is 10000 | |
and p is 400, this takes about 150ms, for example. | |
:param X: Data matrix where rows are samples and cols are features. |
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
#Python 3.6.5 (default, Jun 17 2018, 12:13:06) | |
#Type 'copyright', 'credits' or 'license' for more information | |
#IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help. | |
#Using matplotlib backend: MacOSX | |
In [6]: import scipy | |
In [7]: from scipy import linalg | |
In [1]: n, p = 10**5, 10**2 |
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 | |
def kronmatvec(A, x): | |
"""Given a list of matrices A = [Ar,...,A1] and a vector x, | |
return (Ar o ... o A1)x where o is the Kronecker product. | |
Note | |
---- | |
This function assumes each A[i] is square, and that the vector | |
x is of suitable dimension to make the matrix-vector product |
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 scipy.linalg | |
def kronsolve(A, y): | |
"""Given a list of positive definite matrices A = [Ar,...,A1] | |
and a vector y, return x so that (Ar o ... o A1)x = y where o is | |
the Kronecker product. | |
Note | |
---- |