示例#1
0
def update_bayesian_network_structure(theme, nodes, edges, cpts):
  data = select_theme_data(theme)
  skel = GraphSkeleton()
  skel.load_skel(nodes, edges)
  skel.toporder()

  learner = PGMLearner()
  bn, passed = learner.discrete_mle_estimateparams(skel, data)

  return bn.Vdata, passed
示例#2
0
def create_bayesian_network_structure(theme):
  file_name = "bayes/bayes" + str(theme) + ".txt"  
  data = select_theme_data(theme)

  if not os.path.exists(file_name):
    learner = PGMLearner()
    result = learner.discrete_estimatebn(data, pvalparam=0.05, indegree=1)

    assert len(data[0]) == len(result.V)  # check number of nodes
    print 'Nr of nodes ' + str(len(result.V))
    print 'Nr of edges ' + str(len(result.E))
    print 'Saved network'

    save_network(file_name, result, theme)


  nd = NodeData()
  nd.load(file_name)
  skel = GraphSkeleton()
  skel.load(file_name)
  skel.toporder()
  bn = DiscreteBayesianNetwork(skel, nd)

  return bn