本文整理汇总了Python中libpgm.nodedata.NodeData.load方法的典型用法代码示例。如果您正苦于以下问题:Python NodeData.load方法的具体用法?Python NodeData.load怎么用?Python NodeData.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libpgm.nodedata.NodeData
的用法示例。
在下文中一共展示了NodeData.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def setUp(self):
skel = GraphSkeleton()
skel.load("unittestdict.txt")
skel.toporder()
nodedata = NodeData()
nodedata.load("unittestdict.txt")
self.instance = DiscreteBayesianNetwork(skel, nodedata)
示例2: TestNodeData
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
class TestNodeData(unittest.TestCase):
def setUp(self):
self.nd = NodeData()
def test_entriestoinstances(self):
self.nd.load("unittesthdict.txt")
self.nd.entriestoinstances()
result = self.nd.nodes["Intelligence"].choose([])
self.assertTrue(result == 'low' or result == 'high')
示例3: getTableCPD
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def getTableCPD():
nd = NodeData()
skel = GraphSkeleton()
jsonpath = "job_interview.txt"
nd.load(jsonpath)
skel.load(jsonpath)
#load bayesian network
bn = DiscreteBayesianNetwork(skel, nd)
tablecpd = TableCPDFactorization(bn)
return tablecpd
示例4: test_query
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def test_query(self):
teacher_nd = NodeData()
teacher_nd.load(self.teacher_data_path)
req = DiscreteQueryRequest()
req.nodes = U.discrete_nodes_to_ros(teacher_nd.Vdata)
req.evidence = [DiscreteNodeState("Letter", "weak")]
req.query = ["Grade"]
res = self.query(req)
self.assertEqual(len(res.nodes), 1)
n = res.nodes[0]
self.assertEqual(n.name, "Grade")
self.assertListEqual(['A','B','C'], n.outcomes)
示例5: load
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def load(self, file_name):
#### Load BN
nd = NodeData()
skel = GraphSkeleton()
nd.load(file_name) # any input file
skel.load(file_name)
# topologically order graphskeleton
skel.toporder()
super(DiscreteBayesianNetworkExt, self).__init__(skel, nd)
##TODO load evidence
示例6: TestDynDiscBayesianNetwork
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
class TestDynDiscBayesianNetwork(unittest.TestCase):
def setUp(self):
self.nd = NodeData()
self.nd.load("unittestdyndict.txt")
self.skel = GraphSkeleton()
self.skel.load("unittestdyndict.txt")
self.skel.toporder()
self.d = DynDiscBayesianNetwork(self.skel, self.nd)
def test_randomsample(self):
sample = self.d.randomsample(10)
for i in range(1, 10):
self.assertEqual(sample[0]['Difficulty'], sample[i]['Difficulty'])
示例7: createData
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def createData():
nd = NodeData()
skel = GraphSkeleton()
fpath = "job_interview.txt"
nd.load(fpath)
skel.load(fpath)
skel.toporder()
bn = DiscreteBayesianNetwork(skel, nd)
learner = PGMLearner()
data = bn.randomsample(1000)
X, Y = 'Grades', 'Offer'
c,p,w=learner.discrete_condind(data, X, Y, ['Interview'])
print "independence between X and Y: ", c, " p-value ", p, " witness node: ", w
result = learner.discrete_constraint_estimatestruct(data)
print result.E
示例8: TestHyBayesianNetwork
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
class TestHyBayesianNetwork(unittest.TestCase):
def setUp(self):
self.nd = NodeData()
self.nd.load("unittesthdict.txt")
self.nd.entriestoinstances()
self.skel = GraphSkeleton()
self.skel.load("unittestdict.txt")
self.skel.toporder()
self.hybn = HyBayesianNetwork(self.skel, self.nd)
def test_randomsample(self):
sample = self.hybn.randomsample(1)[0]
self.assertTrue(isinstance(sample['Grade'], float))
self.assertTrue(isinstance(sample['Intelligence'], str))
self.assertEqual(sample["SAT"][-12:], 'blueberries!')
示例9: net2
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def net2():
nd = NodeData()
skel = GraphSkeleton()
nd.load("net.txt") # an input file
skel.load("net.txt")
# topologically order graphskeleton
skel.toporder()
# load bayesian network
lgbn = LGBayesianNetwork(skel, nd)
in_data=read_data.getdata2()
learner = PGMLearner()
bn=learner.lg_mle_estimateparams(skel,in_data)
p=cal_prob(in_data[300:500],bn)
print p
return 0
示例10: setUp
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def setUp(self):
# instantiate learner
self.l = PGMLearner()
# generate graph skeleton
skel = GraphSkeleton()
skel.load("unittestdict.txt")
skel.toporder()
# generate sample sequence to try to learn from - discrete
nd = NodeData.load("unittestdict.txt")
self.samplediscbn = DiscreteBayesianNetwork(nd)
self.samplediscseq = self.samplediscbn.randomsample(5000)
# generate sample sequence to try to learn from - discrete
nda = NodeData.load("unittestlgdict.txt")
self.samplelgbn = LGBayesianNetwork(nda)
self.samplelgseq = self.samplelgbn.randomsample(10000)
self.skel = skel
示例11: test_structure_estimation
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def test_structure_estimation(self):
req = DiscreteStructureEstimationRequest()
skel = GraphSkeleton()
skel.load(self.data_path)
skel.toporder()
teacher_nd = NodeData()
teacher_nd.load(self.teacher_data_path)
bn = DiscreteBayesianNetwork(skel, teacher_nd)
data = bn.randomsample(8000)
for v in data:
gs = DiscreteGraphState()
for k_s, v_s in v.items():
gs.node_states.append(DiscreteNodeState(node=k_s, state=v_s))
req.states.append(gs)
res = self.struct_estimate(req)
self.assertIsNotNone(res.graph)
self.assertEqual(len(res.graph.nodes), 5)
self.assertGreater(len(res.graph.edges), 0)
示例12: test_param_estimation
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def test_param_estimation(self):
req = DiscreteParameterEstimationRequest()
# load graph structure
skel = GraphSkeleton()
skel.load(self.data_path)
req.graph.nodes = skel.V
req.graph.edges = [GraphEdge(k, v) for k,v in skel.E]
skel.toporder()
# generate trial data
teacher_nd = NodeData()
teacher_nd.load(self.teacher_data_path)
bn = DiscreteBayesianNetwork(skel, teacher_nd)
data = bn.randomsample(200)
for v in data:
gs = DiscreteGraphState()
for k_s, v_s in v.items():
gs.node_states.append(DiscreteNodeState(node=k_s, state=v_s))
req.states.append(gs)
self.assertEqual(len(self.param_estimate(req).nodes), 5)
示例13: main
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
def main():
in_data=read_data.getdata()
f_data=format_data(in_data)
nd = NodeData()
nd.load("net4.txt") # an input file
skel = GraphSkeleton()
skel.load("net4.txt")
skel.toporder()
bn=DiscreteBayesianNetwork(skel,nd)
#training dataset:70%
bn2=em(f_data[1:6000],bn,skel)
pr_training = precision(f_data[1:6000],bn2)
print "Prediction accuracy for training data:" , pr_training[1]
#testing dataset:30%
pr=precision(f_data[6700:6800],bn2)
print "Prediction accuracy for test data:", pr[1]
示例14: NodeData
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
import json
from libpgm.nodedata import NodeData
from libpgm.graphskeleton import GraphSkeleton
from libpgm.discretebayesiannetwork import DiscreteBayesianNetwork
from libpgm.pgmlearner import PGMLearner
# generate some data to use
nd = NodeData()
nd.load("grades.txt") # an input file
skel = GraphSkeleton()
skel.load("grades.txt")
skel.toporder()
bn = DiscreteBayesianNetwork(skel, nd)
data = bn.randomsample(80000)
# instantiate my learner
learner = PGMLearner()
# estimate structure
result = learner.discrete_constraint_estimatestruct(data)
# output
print json.dumps(result.E, indent=2)
示例15: NodeData
# 需要导入模块: from libpgm.nodedata import NodeData [as 别名]
# 或者: from libpgm.nodedata.NodeData import load [as 别名]
import json
from libpgm.nodedata import NodeData
from libpgm.graphskeleton import GraphSkeleton
from libpgm.lgbayesiannetwork import LGBayesianNetwork
from libpgm.pgmlearner import PGMLearner
# generate some data to use
nd = NodeData()
nd.load("gaussGrades.txt") # an input file
skel = GraphSkeleton()
skel.load("gaussGrades.txt")
skel.toporder()
lgbn = LGBayesianNetwork(skel, nd)
data = lgbn.randomsample(8000)
print data
# instantiate my learner
learner = PGMLearner()
# estimate structure
result = learner.lg_constraint_estimatestruct(data)
# output
print json.dumps(result.E, indent=2)