本文整理汇总了Python中pgmpy.models.BayesianModel.add_factors方法的典型用法代码示例。如果您正苦于以下问题:Python BayesianModel.add_factors方法的具体用法?Python BayesianModel.add_factors怎么用?Python BayesianModel.add_factors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmpy.models.BayesianModel
的用法示例。
在下文中一共展示了BayesianModel.add_factors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_model
# 需要导入模块: from pgmpy.models import BayesianModel [as 别名]
# 或者: from pgmpy.models.BayesianModel import add_factors [as 别名]
def get_model(self):
"""
Returns an instance of Bayesian Model or Markov Model.
Varibles are in the pattern var_0, var_1, var_2 where var_0 is
0th index variable, var_1 is 1st index variable.
Return
------
model: an instance of Bayesian or Markov Model.
Examples
--------
>>> reader = UAIReader('TestUAI.uai')
>>> reader.get_model()
"""
if self.network_type == 'BAYES':
model = BayesianModel(self.edges)
tabular_cpds = []
for cpd in self.tables:
child_var = cpd[0]
states = int(self.domain[child_var])
arr = list(map(float, cpd[1]))
values = np.array(arr)
values = values.reshape(states, values.size // states)
tabular_cpds.append(TabularCPD(child_var, states, values))
model.add_cpds(*tabular_cpds)
return model
elif self.network_type == 'MARKOV':
model = MarkovModel(self.edges)
factors = []
for table in self.tables:
variables = table[0]
cardinality = [int(self.domain[var]) for var in variables]
value = list(map(float, table[1]))
factor = DiscreteFactor(variables=variables, cardinality=cardinality, values=value)
factors.append(factor)
model.add_factors(*factors)
return model