This repository has been archived by the owner on Jul 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bc6a76e
Showing
28 changed files
with
4,114 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
language: python | ||
sudo: false | ||
branches: | ||
only: | ||
- master | ||
python: | ||
- "2.7" | ||
- "3.5" | ||
- "3.6" | ||
|
||
env: | ||
- PYSAL_PLUS=false | ||
- PYSAL_PLUS=true | ||
|
||
before_install: | ||
- wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh | ||
- chmod +x miniconda.sh | ||
- ./miniconda.sh -b -p ./miniconda | ||
- export PATH=`pwd`/miniconda/bin:$PATH | ||
- conda update --yes conda | ||
- conda config --add channels conda-forge | ||
- conda create -y -q -n test-env python=$TRAVIS_PYTHON_VERSION | ||
- source activate test-env | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; | ||
then 2to3 -nw gwr > /dev/null; | ||
fi | ||
|
||
install: | ||
- conda install --yes pip | ||
- conda install --yes --file requirements.txt; | ||
- conda install --yes nose | ||
- pip install libpysal | ||
- cd ../ && git clone https://github.com/TaylorOshan/spglm.git | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; | ||
then 2to3 -nw spglm/ > /dev/null; | ||
fi | ||
- pip install -e ./spglm | ||
- cd ./gwr | ||
- pip install -r requirements_dev.txt | ||
|
||
script: | ||
- python setup.py sdist >/dev/null | ||
- nosetests --with-coverage --cover-package=gwr; | ||
|
||
notifications: | ||
email: | ||
recipients: | ||
- [email protected] | ||
on_change: always | ||
on_failure: always | ||
|
||
after_success: | ||
- coveralls |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
BSD 2-Clause License | ||
|
||
Copyright (c) 2017, pysal | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
**G**eographically **W**eighted **R**egression | ||
======================================= | ||
|
||
Description goes here | ||
|
||
Features | ||
-------- | ||
|
||
- Feature 1 | ||
- Feature 2 | ||
- Feature 3 | ||
|
||
Future Work | ||
----------- | ||
|
||
- Future work 1 | ||
- Future work 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from . import gwr | ||
from . import sel_bw | ||
from . import diagnostics | ||
from . import kernels |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
""" | ||
Diagnostics for estimated gwr models | ||
""" | ||
__author__ = "Taylor Oshan [email protected]" | ||
|
||
import numpy as np | ||
from spglm.family import Gaussian, Poisson, Binomial | ||
|
||
def get_AICc(gwr): | ||
""" | ||
Get AICc value | ||
Gaussian: p61, (2.33), Fotheringham, Brunsdon and Charlton (2002) | ||
GWGLM: AICc=AIC+2k(k+1)/(n-k-1), Nakaya et al. (2005): p2704, (36) | ||
""" | ||
n = gwr.n | ||
k = gwr.tr_S | ||
if isinstance(gwr.family, Gaussian): | ||
aicc = -2.0*gwr.llf + 2.0*n*(k + 1.0)/(n-k-2.0) | ||
elif isinstance(gwr.family, (Poisson, Binomial)): | ||
aicc = get_AIC(gwr) + 2.0 * k * (k+1.0) / (n - k - 1.0) | ||
return aicc | ||
|
||
def get_AIC(gwr): | ||
""" | ||
Get AIC calue | ||
Gaussian: p96, (4.22), Fotheringham, Brunsdon and Charlton (2002) | ||
GWGLM: AIC(G)=D(G) + 2K(G), where D and K denote the deviance and the effective | ||
number of parameters in the model with bandwidth G, respectively. | ||
""" | ||
k = gwr.tr_S | ||
#deviance = -2*log-likelihood | ||
y = gwr.y | ||
mu = gwr.mu | ||
if isinstance(gwr.family, Gaussian): | ||
aic = -2.0 * gwr.llf + 2.0 * (k+1) | ||
elif isinstance(gwr.family, (Poisson, Binomial)): | ||
aic = np.sum(gwr.family.resid_dev(y, mu)**2) + 2.0 * k | ||
return aic | ||
|
||
def get_BIC(gwr): | ||
""" | ||
Get BIC value | ||
Gaussian: p61 (2.34), Fotheringham, Brunsdon and Charlton (2002) | ||
BIC = -2log(L)+klog(n) | ||
GWGLM: BIC = dev + tr_S * log(n) | ||
""" | ||
n = gwr.n # (scalar) number of observations | ||
k = gwr.tr_S | ||
y = gwr.y | ||
mu = gwr.mu | ||
if isinstance(gwr.family, Gaussian): | ||
bic = -2.0 * gwr.llf + (k+1) * np.log(n) | ||
elif isinstance(gwr.family, (Poisson, Binomial)): | ||
bic = np.sum(gwr.family.resid_dev(y, mu)**2) + k * np.log(n) | ||
return bic | ||
|
||
def get_CV(gwr): | ||
""" | ||
Get CV value | ||
Gaussian only | ||
Methods: p60, (2.31) or p212 (9.4) | ||
Fotheringham, A. S., Brunsdon, C., & Charlton, M. (2002). | ||
Geographically weighted regression: the analysis of spatially varying relationships. | ||
Modification: sum of residual squared is divided by n according to GWR4 results | ||
""" | ||
aa = gwr.resid_response.reshape((-1,1))/(1.0-gwr.influ) | ||
cv = np.sum(aa**2)/gwr.n | ||
return cv | ||
|
Binary file not shown.
Oops, something went wrong.