9 from pgm_learner.srv
import LinearGaussianParameterEstimation, LinearGaussianParameterEstimationRequest
10 from pgm_learner.msg
import GraphEdge, LinearGaussianGraphState, LinearGaussianNodeState
12 from libpgm.graphskeleton
import GraphSkeleton
13 from libpgm.nodedata
import NodeData
14 from libpgm.lgbayesiannetwork
import LGBayesianNetwork
16 PKG_PATH = rospkg.RosPack().get_path(
"pgm_learner")
17 PP = pprint.PrettyPrinter(indent=2)
19 if __name__ ==
'__main__':
20 rospy.init_node(
"pgm_learner_sample_linear_gaussian")
22 param_estimate = rospy.ServiceProxy(
"pgm_learner/linear_gaussian/parameter_estimation", LinearGaussianParameterEstimation)
24 req = LinearGaussianParameterEstimationRequest()
26 dpath = os.path.join(PKG_PATH,
"test",
"graph-test.txt")
27 tpath = os.path.join(PKG_PATH,
"test",
"graph-lg-test.txt")
30 skel = GraphSkeleton()
32 req.graph.nodes = skel.V
33 req.graph.edges = [GraphEdge(k, v)
for k,v
in skel.E]
37 teacher_nd = NodeData()
38 teacher_nd.load(tpath)
39 bn = LGBayesianNetwork(skel, teacher_nd)
40 data = bn.randomsample(200)
43 gs = LinearGaussianGraphState()
44 for k_s, v_s
in v.items():
45 gs.node_states.append(LinearGaussianNodeState(node=k_s, state=v_s))