Skip to content

Instantly share code, notes, and snippets.

@ljwolf
ljwolf / fastkernel.py
Last active September 26, 2022 16:15
Towards a faster kernel weights class in PySAL
from sklearn import metrics
from sklearn.neighbors import BallTree
import numpy, pandas
from scipy.optimize import minimize_scalar
from scipy import sparse, stats
from libpysal.weights import WSP, Kernel
from libpysal.weights.util import get_points_array
coordinates = numpy.random.normal(0, 1, size=(100, 2))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
We can't make this file beautiful and searchable because it's too large.
latitude,longitude,q-score,geometry
40.571148,-73.997086,10.854957,POINT (-73.997086 40.571148)
40.571148,-73.996719,13.955506,POINT (-73.996719 40.571148)
40.571159,-73.995979,11.594976,POINT (-73.99597900000001 40.571159)
40.571167,-73.995605,12.206305,POINT (-73.995605 40.571167)
40.571175,-73.998177,11.686462,POINT (-73.998177 40.571175)
40.571178,-73.994858,11.74865,POINT (-73.99485799999999 40.571178)
40.571178,-73.99781,11.360404,POINT (-73.99781 40.571178)
40.571186,-73.994476,11.910742,POINT (-73.99447600000001 40.571186)
@ljwolf
ljwolf / losh.py
Created June 12, 2020 11:51
Losh function by @jeffcsauer
import numpy
from scipy import sparse
from scipy import stats
from sklearn.base import BaseEstimator
import pysal.lib as lp
class losh(BaseEstimator):
"""Local spatial heteroscedasticity (LOSH)"""
@ljwolf
ljwolf / divergence.py
Last active January 24, 2020 12:40
This is the egohood-style estimators that I is in the spirit of https://www.pnas.org/content/pnas/116/25/12250.full.pdf. See https://www.youtube.com/watch?v=ezYxhmcDM6M&feature=youtu.be for the visualization
import numpy as np
from scipy.spatial import distance
from scipy.special import (entr, rel_entr, kl_div)
def entropy(p, q=None):
p = np.asarray(p)
if p.ndim == 1:
p = p.reshape(1,-1)
p = p/p.sum(axis=1, keepdims=True)
if q is None:
@ljwolf
ljwolf / alphabug.ipynb
Last active October 10, 2019 14:57 — forked from sjsrey/alphabug.ipynb
alpha clipping bug
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# packages in environment at /home/lw17329/anaconda/envs/ana:
#
# Name Version Build Channel
_r-mutex 1.0.0 mro_2 r
affine 2.2.1 py_0 conda-forge
appdirs 1.4.3 py37h28b3542_0
asn1crypto 0.24.0 py37_0
atomicwrites 1.1.5 py37_0
atomicwrites 1.1.5 <pip>
attrs 18.1.0 py_1 conda-forge