Skip to content

Instantly share code, notes, and snippets.

View cdipaolo's full-sized avatar

Conner DiPaolo cdipaolo

View GitHub Profile
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
----
@cdipaolo
cdipaolo / kronmatvec.py
Last active July 27, 2019 18:32
Computes (Ar * ... * A2 * A1) x Efficiently where * is the Kronecker product.
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
#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
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.
@cdipaolo
cdipaolo / LICENSE.txt
Last active June 6, 2024 22:54
Estimate a known degrees of freedom student t distribution from data using the EM algorithm
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
@cdipaolo
cdipaolo / HaversinFormula.go
Created April 15, 2015 01:31
Golang functions to calculate the distance in meters between long,lat points on Earth.
// 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
//
@cdipaolo
cdipaolo / arrowUIBezierPath.swift
Created January 11, 2015 19:57
|| Swift || Create a UIBezierPath shaped like an arrow with given dimensions
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))