-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from knaaptime/builddocs
use ax instead of plt
- Loading branch information
Showing
3 changed files
with
68 additions
and
46 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
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 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 |
---|---|---|
|
@@ -2,15 +2,20 @@ | |
|
||
__author__ = "Renan X. Cortes <[email protected]>, Sergio J. Rey <[email protected]> and Elijah Knaap <[email protected]>" | ||
|
||
import os | ||
|
||
import geopandas as gpd | ||
import numpy as np | ||
|
||
from .._base import SingleGroupIndex, SpatialImplicitIndex | ||
# must be set prior to importing numpy | ||
# <https://github.com/numba/numba/issues/5275> | ||
os.environ["KMP_WARNINGS"] = "off" | ||
|
||
import numpy as np | ||
|
||
from .._base import SingleGroupIndex, SpatialImplicitIndex | ||
|
||
try: | ||
from numba import njit, jit, prange, boolean | ||
from numba import boolean, jit, njit, prange | ||
except (ImportError, ModuleNotFoundError): | ||
|
||
def jit(*dec_args, **dec_kwargs): | ||
|
@@ -28,7 +33,11 @@ def intercepted_function(f, *f_args, **f_kwargs): | |
prange = range | ||
boolean = bool | ||
|
||
@njit(parallel=True, fastmath=True,) | ||
|
||
@njit( | ||
parallel=True, | ||
fastmath=True, | ||
) | ||
def _gini_vecp(pi: np.ndarray, ti: np.ndarray): | ||
"""Memory efficient calculation of Gini | ||
|
@@ -41,25 +50,23 @@ def _gini_vecp(pi: np.ndarray, ti: np.ndarray): | |
Returns | ||
---------- | ||
implicit: float | ||
Gini coefficient | ||
""" | ||
|
||
|
||
n = ti.shape[0] | ||
num = np.zeros(1) | ||
T = ti.sum() | ||
P = pi.sum() / T | ||
pi = np.where(ti == 0, 0, pi / ti) | ||
T = ti.sum() | ||
for i in prange(n-1): | ||
num += (ti[i] * ti[i+1:] * np.abs(pi[i] - pi[i+1:])).sum() | ||
for i in prange(n - 1): | ||
num += (ti[i] * ti[i + 1 :] * np.abs(pi[i] - pi[i + 1 :])).sum() | ||
num *= 2 | ||
den = (2 * T * T * P * (1-P)) | ||
den = 2 * T * T * P * (1 - P) | ||
return (num / den)[0] | ||
|
||
|
||
|
||
def _gini_seg(data, group_pop_var, total_pop_var): | ||
"""Calculate Gini segregation index. | ||
|
@@ -107,6 +114,7 @@ def _gini_seg(data, group_pop_var, total_pop_var): | |
|
||
return G, data | ||
|
||
|
||
class Gini(SingleGroupIndex, SpatialImplicitIndex): | ||
"""Gini Index. | ||
|
@@ -154,7 +162,7 @@ def __init__( | |
decay=None, | ||
function="triangular", | ||
precompute=None, | ||
**kwargs | ||
**kwargs, | ||
): | ||
"""Init.""" | ||
SingleGroupIndex.__init__(self, data, group_pop_var, total_pop_var) | ||
|