10 from pgm_learner.srv
import DiscreteParameterEstimation, DiscreteParameterEstimationRequest
11 from pgm_learner.msg
import GraphEdge, DiscreteGraphState, DiscreteNodeState
13 from libpgm.graphskeleton
import GraphSkeleton
14 from libpgm.nodedata
import NodeData
15 from libpgm.discretebayesiannetwork
import DiscreteBayesianNetwork
17 PKG_PATH = rospkg.RosPack().get_path(
"pgm_learner")
18 PP = pprint.PrettyPrinter(indent=2)
20 if __name__ ==
'__main__':
21 rospy.init_node(
"pgm_learner_sample_discrete")
23 param_estimate = rospy.ServiceProxy(
"pgm_learner/discrete/parameter_estimation", DiscreteParameterEstimation)
25 req = DiscreteParameterEstimationRequest()
27 dpath = os.path.join(PKG_PATH,
"test",
"graph-test.txt")
31 skel = GraphSkeleton()
33 req.graph.nodes = skel.V
34 req.graph.edges = [GraphEdge(k, v)
for k,v
in skel.E]
38 teacher_nd = NodeData()
39 teacher_nd.load(dpath)
40 bn = DiscreteBayesianNetwork(skel, teacher_nd)
41 data = bn.randomsample(200)
43 gs = DiscreteGraphState()
44 for k_s, v_s
in v.items():
45 gs.node_states.append(DiscreteNodeState(node=k_s, state=v_s))