detector.py 文件源码

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

项目:pymchelper 作者: DataMedSci 项目源码 文件源码
def average_with_nan(detector_list, error_estimate=ErrorEstimate.stderr):
    """
    Calculate average detector object, excluding malformed data (NaN) from averaging.
    :param detector_list:
    :param error_estimate:
    :return:
    """
    # TODO add compatibility check
    result = Detector()
    result.counter = len(detector_list)
    result.data_raw = np.nanmean([det.data_raw for det in detector_list], axis=0)
    if result.counter > 1 and error_estimate != ErrorEstimate.none:
        # s = stddev = sqrt(1/(n-1)sum(x-<x>)**2)
        # s : corrected sample standard deviation
        result.error_raw = np.nanstd([det.data_raw for det in detector_list], axis=0, ddof=1)

        # if user requested standard error then we calculate it as:
        # S = stderr = stddev / sqrt(n), or in other words,
        # S = s/sqrt(N) where S is the corrected standard deviation of the mean.
        if error_estimate == ErrorEstimate.stderr:
            result.error_raw /= np.sqrt(result.counter)  # np.sqrt() always returns np.float64
    else:
        result.error_raw = np.zeros_like(result.data_raw)
    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号