normal_score_transform.py 文件源码

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

项目:pyGeoStatistics 作者: whimian 项目源码 文件源码
def back_transform(self, scores):
        "transform nore score back to orginal data"
        values = np.full_like(scores, np.nan)

        lo_value = self.transform_table['value'][0]
        up_value = self.transform_table['value'][-1]
        lo_score = self.transform_table['score'][0]
        up_score = self.transform_table['score'][-1]
        # scores in normal range
        normal_mask = np.logical_and(scores <= up_score, scores >= lo_score)
        normal_scores = scores[normal_mask]
        values[normal_mask] = self.back_func(normal_scores)
        # scores in lower tail: 1=linear, 2=power
        lower_mask = scores < lo_score
        lower_scores = scores[lower_mask]
        temp = list()
        for sc in lower_scores:
            backtr = lo_value
            cdflo = gcum(lo_score)
            cdfbt = gcum(sc)
            if self.ltail == 1:  # linear
                backtr = powint(0, cdflo, self.zmin, lo_value, cdfbt, 1)
                temp.append(backtr)
            elif self.ltail == 2:  # power
                cpow = 1.0 / self.ltpar
                backtr = powint(0, cdflo, self.zmin, lo_value, cdfbt, cpow)
                temp.append(backtr)
        values[lower_mask] = temp
        # scores in upper tail: 1=linear, 2=power, 4=hyperbolic
        upper_mask = scores > up_score
        upper_scores = scores[upper_mask]
        temp = list()
        for sc in up_score:
            backtr = up_value
            cdfhi = gcum(up_score)
            cdfbt = gcum(sc)  # cdf value of the score to be back-transformed
            if self.utail == 1:  # linear
                backtr = powint(cdfhi, 1.0, up_value, self.zmax, cdfbt, 1)
                temp.append(backtr)
            elif self.utail == 2:  # power
                cpow = 1.0 / self.utpar
                backtr = powint(cdfhi, 1.0, up_value, self.zmax, cdfbt, cpow)
                temp.append(backtr)
            elif self.utail == 4:  # hyperbolic
                l = (up_value**self.utpar) * (1 - gcum(up_score))
                backtr = (l / (1 - gcum(sc)))**(1 / self.utpar)
                temp.append(backtr)
        values[upper_mask] = temp
        return values
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号