本文整理汇总了Python中source.Source.logL方法的典型用法代码示例。如果您正苦于以下问题:Python Source.logL方法的具体用法?Python Source.logL怎么用?Python Source.logL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类source.Source
的用法示例。
在下文中一共展示了Source.logL方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sample
# 需要导入模块: from source import Source [as 别名]
# 或者: from source.Source import logL [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
示例2: sample
# 需要导入模块: from source import Source [as 别名]
# 或者: from source.Source import logL [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