本文整理汇总了Python中libpgm.nodedata.NodeData类的典型用法代码示例。如果您正苦于以下问题:Python NodeData类的具体用法?Python NodeData怎么用?Python NodeData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeData类的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: 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
示例3: TestNodeData
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')
示例4: 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
示例5: test_query
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)
示例6: 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
示例7: TestDynDiscBayesianNetwork
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'])
示例8: TestHyBayesianNetwork
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: 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
示例10: 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
示例11: 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)
示例12: setUp
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
示例13: test_param_estimation
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)
示例14: main
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]
示例15: LinearGaussianParameterEstimationRequest
param_estimate = rospy.ServiceProxy(
"pgm_learner/linear_gaussian/parameter_estimation", LinearGaussianParameterEstimation
)
req = LinearGaussianParameterEstimationRequest()
dpath = os.path.join(PKG_PATH, "test", "graph-test.txt")
tpath = os.path.join(PKG_PATH, "test", "graph-lg-test.txt")
# load graph structure
skel = GraphSkeleton()
skel.load(dpath)
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(tpath)
bn = LGBayesianNetwork(skel, teacher_nd)
data = bn.randomsample(200)
for v in data:
gs = LinearGaussianGraphState()
for k_s, v_s in v.items():
gs.node_states.append(LinearGaussianNodeState(node=k_s, state=v_s))
req.states.append(gs)
PP.pprint(param_estimate(req).nodes)
开发者ID:1224830613,项目名称:jsk_3rdparty,代码行数:29,代码来源:linear_gaussian_bayesian_parameter_estimation_sample.py