def get_parents(x, collection=None):
 if (collection is None):
  collection = random_variables()
 node_dict = {node.value(): node for node in collection}
 output = set([])
 nodes = set([x])
 while nodes:
  node = nodes.pop()
  if isinstance(node, RandomVariable):
   node = node.value()
  candidate_node = node_dict.get(node, None)
  if (candidate_node and (candidate_node != x)):
   output.add(candidate_node)
  else:
   nodes.update(node.op.inputs)
 return list(output)

def get_parents ( x , collection = None ) : if ( collection is None ) : collection = random_variables ( ) node_dict = { node . value ( ) : node for node in collection } output = set ( [ ] ) nodes = set ( [ x ] ) while nodes : node = nodes . pop ( ) if isinstance ( node , RandomVariable ) : node = node . value ( ) candidate_node = node_dict . get ( node , None ) if ( candidate_node and ( candidate_node != x ) ) : output . add ( candidate_node ) else : nodes . update ( node . op . inputs ) return list ( output )
get parent random variables of input .