7 from pgm_learner.msg
import DiscreteNode, LinearGaussianNode, ConditionalProbability, GraphStructure, GraphEdge
9 from libpgm.graphskeleton
import GraphSkeleton
10 from libpgm.nodedata
import NodeData
13 skel = GraphSkeleton()
16 for name, v
in nd.Vdata.items():
18 skel.E += [[name, c]
for c
in v[
"children"]]
22 skel = GraphSkeleton()
23 skel.V = graph_structure.nodes
24 skel.E = [[e.node_from, e.node_to]
for e
in graph_structure.edges]
28 graph = GraphStructure()
29 if skel.V
and len(skel.V) > 0:
30 graph.nodes = map(str, skel.V)
31 if skel.E
and len(skel.E) > 0:
32 graph.edges = [GraphEdge(str(e[0]),str(e[1]))
for e
in skel.E]
37 for s
in graph_state.node_states:
38 data[s.node] = s.state
47 n.outcomes = map(str, d[
"vals"])
49 n.parents = map(str, d[
"parents"])
51 n.children = map(str, d[
"children"])
53 if isinstance(cprob, dict):
54 n.CPT = [ConditionalProbability(values=eval(k), probabilities=v)
for k,v
in (d[
"cprob"]).items()]
56 n.CPT = [ConditionalProbability(values=map(str, d[
"vals"]), probabilities=cprob)]
64 d[
"vals"] = msg.outcomes
65 d[
"numoutcomes"] = len(msg.outcomes)
66 d[
"parents"] = msg.parents
67 d[
"children"] = msg.children
69 d[
"cprob"] = msg.CPT[0].probabilities
71 d[
"cprob"] = {str(p.values): p.probabilities
for p
in msg.CPT}
81 n = LinearGaussianNode()
84 n.parents = map(str, d[
"parents"])
86 n.children = map(str, d[
"children"])
87 n.mean = d[
"mean_base"]
88 n.variance = d[
"variance"]
89 n.mean_scalar = d[
"mean_scal"]
def discrete_nodedata_from_ros(nodes)
def graph_skeleton_from_ros(graph_structure)
def linear_gaussian_node_from_dict(name, d)
def graph_skeleton_to_ros(skel)
def linear_gaussian_nodes_to_ros(d)
def graph_skeleton_from_node_data(nd)
def graph_state_dict_from_ros(graph_state)
def discrete_nodes_to_ros(d)
def discrete_node_from_dict(name, d)
def graph_states_dict_from_ros(graph_states)
def dict_from_ros_discrete_node(msg)