spatial_analysis.py 文件源码

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

项目:Waskom_PNAS_2017 作者: WagnerLabPapers 项目源码 文件源码
def prediction_curve(dmat, vals, steps, radius):
    """Return MSE from predicting values from neighbors at radial steps."""
    # Set null distances (greater than some threshold) to 0.
    # Not in general a great idea, but fine here because we don't
    # do anything with identity edges, and sums will be faster
    # if we don't have to worry about nans
    dmat = np.nan_to_num(dmat)

    error_vals = []
    for step in steps:
        neighbors = (np.abs(dmat - step) < radius).astype(np.float)
        neighbors /= neighbors.sum(axis=1, keepdims=True)
        predicted = neighbors.dot(vals)
        m = ~np.isnan(predicted)
        error_vals.append(mean_squared_error(vals[m], predicted[m]))
    return np.array(error_vals)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号