本文整理汇总了Python中libpgm.graphskeleton.GraphSkeleton类的典型用法代码示例。如果您正苦于以下问题:Python GraphSkeleton类的具体用法?Python GraphSkeleton怎么用?Python GraphSkeleton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphSkeleton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
skel = GraphSkeleton()
skel.load("unittestdict.txt")
skel.toporder()
nodedata = NodeData()
nodedata.load("unittestdict.txt")
self.instance = DiscreteBayesianNetwork(skel, nodedata)
示例2: setUp
def setUp(self):
nodedata = NodeData.load("unittestlgdict.txt")
skel = GraphSkeleton()
skel.load("unittestdict.txt")
skel.toporder()
self.lgb = LGBayesianNetwork(nodedata)
示例3: graph_skeleton_from_node_data
def graph_skeleton_from_node_data(nd):
skel = GraphSkeleton()
skel.V = []
skel.E = []
for name, v in nd.Vdata.items():
skel.V += [name]
skel.E += [[name, c] for c in v["children"]]
return skel
示例4: test_hybn_mte_estimateparams
def test_hybn_mte_estimateparams(self):
skel = GraphSkeleton()
skel.load("../tests/bn_skeleton.txt")
skel.toporder()
with open('../tests/dataBR2.json', 'r') as f:
samples = eval(f.read())
result = self.l.hybn_mte_estimateparams(self.skel, self.samplelgseq)
示例5: q_without_ros
def q_without_ros():
skel = GraphSkeleton()
skel.V = ["prize_door", "guest_door", "monty_door"]
skel.E = [["prize_door", "monty_door"],
["guest_door", "monty_door"]]
skel.toporder()
nd = NodeData()
nd.Vdata = {
"prize_door": {
"numoutcomes": 3,
"parents": None,
"children": ["monty_door"],
"vals": ["A", "B", "C"],
"cprob": [1.0/3, 1.0/3, 1.0/3],
},
"guest_door": {
"numoutcomes": 3,
"parents": None,
"children": ["monty_door"],
"vals": ["A", "B", "C"],
"cprob": [1.0/3, 1.0/3, 1.0/3],
},
"monty_door": {
"numoutcomes": 3,
"parents": ["prize_door", "guest_door"],
"children": None,
"vals": ["A", "B", "C"],
"cprob": {
"['A', 'A']": [0., 0.5, 0.5],
"['B', 'B']": [0.5, 0., 0.5],
"['C', 'C']": [0.5, 0.5, 0.],
"['A', 'B']": [0., 0., 1.],
"['A', 'C']": [0., 1., 0.],
"['B', 'A']": [0., 0., 1.],
"['B', 'C']": [1., 0., 0.],
"['C', 'A']": [0., 1., 0.],
"['C', 'B']": [1., 0., 0.],
},
},
}
bn = DiscreteBayesianNetwork(skel, nd)
fn = TableCPDFactorization(bn)
query = {
"prize_door": ["A","B","C"],
}
evidence = {
"guest_door": "A",
"monty_door": "B",
}
res = fn.condprobve(query, evidence)
print res.vals
print res.scope
print res.card
print res.stride
示例6: getTableCPD
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
示例7: TestOrderedSkeleton
class TestOrderedSkeleton(unittest.TestCase):
def setUp(self):
self.os = OrderedSkeleton()
self.os.load("unittestdict.txt")
self.gs = GraphSkeleton()
self.gs.load("unittestdict.txt")
def test_constructor(self):
self.assertNotEqual(self.os.V, self.gs.V)
self.gs.toporder()
self.assertEqual(self.os.V, self.gs.V)
示例8: load
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
示例9: TestDynDiscBayesianNetwork
class TestDynDiscBayesianNetwork(unittest.TestCase):
def setUp(self):
self.nd = NodeData.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'])
示例10: TestHyBayesianNetwork
class TestHyBayesianNetwork(unittest.TestCase):
def setUp(self):
self.nd = HybridNodeData.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!')
示例11: add_sensor
def add_sensor(self, sensor_keys):
for key in sensor_keys:
network_file = open(self.dbn_file_name, 'r')
network_file_data = eval(network_file.read())
network_skeleton = GraphSkeleton()
network_skeleton.V = network_file_data["V"]
network_skeleton.E = network_file_data["E"]
self.network = DynDiscBayesianNetwork()
self.network.V = network_skeleton.V
self.network.E = network_skeleton.E
self.network.initial_Vdata = network_file_data["initial_Vdata"]
self.network.twotbn_Vdata = network_file_data["twotbn_Vdata"]
self.inference_engines[key] = SensorDbnInferenceEngine(self.network)
示例12: createData
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
示例13: TestGraphSkeleton
class TestGraphSkeleton(unittest.TestCase):
def setUp(self):
self.instance = GraphSkeleton()
self.instance.V = [1,2,3,4,5]
self.instance.E = [[5,1],[1,2]]
def test_getparents(self):
self.assertEqual(self.instance.getparents(1), [5])
self.assertEqual(self.instance.getparents(4), [])
def test_getchildren(self):
self.assertEqual(self.instance.getchildren(5), [1])
self.assertEqual(self.instance.getchildren(4), [])
def test_toporder(self):
self.instance.toporder()
self.assertTrue(self.instance.V.index(5)<self.instance.V.index(1))
self.assertTrue(self.instance.V.index(5)<self.instance.V.index(2))
示例14: net2
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
示例15: test_structure_estimation
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)