使用F-AI artificial intelligence for F#/.NET 可视化自己的贝叶斯网络。
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 15 22:11:38 2017
@author: Beyond
"""
import pandas as pd
import itertools
class Node(object):
def __init__(self, name, name2, labels, parents, correct_order = None):
self.name = name
self.name2 = name2
self.labels = labels
self.load_excel()
self.parents = parents
self.correct_order = correct_order
def load_excel(self):
self.distributionSet_raw = pd.read_excel('概率矩阵.xlsx', sheetname = self.name2, header=None)
self.discrete = [x+1 for x in list(self.distributionSet_raw.index)]
def create_dot_bn(node):
result = {}
result["name"] = node.name
result["space"] = {
"discrete":node.discrete, "labels":node.labels}
if len(node.parents) == 0:
set_dict = {}
set_dict["key"] = {}
distribution_list = []
for value, mass in zip(node.discrete, list(node.distributionSet_raw[0])):
distribution_list.append({
"value": value,