当前位置: 首页>>代码示例>>Python>>正文


Python Source.X方法代码示例

本文整理汇总了Python中source.Source.X方法的典型用法代码示例。如果您正苦于以下问题:Python Source.X方法的具体用法?Python Source.X怎么用?Python Source.X使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在source.Source的用法示例。


在下文中一共展示了Source.X方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sample

# 需要导入模块: from source import Source [as 别名]
# 或者: from source.Source import X [as 别名]
    def sample(self):

        """
        Method to pick the sample satisfying the likelihood constraint using uniform sampling

        Returns
        -------
        new : object
            The evolved sample
        number : int
            Number of likelihood calculations after sampling

        """

        new = Source()

        x_l, x_u = self.getPrior_X()
        y_l, y_u = self.getPrior_Y()
        r_l, r_u = self.getPrior_R()
        a_l, a_u = self.getPrior_A()

        while(True):

            new.X = np.random.uniform(x_l,x_u)
            new.Y = np.random.uniform(y_l,y_u)
            new.A = np.random.uniform(a_l,a_u)
            new.R = np.random.uniform(r_l,r_u)
            new.logL = self.log_likelihood(new)
            self.number+=1

            if(new.logL > self.LC):
                break

        return new, self.number
开发者ID:ProfessorBrunner,项目名称:bayes-detect,代码行数:36,代码来源:uniform.py

示例2: sample

# 需要导入模块: from source import Source [as 别名]
# 或者: from source.Source import X [as 别名]
    def sample(self):

        """
        Method to pick the sample satisfying the likelihood constraint using metropolis sampling

        Returns
        -------
        metro : object
            The evolved sample
        number : int
            Number of likelihood calculations until now

        """

        metro = Source()
        metro.__dict__ = self.source.__dict__.copy()
        start = Source()
        start.__dict__ = self.source.__dict__.copy()
        new   = Source()
        self.number+=1
        count = 0
        hit = 0
        miss = 0

        x_l, x_u = self.getPrior_X()
        y_l, y_u = self.getPrior_Y()
        r_l, r_u = self.getPrior_R()
        a_l, a_u = self.getPrior_A()

        stepnormalize = self.step/x_u

        stepX    = self.step
        stepY    = stepnormalize*(y_u-y_l)
        stepA    = stepnormalize*(a_u - a_l)
        stepR    = stepnormalize*(r_u-r_l)

        bord = 1

        while(count<20):

            while bord==1:
                bord = 0
                new.X    = metro.X + stepX * (2.*np.random.uniform(0, 1) - 1.);
                new.Y    = metro.Y + stepY * (2.*np.random.uniform(0, 1) - 1.);
                new.A    = metro.A + stepA * (2.*np.random.uniform(0, 1) - 1.);
                new.R    = metro.R + stepR * (2.*np.random.uniform(0, 1) - 1.);



                if(new.X > x_u or new.X < x_l): bord = 1;
                if(new.Y > y_u or new.Y < y_l): bord = 1;
                if(new.A > a_u or new.A < a_l): bord = 1;
                if(new.R > r_u or new.R < r_l): bord = 1;

            new.logL = self.log_likelihood(new)
            self.number+=1

            if(new.logL > self.LC):
                metro.__dict__ = new.__dict__.copy()
                hit+=1
            else:
                miss+=1

            if( hit > miss ):   self.step *= exp(1.0 / hit);
            if( hit < miss ):   self.step /= exp(1.0 / miss);

            stepnormalize = self.step/x_u

            stepX    = self.step
            stepY    = stepnormalize*(y_u-y_l)
            stepA    = stepnormalize*(a_u - a_l)
            stepR    = stepnormalize*(r_u-r_l)


            count+=1
            bord=1

        return metro, self.number
开发者ID:ProfessorBrunner,项目名称:bayes-detect,代码行数:80,代码来源:mh.py


注:本文中的source.Source.X方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。