Skip to content

Commit

Permalink
added monotonized experimental variogram option
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaelicke committed Feb 1, 2018
1 parent 316cd71 commit 9a6006e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.6
0.1.7
47 changes: 46 additions & 1 deletion skgstat/Variogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Variogram(object):
def __init__(self, coordinates=None, values=None, dm_func=nd_dist, bm_func=binify_even_width,
estimator=matheron, model=spherical, dm=None, bm=None, normalize=True, fit_method='lm',
pec_punish=1.0, is_directional=False, azimuth=0, tolerance=45.0, use_nugget=False, maxlag=None,
N=None, verbose=False):
N=None, verbose=False, harmonize=False):
"""
:param coordinates: numpy array or list with the coordinates of the sample as tuples
Expand All @@ -56,6 +56,7 @@ def __init__(self, coordinates=None, values=None, dm_func=nd_dist, bm_func=binif
:param maxlag:
:param N: number of bins
:param verbose:
:param harmonize: bool, if True, the experimental variogram will be harmonized.
"""

# Set coordinates and values
Expand Down Expand Up @@ -93,6 +94,9 @@ def __init__(self, coordinates=None, values=None, dm_func=nd_dist, bm_func=binif
# specify if the lag should be given absolute or relative to the maxlag
self.normalized = normalize

# specify if the experimental variogram shall be harmonized
self.harmonize = harmonize

# set the fitting method and model quality measure
self.fit_method = fit_method
self.pec_punish = pec_punish
Expand Down Expand Up @@ -305,6 +309,20 @@ def maxlag(self, value):

@property
def experimental(self):
"""
Return the experimental variogram.
If :param harmonize: is True, it will return self.isotonic, instead of self.experimental.
:return: np.array, the isotonic or non-isotonic experimental varigram
"""
if self.harmonize:
return self.isotonic
else:
return self._experimental


@property
def _experimental(self):
"""
:return: experimental variogram as a numpy.ndarray.
"""
Expand All @@ -314,6 +332,33 @@ def experimental(self):
# apply
return np.array(self._estimator(_g))

@property
def isotonic(self):
"""
Return the isotonic harmonized experimental variogram.
This means, the experimental variogram is monotonic after harmonization.
The harmonization is done using PAVA algorithm:
Barlow, R., D. Bartholomew, et al. (1972): Statistical Interference Under Order Restrictions.
John Wiley and Sons, New York.
Hiterding, A. (2003): Entwicklung hybrider Interpolationsverfahren für den automatisierten Betrieb am
Beispiel meteorologischer Größen. Dissertation, Institut für Geoinformatik, Westphälische
Wilhelms-Universität Münster, IfGIprints, Münster. ISBN: 3-936616-12-4
TODO: solve the import
:return: np.ndarray, monotonized experimental variogram
"""
# TODO this is imported in the function as sklearn is not a dependency (and should not be for now)
try:
from sklearn.isotonic import IsotonicRegression
y = self._experimental
x = self.bins
return IsotonicRegression().fit_transform(x,y)
except ImportError:
raise NotImplementedError('scikit-learn is not installed, but the isotonic function without sklear dependency is not installed yet.')

@property
def grouped_pairs(self):
"""
Expand Down

0 comments on commit 9a6006e

Please sign in to comment.