• 大小: 26KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: Python
  • 标签: Bayesian  

资源简介

用python写的一段贝叶斯网络的程序 This file describes a Bayes Net Toolkit that we will refer to now as BNT. This version is 0.1. Let's consider this code an "alpha" version that contains some useful functionality, but is not complete, and is not a ready-to-use "application". The purpose of the toolkit is to facilitate creating experimental Bayes nets that analyze sequences of events. The toolkit provides code to help with the following: (a) creating Bayes nets. There are three classes of nodes defined, and to construct a Bayes net, you can write code that calls the constructors of these classes, and then you can create links among them. (b) displaying Bayes nets. There is code to create new windows and to draw Bayes nets in them. This includes drawing the nodes, the arcs, the labels, and various properties of nodes. (c) propagating a-posteriori probabilities. When one node's probability changes, the posterior probabilities of nodes downstream from it may need to change, too, depending on firing thresholds, etc. There is code in the toolkit to support that. (d) simulating events ("playing" event sequences) and having the Bayes net respond to them. This functionality is split over several files. Here are the files and the functionality that they represent. BayesNetNode.py: class definition for the basic node in a Bayes net. BayesUpdating.py: computing the a-posteriori probability of a node given the probabilities of its parents. InputNode.py: class definition for "input nodes". InputNode is a subclass of BayesNetNode. Input nodes have special features that allow them to recognize evidence items (using regular-expression pattern matching of the string descriptions of events). OutputNode.py: class definition for "output nodes". OutputBode is a subclass of BayesNetNode. An output node can have a list of actions to be performed when the node's posterior probability exceeds a threshold ReadWriteSigmaFiles.py: Functionality for loading and saving Bayes nets

资源截图

代码片段和文件信息

‘‘‘ BayesNetNode.py


S. Tanimoto 11 Jan 2009

This file provides:

-- Node class definitions.
‘‘‘

import Tkinter

class Node:

    name_node_hash = {}
    def __init__(self name desc x y poss_vals = [‘True‘ ‘False‘]):
        self.name = name
        self.desc = desc
        self.x = x
        self.y = y
        Node.name_node_hash[name] = self
        self.parents = []
        self.children = []
        self.possible_values = poss_vals
        self.p = {} # Hash so that number of parents can change.
        self.current_prob = {} # current probabilities one for each
            # possible_value.
        default_prob = 1.0 / len(poss_vals)
        for pv in poss_vals:
            self.current_prob[pv] = default_prob
            self.p[self.name+“=“+pv] = default_prob

    def get_prior(self poss_val):
        return self.p[self.name+“=“+poss_val]
        
    def set_prior(self poss_val prob):
        self.p[self.name+“=“+poss_val] = prob
        self.current_prob[poss_val] = prob
        
    def add_parent(self parent_name):
        p = Node.name_node_hash[parent_name]
        self.parents.append(p)
        return p
                
    def add_child(self child_name):
        c = Node.name_node_hash[child_name]
        self.children.append(c)
        return c        
        
class BayesNet:
    def __init__(self name):
        self.name = name
        self.nodes = []
        self.input_nodes = []

    def add_node(self node):
        self.nodes.append(node)
        from InputNode import Input_Node
        if isinstance(node Input_Node):
            self.input_nodes.append(node)

    def get_input_nodes(self):
        return self.input_nodes



 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1693  2009-02-21 23:49  bayeskit01\BayesKit\BayesNetNode.py

     文件       2726  2009-02-21 23:49  bayeskit01\BayesKit\BayesUpdating.py

     文件        424  2009-02-21 23:50  bayeskit01\BayesKit\OutputNode.py

     文件       9219  2009-02-21 23:50  bayeskit01\BayesKit\ReadWriteSigmaFiles.py

     文件       2508  2009-02-21 23:50  bayeskit01\BayesKit\gma-mona.igm

     文件        485  2009-02-21 23:50  bayeskit01\BayesKit\sample-event-file.txt

     文件       2439  2009-02-21 23:49  bayeskit01\BayesKit\SampleNets.py

     文件       6884  2009-02-23 14:14  bayeskit01\BayesKit\SIGMAEditor.py

     文件       2393  2009-02-23 14:14  bayeskit01\BayesKit\InputNode.py

     文件       4778  2009-02-23 19:57  bayeskit01\BayesKit\README.txt

     文件       3187  2009-02-23 20:38  bayeskit01\BayesKit\BayesNetNode.pyc

     文件       3948  2009-02-23 20:38  bayeskit01\BayesKit\BayesUpdating.pyc

     文件       9919  2009-02-23 20:38  bayeskit01\BayesKit\ReadWriteSigmaFiles.pyc

     文件       3227  2009-02-23 20:38  bayeskit01\BayesKit\InputNode.pyc

     文件       1139  2009-02-23 20:38  bayeskit01\BayesKit\OutputNode.pyc

     文件       9183  2009-02-23 20:38  bayeskit01\BayesKit\SIGMAEditor.pyc

     文件       3217  2009-02-23 20:38  bayeskit01\BayesKit\SampleNets.pyc

     目录          0  2009-02-23 20:45  bayeskit01\BayesKit

     目录          0  2009-02-23 20:45  bayeskit01

----------- ---------  ---------- -----  ----

                67369                    19


评论

共有 条评论

相关资源