linear_gaussian_bayesian_parameter_estimation_sample.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 # Author: Yuki Furuta <furushchev@jsk.imi.i.u-tokyo.ac.jp>
00004 
00005 import os
00006 import pprint
00007 import rospkg
00008 import rospy
00009 from pgm_learner.srv import LinearGaussianParameterEstimation, LinearGaussianParameterEstimationRequest
00010 from pgm_learner.msg import GraphEdge, LinearGaussianGraphState, LinearGaussianNodeState
00011 
00012 from libpgm.graphskeleton import GraphSkeleton
00013 from libpgm.nodedata import NodeData
00014 from libpgm.lgbayesiannetwork import LGBayesianNetwork
00015 
00016 PKG_PATH = rospkg.RosPack().get_path("pgm_learner")
00017 PP = pprint.PrettyPrinter(indent=2)
00018 
00019 if __name__ == '__main__':
00020     rospy.init_node("pgm_learner_sample_linear_gaussian")
00021 
00022     param_estimate = rospy.ServiceProxy("pgm_learner/linear_gaussian/parameter_estimation", LinearGaussianParameterEstimation)
00023 
00024     req = LinearGaussianParameterEstimationRequest()
00025 
00026     dpath = os.path.join(PKG_PATH, "test", "graph-test.txt")
00027     tpath = os.path.join(PKG_PATH, "test", "graph-lg-test.txt")
00028 
00029     # load graph structure
00030     skel = GraphSkeleton()
00031     skel.load(dpath)
00032     req.graph.nodes = skel.V
00033     req.graph.edges = [GraphEdge(k, v) for k,v in skel.E]
00034     skel.toporder()
00035 
00036     # generate trial data
00037     teacher_nd = NodeData()
00038     teacher_nd.load(tpath)
00039     bn = LGBayesianNetwork(skel, teacher_nd)
00040     data = bn.randomsample(200)
00041 
00042     for v in data:
00043         gs = LinearGaussianGraphState()
00044         for k_s, v_s in v.items():
00045             gs.node_states.append(LinearGaussianNodeState(node=k_s, state=v_s))
00046         req.states.append(gs)
00047 
00048     PP.pprint(param_estimate(req).nodes)


pgm_learner
Author(s): Yuki Furuta
autogenerated on Wed Jul 10 2019 03:24:11