estimator.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:scikit-gstat 作者: mmaelicke 项目源码 文件源码
def genton(X):
    """
    Return the Genton Variogram of the given sample X.
    X has to be an even-length array of point pairs like: x1, x1+h, x2, x2+h ...., xn, xn + h.
    If X.ndim > 1, genton will be called recursively and a list of Cressie-Hawkins Variances is returned.

    Genton, M. G., (1998): Highly robust variogram estimation, Math. Geol., 30, 213 - 221.

    :param X:
    :return:
    """
    _X = np.array(X)

    if any([isinstance(_, list) or isinstance(_, np.ndarray) for _ in _X]):
        return np.array([genton(_) for _ in _X])

    # check even
    if len(_X) % 2 > 0:
        raise ValueError('The sample does not have an even length: {}'.format(_X))

    # calculate
    try:
        y = [np.abs( (_X[i] - _X[i + 1]) - (_X[j]) - _X[j + 1] ) for i in np.arange(0, len(_X), 2) for j in np.arange(0, len(_X), 2) if i < j]

        # get k  k is binom(N(x)/2+1, 2)
        k = binom(int(len(_X) / 2 + 1), 2)

        # return the kth percentile
        return 0.5 * np.power(2.219 * np.percentile(y, k), 2)
    except ZeroDivisionError:
        return np.nan
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号