當前位置: 首頁>>代碼示例>>Python>>正文


Python Source.Y方法代碼示例

本文整理匯總了Python中source.Source.Y方法的典型用法代碼示例。如果您正苦於以下問題:Python Source.Y方法的具體用法?Python Source.Y怎麽用?Python Source.Y使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在source.Source的用法示例。


在下文中一共展示了Source.Y方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sample

# 需要導入模塊: from source import Source [as 別名]
# 或者: from source.Source import Y [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 Y [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.Y方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。