贝叶斯网络中一个节点的类
#author=lx #date=2011-12-27 import os import sys class node: "store the information of a node in bnt" def __init__( self, nodename=None, cptnum=2, pnum=0, cnum=0, parename=None, childname=None ): self.node_name = nodename self.cpt_num = cptnum self.p_num = pnum self.c_num = cnum self.pare_name = parename self.child_name = childname def get_name( self ): return self.node_name def get_cptNum( self ): return self.cpt_num def get_parentNum( self ): return self.p_num def get_childNum( self ): return self.c_num def get_parentName( self ): if self.p_num >= 1: return self.pare_name else: return None def get_childName( self ): if self.c_num >= 1: return self.child_name else: return None def the_new_node( self ): print 'the new node is %s' % self.node_name if __name__ == "__main__": parent = [ 'god', 'godgod' ] child = ['my', 'mymy'] node1 = node( 'lx', 2, 2, 2, parent, child ) node1.the_new_node() print node1.get_name() print node1.get_cptNum() print node1.get_parentNum() print node1.get_parentName() print node1.get_childName()