Skip to content

Commit

Permalink
Merge pull request #185 from mmaelicke/fix-nan-error
Browse files Browse the repository at this point in the history
fix np.NaN usages
  • Loading branch information
mmaelicke authored Jun 26, 2024
2 parents 22ff51c + eed56c3 commit 6c8ec5e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
16 changes: 9 additions & 7 deletions skgstat/MetricSpace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import multiprocessing as mp


def _sparse_dok_get(m, fill_value=np.NaN):
def _sparse_dok_get(m, fill_value=np.nan):
"""Like m.toarray(), but setting empty values to `fill_value`, by
default `np.NaN`, rather than 0.0.
default `np.nan`, rather than 0.0.
Parameters
----------
Expand Down Expand Up @@ -777,14 +777,16 @@ def dists(self):
# from https://stackoverflow.com/questions/28677162/ignoring-duplicate-entries-in-sparse-matrix

# Stable solution but a bit slow
# c, eq, d = zip(*set(zip(c, eq, d)))
# dists = sparse.csr_matrix((d, (c, eq)), shape=(len(self.coords), len(self.coords)))
c, eq, d = zip(*set(zip(c, eq, d)))
dists = sparse.csr_matrix((d, (c, eq)), shape=(len(self.coords), len(self.coords)))

# comment mmaelicke: We need to fall back to the slower solution as dok._update is not supported in scipy 1.0 anymore
#
# Solution 5+ times faster than the preceding, but relies on _update() which might change in scipy (which
# only has an implemented method for summing duplicates, and not ignoring them yet)
dok = sparse.dok_matrix((len(self.coords), len(self.coords)))
dok._update(zip(zip(c, eq), d))
dists = dok.tocsr()
# dok = sparse.dok_matrix((len(self.coords), len(self.coords)))
# dok._update(zip(zip(c, eq), d))
# dists = dok.tocsr()

self._dists = dists

Expand Down
6 changes: 3 additions & 3 deletions skgstat/Variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -3164,9 +3164,9 @@ def __str__(self): # pragma: no cover
"""
par = self.describe()

_sill = np.NaN if 'error' in par else par['sill']
_range = np.NaN if 'error' in par else par['effective_range']
_nugget = np.NaN if 'error' in par else par['nugget']
_sill = np.nan if 'error' in par else par['sill']
_range = np.nan if 'error' in par else par['effective_range']
_nugget = np.nan if 'error' in par else par['nugget']

s = "{0} Variogram\n".format(par['model'])
s += "-" * (len(s) - 1) + "\n"
Expand Down
12 changes: 6 additions & 6 deletions skgstat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def spherical(h, r, c0, b=0.0):
The effective range. Note this is not the range parameter! However,
for the spherical variogram the range and effective range are the same.
c0 : float
The sill of the variogram, where it will flatten out. The function
The partial sill of the variogram, where it will flatten out. The function
will not return a value higher than C0 + b.
b : float
The nugget of the variogram. This is the value of independent
Expand Down Expand Up @@ -102,7 +102,7 @@ def exponential(h, r, c0, b=0.0):
sill are exceeded. This is needed as the sill is only approached
asymptotically by an exponential function.
c0 : float
The sill of the variogram, where it will flatten out. The function
The partial sill of the variogram, where it will flatten out. The function
will not return a value higher than C0 + b.
b : float
The nugget of the variogram. This is the value of independent
Expand Down Expand Up @@ -164,7 +164,7 @@ def gaussian(h, r, c0, b=0.0):
sill are exceeded. This is needed as the sill is only approached
asymptotically by an exponential function.
c0 : float
The sill of the variogram, where it will flatten out. The function
The partial sill of the variogram, where it will flatten out. The function
will not return a value higher than C0 + b.
b : float
The nugget of the variogram. This is the value of independent
Expand Down Expand Up @@ -226,7 +226,7 @@ def cubic(h, r, c0, b=0.0):
The effective range. Note this is not the range parameter! However,
for the cubic variogram the range and effective range are the same.
c0 : float
The sill of the variogram, where it will flatten out. The function
The partial sill of the variogram, where it will flatten out. The function
will not return a value higher than C0 + b.
b : float
The nugget of the variogram. This is the value of independent
Expand Down Expand Up @@ -297,7 +297,7 @@ def stable(h, r, c0, s, b=0.0):
only approached asymptotically by the e-function part of the stable
model.
c0 : float
The sill of the variogram, where it will flatten out. The function
The partial sill of the variogram, where it will flatten out. The function
will not return a value higher than C0 + b.
s : float
Shape parameter. For s <= 2 the model will be shaped more like a
Expand Down Expand Up @@ -369,7 +369,7 @@ def matern(h, r, c0, s, b=0.0):
where 95% of the sill are exceeded. This is needed as the sill is
only approached asymptotically by Matérn model.
c0 : float
The sill of the variogram, where it will flatten out. The function
The partial sill of the variogram, where it will flatten out. The function
will not return a value higher than C0 + b.
s : float
Smoothness parameter. The smoothness parameter can shape a smooth or
Expand Down
2 changes: 1 addition & 1 deletion skgstat/tests/test_variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ def test_harmonize_model(self):

assert_array_almost_equal(
V.transform(x),
[np.NaN, 0.57, 1.01, 1.12, 1.15, 1.15, 1.15, 1.15, 1.21, 1.65],
[np.nan, 0.57, 1.01, 1.12, 1.15, 1.15, 1.15, 1.15, 1.21, 1.65],
decimal=2
)

Expand Down

0 comments on commit 6c8ec5e

Please sign in to comment.