Skip to content
This repository has been archived by the owner on Jul 19, 2018. It is now read-only.

Thoughts about adaptive gaussian #12

Closed
Ziqi-Li opened this issue Feb 1, 2018 · 2 comments
Closed

Thoughts about adaptive gaussian #12

Ziqi-Li opened this issue Feb 1, 2018 · 2 comments

Comments

@Ziqi-Li
Copy link
Member

Ziqi-Li commented Feb 1, 2018

The adaptive gaussian and adaptive bisquare show totally different curves for the model PctBach~FB+Black+Pov. The optimal bandwidth found for adaptive gaussian would be local and for adaptive bisquare would be global. Test against GWModel is showing exactly same curves. Test against ArcGIS adaptive gaussian is showing similar curve as PySAL's adaptive bisqaure. BTW, ArcGIS claims their gaussian kernel is w = exp(-(d/b)**2), while we are using exp(-0.5*(d/b)**2) which is from the book. Will look into to see what it implies.

#Imports
import numpy as np
import matplotlib.pyplot as plt
import pysal
from pysal.contrib.gwr.gwr import GWR
from pysal.contrib.gwr.sel_bw import Sel_BW
from pysal.contrib.glm.family import Gaussian, Poisson, Binomial


#Load the GA data
data = pysal.open(pysal.examples.get_path('GData_utm.csv'))
y = np.array(data.by_col('PctBach')).reshape((-1,1))
fb  = np.array(data.by_col('PctFB')).reshape((-1,1))
pov = np.array(data.by_col('PctPov')).reshape((-1,1)) 
blk = np.array(data.by_col('PctBlack')).reshape((-1,1))
X = np.hstack([fb,pov,blk])
coords = list(zip(data.by_col('X'), data.by_col('Y')))

#Fit using each bandwidth
pysal_aicc_gau = []
pysal_aicc_bisq = []
for bw in range(20,160):
    results = GWR(coords, y, X, bw,fixed=False,kernel='gaussian',family=Gaussian()).fit()
    pysal_aicc_gau += [results.aicc]
    results = GWR(coords, y, X, bw,fixed=False,kernel='bisquare',family=Gaussian()).fit()
    pysal_aicc_bisq += [results.aicc]

#Plot
bw = range(20,160)
plt.figure(figsize=(12,8))
#plt.plot(bw,arc_aiccs,'r-',label="ArcGIS Adaptive 'Gaussian'") #Calculated from ArcGIS
plt.plot(bw,pysal_aicc_bisq,'b-',label='PySAL Adaptive Bisquare')
plt.plot(bw,pysal_aicc_gau,'y-',label='PySAL Adaptive Gaussian')
plt.xlabel('Bandwidth',fontsize=14)
plt.ylabel('AICc',fontsize=14)
plt.title('Georgia: Bach~ForeignBorn+Poverty+Black',fontsize=20)
plt.legend(fontsize=14)
plt.show()

ga

@Ziqi-Li
Copy link
Member Author

Ziqi-Li commented Feb 1, 2018

By default, the truncate parameter in adaptive_gauss from kernels.py is set to be False, while change that to True gives the following AICc curve. Also attached the kernel function lines. It is like after truncate point (beyond local neighbors), the gaussian still has pretty large weights.

def adapt_gauss(coords, nn, points=None, dmat=None,sorted_dmat=None):
    w = _Kernel(coords, fixed=False, k=nn-1, function='gwr_gaussian',
            truncate=**True**, points=points, dmat=dmat,sorted_dmat=sorted_dmat)
    return w.kernel

ga-after truncate
weight curve

@Ziqi-Li Ziqi-Li changed the title Strange behavior in adaptive gaussian Thoughts about adaptive gaussian Feb 1, 2018
@pysal pysal deleted a comment from ljwolf Feb 9, 2018
@pysal pysal deleted a comment from ljwolf Feb 9, 2018
@pysal pysal deleted a comment from Ziqi-Li Feb 9, 2018
@pysal pysal deleted a comment from ljwolf Feb 9, 2018
@pysal pysal deleted a comment from ljwolf Feb 9, 2018
@pysal pysal deleted a comment from ljwolf Feb 9, 2018
@pysal pysal deleted a comment from ljwolf Feb 9, 2018
@pysal pysal deleted a comment from Ziqi-Li Feb 9, 2018
@pysal pysal deleted a comment from ljwolf Feb 9, 2018
@pysal pysal deleted a comment from ASFotheringham Feb 9, 2018
@pysal pysal deleted a comment from ljwolf Feb 9, 2018
@TaylorOshan
Copy link
Collaborator

Closing this as the discussion was moved to a private repo.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants