当前位置: 首页>>代码示例>>Python>>正文


Python GraphSkeleton.E方法代码示例

本文整理汇总了Python中libpgm.graphskeleton.GraphSkeleton.E方法的典型用法代码示例。如果您正苦于以下问题:Python GraphSkeleton.E方法的具体用法?Python GraphSkeleton.E怎么用?Python GraphSkeleton.E使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在libpgm.graphskeleton.GraphSkeleton的用法示例。


在下文中一共展示了GraphSkeleton.E方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: graph_skeleton_from_node_data

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import E [as 别名]
def graph_skeleton_from_node_data(nd):
    skel = GraphSkeleton()
    skel.V = []
    skel.E = []
    for name, v in nd.Vdata.items():
        skel.V += [name]
        skel.E += [[name, c] for c in v["children"]]
    return skel
开发者ID:1224830613,项目名称:jsk_3rdparty,代码行数:10,代码来源:msg_utils.py

示例2: q_without_ros

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import E [as 别名]
def q_without_ros():
    skel = GraphSkeleton()
    skel.V = ["prize_door", "guest_door", "monty_door"]
    skel.E = [["prize_door", "monty_door"],
              ["guest_door", "monty_door"]]
    skel.toporder()
    nd = NodeData()
    nd.Vdata = {
        "prize_door": {
            "numoutcomes": 3,
            "parents": None,
            "children": ["monty_door"],
            "vals": ["A", "B", "C"],
            "cprob": [1.0/3, 1.0/3, 1.0/3],
        },
        "guest_door": {
            "numoutcomes": 3,
            "parents": None,
            "children": ["monty_door"],
            "vals": ["A", "B", "C"],
            "cprob": [1.0/3, 1.0/3, 1.0/3],
        },
        "monty_door": {
            "numoutcomes": 3,
            "parents": ["prize_door", "guest_door"],
            "children": None,
            "vals": ["A", "B", "C"],
            "cprob": {
                "['A', 'A']": [0., 0.5, 0.5],
                "['B', 'B']": [0.5, 0., 0.5],
                "['C', 'C']": [0.5, 0.5, 0.],
                "['A', 'B']": [0., 0., 1.],
                "['A', 'C']": [0., 1., 0.],
                "['B', 'A']": [0., 0., 1.],
                "['B', 'C']": [1., 0., 0.],
                "['C', 'A']": [0., 1., 0.],
                "['C', 'B']": [1., 0., 0.],
            },
        },
    }
    bn = DiscreteBayesianNetwork(skel, nd)
    fn = TableCPDFactorization(bn)

    query = {
        "prize_door": ["A","B","C"],
    }
    evidence = {
        "guest_door": "A",
        "monty_door": "B",
    }

    res = fn.condprobve(query, evidence)
    print res.vals
    print res.scope
    print res.card
    print res.stride
开发者ID:1224830613,项目名称:jsk_3rdparty,代码行数:58,代码来源:discrete_bayesian_query_sample.py

示例3: add_sensor

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import E [as 别名]
    def add_sensor(self, sensor_keys):
        for key in sensor_keys:
            network_file = open(self.dbn_file_name, 'r')
            network_file_data = eval(network_file.read())

            network_skeleton = GraphSkeleton()
            network_skeleton.V = network_file_data["V"]
            network_skeleton.E = network_file_data["E"]

            self.network = DynDiscBayesianNetwork()
            self.network.V = network_skeleton.V
            self.network.E = network_skeleton.E
            self.network.initial_Vdata = network_file_data["initial_Vdata"]
            self.network.twotbn_Vdata = network_file_data["twotbn_Vdata"]

            self.inference_engines[key] = SensorDbnInferenceEngine(self.network)
开发者ID:alex-mitrevski,项目名称:robot_simulation,代码行数:18,代码来源:fault_detector.py

示例4: graph_skeleton_from_ros

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import E [as 别名]
def graph_skeleton_from_ros(graph_structure):
    skel = GraphSkeleton()
    skel.V = graph_structure.nodes
    skel.E = [[e.node_from, e.node_to] for e in graph_structure.edges]
    return skel
开发者ID:1224830613,项目名称:jsk_3rdparty,代码行数:7,代码来源:msg_utils.py

示例5: learnDiscreteBN_with_structure

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import E [as 别名]
def learnDiscreteBN_with_structure(df, continous_columns, features_column_names, label_column='cat',
                                   draw_network=False):
    features_df = df.copy()
    features_df = features_df.drop(label_column, axis=1)

    labels_df = DataFrame()
    labels_df[label_column] = df[label_column].copy()

    for i in continous_columns:
        bins = np.arange((min(features_df[i])), (max(features_df[i])),
                         ((max(features_df[i]) - min(features_df[i])) / 5.0))
        features_df[i] = pandas.np.digitize(features_df[i], bins=bins)

    data = []
    for index, row in features_df.iterrows():
        dict = {}
        for i in features_column_names:
            dict[i] = row[i]
        dict[label_column] = labels_df[label_column][index]
        data.append(dict)

    print "Init done"
    learner = PGMLearner()

    graph = GraphSkeleton()

    graph.V = []
    graph.E = []

    graph.V.append(label_column)

    for vertice in features_column_names:
        graph.V.append(vertice)
        graph.E.append([vertice, label_column])

    test = learner.discrete_mle_estimateparams(graphskeleton=graph, data=data)

    print "done learning"

    edges = test.E
    vertices = test.V
    probas = test.Vdata

    # print probas

    dot_string = 'digraph BN{\n'
    dot_string += 'node[fontname="Arial"];\n'

    dataframes = {}

    print "save data"
    for vertice in vertices:
        print "New vertice: " + str(vertice)
        dataframe = DataFrame()

        pp = pprint.PrettyPrinter(indent=4)
        # pp.pprint(probas[vertice])
        dot_string += vertice.replace(" ", "_") + ' [label="' + vertice + '\n' + '" ]; \n'

        if len(probas[vertice]['parents']) == 0:
            dataframe['Outcome'] = None
            dataframe['Probability'] = None
            vertex_dict = {}
            for index_outcome, outcome in enumerate(probas[vertice]['vals']):
                vertex_dict[str(outcome)] = probas[vertice]["cprob"][index_outcome]

            od = collections.OrderedDict(sorted(vertex_dict.items()))
            # print "Vertice: " + str(vertice)
            # print "%-7s|%-11s" % ("Outcome", "Probability")
            # print "-------------------"
            for k, v in od.iteritems():
                # print "%-7s|%-11s" % (str(k), str(round(v, 3)))
                dataframe.loc[len(dataframe)] = [k, v]
            dataframes[vertice] = dataframe
        else:
            # pp.pprint(probas[vertice])
            dataframe['Outcome'] = None

            vertexen = {}
            for index_outcome, outcome in enumerate(probas[vertice]['vals']):
                temp = []
                for parent_index, parent in enumerate(probas[vertice]["parents"]):
                    # print str([str(float(index_outcome))])
                    temp = probas[vertice]["cprob"]
                    dataframe[parent] = None
                vertexen[str(outcome)] = temp

            dataframe['Probability'] = None
            od = collections.OrderedDict(sorted(vertexen.items()))

            # [str(float(i)) for i in ast.literal_eval(key)]


            # str(v[key][int(float(k))-1])

            # print "Vertice: " + str(vertice) + " with parents: " + str(probas[vertice]['parents'])
            # print "Outcome" + "\t\t" + '\t\t'.join(probas[vertice]['parents']) + "\t\tProbability"
            # print "------------" * len(probas[vertice]['parents']) *3
            # pp.pprint(od.values())

#.........这里部分代码省略.........
开发者ID:GillesVandewiele,项目名称:HeadacheClassifier,代码行数:103,代码来源:bayesian_network.py

示例6: open

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import E [as 别名]
result = learner.discrete_estimatebn(data)

# output - toggle comment to see
#print json.dumps(result.E, indent=2)
#print json.dumps(result.Vdata, indent=2)

# (13) -----------------------------------------------------------------------
# Forward sample on dynamic Bayesian networks

# read input file
path = "../tests/unittestdyndict.txt"
f = open(path, 'r')
g = eval(f.read())

# set up dynamic BN
d = DynDiscBayesianNetwork()
skel = GraphSkeleton()
skel.V = g["V"]
skel.E = g["E"]
skel.toporder()
d.V = skel.V
d.E = skel.E
d.initial_Vdata = g["initial_Vdata"]
d.twotbn_Vdata = g["twotbn_Vdata"]

# forward sample
seq = d.randomsample(10)

# output - toggle comment to see
#print json.dumps(seq, indent=2)
开发者ID:Anaphory,项目名称:libpgm,代码行数:32,代码来源:examples.py

示例7: open

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import E [as 别名]
import json

from libpgm.nodedata import NodeData
from libpgm.graphskeleton import GraphSkeleton
from libpgm.dyndiscbayesiannetwork import DynDiscBayesianNetwork

from inference.sensor_dbn_inference import SensorDbnInference

network_file = open('test_bayesian_networks/sensor_dbn.txt', 'r')
network_file_data = eval(network_file.read())

network_skeleton = GraphSkeleton()
network_skeleton.V = network_file_data["V"]
network_skeleton.E = network_file_data["E"]

network = DynDiscBayesianNetwork()
network.V = network_skeleton.V
network.E = network_skeleton.E
network.initial_Vdata = network_file_data["initial_Vdata"]
network.twotbn_Vdata = network_file_data["twotbn_Vdata"]

inference_engine = SensorDbnInference(network)
print 'Initial belief: ', inference_engine.get_current_belief()
inference_engine.filter('1')
print 'Measurement = 1: ', inference_engine.get_current_belief()
inference_engine.filter('0')
print 'Measurement = 0: ', inference_engine.get_current_belief()
inference_engine.filter('0')
print 'Measurement = 0: ', inference_engine.get_current_belief()
开发者ID:alex-mitrevski,项目名称:graphical-models,代码行数:31,代码来源:dbn_test.py

示例8: open

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import E [as 别名]
# figure.add_subplot(1,2,2)
# plt.scatter(test_data[cluster_1,0], test_data[cluster_1,1], c= 'r', marker='o')
# plt.scatter(test_data[cluster_2,0], test_data[cluster_2,1], c='b', marker='o')
# plt.scatter(test_data[cluster_3,0], test_data[cluster_3,1], c='k', marker='o')
# plt.scatter(means[:,0], means[:,1], c='c', marker='o')
# plt.show()

means = numpy.array([[  2.00755688e-04,   1.65181639e-01], [  8.37884753e-01,   9.99778286e-01], [  9.75317567e-01,   2.46051178e-02]])

# sensor network
sensor_network_file = open('test_bayesian_networks/graph_sensor_dbn.txt', 'r')
sensor_network_file_data = eval(sensor_network_file.read())

sensor_network_skeleton = GraphSkeleton()
sensor_network_skeleton.V = sensor_network_file_data["V"]
sensor_network_skeleton.E = sensor_network_file_data["E"]

sensor_network = DynDiscBayesianNetwork()
sensor_network.V = sensor_network_skeleton.V
sensor_network.E = sensor_network_skeleton.E
sensor_network.initial_Vdata = sensor_network_file_data["initial_Vdata"]
sensor_network.twotbn_Vdata = sensor_network_file_data["twotbn_Vdata"]

# observation_network
observation_network_file = open('test_bayesian_networks/graph_transition_dbn.txt', 'r')
observation_network_file_data = eval(observation_network_file.read())

observation_network_skeleton = GraphSkeleton()
observation_network_skeleton.V = observation_network_file_data["V"]
observation_network_skeleton.E = observation_network_file_data["E"]
开发者ID:alex-mitrevski,项目名称:graphical-models,代码行数:32,代码来源:graph_inference_test.py


注:本文中的libpgm.graphskeleton.GraphSkeleton.E方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。