本文整理汇总了Python中message.Message.add_potential方法的典型用法代码示例。如果您正苦于以下问题:Python Message.add_potential方法的具体用法?Python Message.add_potential怎么用?Python Message.add_potential使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类message.Message
的用法示例。
在下文中一共展示了Message.add_potential方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: predict
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import add_potential [as 别名]
def predict(self, alpha):
m = Message()
# add change component
m.add_potential(Potential(self.prior.alpha, self.prior.a, self.prior.b, self.log_p1 + alpha.log_likelihood()))
# add no-change components
for p in alpha.potentials:
m.add_potential(Potential(p.alpha, p.a, p.b, p.log_c + self.log_p0))
return m
示例2: forward
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import add_potential [as 别名]
def forward(self, obs):
alpha = []
alpha_predict = []
for i in range(obs.shape[0]):
if i == 0:
m = Message()
m.add_potential(Potential(self.prior.alpha, self.prior.a, self.prior.b, self.log_p1))
m.add_potential(Potential(self.prior.alpha, self.prior.a, self.prior.b, self.log_p0))
alpha_predict.append(m)
else:
alpha_predict.append(self.predict(alpha[-1]))
alpha.append(self.update(alpha_predict[-1], obs[i, :]))
return [alpha_predict, alpha]
示例3: backward
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import add_potential [as 别名]
def backward(self, obs, start=0, length=0):
if length == 0:
length = obs.shape[0]
start = length-1
beta = []
for i in range(start, start - length, -1):
message = Message()
# change
p_obs = Potential.from_observation(obs[i, :], self.m, self.n)
pot_change = p_obs.copy()
if len(beta) > 0:
temp = Message()
for p in beta[-1].potentials:
temp.add_potential(p * self.prior)
pot_change.log_c += self.log_p1 + temp.log_likelihood()
message.add_potential(pot_change)
# no change
if len(beta) > 0:
for p in beta[-1].potentials:
p2 = p * p_obs
p2.log_c += self.log_p0
message.add_potential(p2)
beta.append(message)
beta.reverse()
return beta
示例4: update
# 需要导入模块: from message import Message [as 别名]
# 或者: from message.Message import add_potential [as 别名]
def update(self, predict, obs):
m = Message()
p_obs = Potential.from_observation(obs, self.m, self.n)
for p in predict.potentials:
m.add_potential(p * p_obs)
return m