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


Python GraphSkeleton.toporder方法代码示例

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


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

示例1: setUp

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
 def setUp(self):
     skel = GraphSkeleton()
     skel.load("unittestdict.txt")
     skel.toporder()
     nodedata = NodeData.load("unittestdict.txt")
     self.bn = DiscreteBayesianNetwork(nodedata)
     self.fn = TableCPDFactorization(self.bn)
开发者ID:Anaphory,项目名称:libpgm,代码行数:9,代码来源:run_unit_tests.py

示例2: setUp

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
 def setUp(self):
     skel = GraphSkeleton()
     skel.load("unittestdict.txt")
     skel.toporder()
     nodedata = NodeData()
     nodedata.load("unittestdict.txt")
     self.instance = DiscreteBayesianNetwork(skel, nodedata)
开发者ID:CyberPoint,项目名称:libpgm,代码行数:9,代码来源:run_unit_tests.py

示例3: test_hybn_mte_estimateparams

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
    def test_hybn_mte_estimateparams(self):
        skel = GraphSkeleton()
        skel.load("../tests/bn_skeleton.txt")
        skel.toporder()
        
        with open('../tests/dataBR2.json', 'r') as f:
            samples = eval(f.read())

        result = self.l.hybn_mte_estimateparams(self.skel, self.samplelgseq)        
开发者ID:stchepanhagn,项目名称:libpgm,代码行数:11,代码来源:run_unit_tests.py

示例4: q_without_ros

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [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

示例5: TestOrderedSkeleton

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
class TestOrderedSkeleton(unittest.TestCase):

    def setUp(self):
        self.os = OrderedSkeleton()
        self.os.load("unittestdict.txt")
        self.gs = GraphSkeleton()
        self.gs.load("unittestdict.txt")

    def test_constructor(self):
        self.assertNotEqual(self.os.V, self.gs.V)
        self.gs.toporder()
        self.assertEqual(self.os.V, self.gs.V)
开发者ID:CyberPoint,项目名称:libpgm,代码行数:14,代码来源:run_unit_tests.py

示例6: load

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
    def load(self, file_name):
        #### Load BN
        nd = NodeData()
        skel = GraphSkeleton()
        nd.load(file_name)  # any input file
        skel.load(file_name)

        # topologically order graphskeleton
        skel.toporder()

        super(DiscreteBayesianNetworkExt, self).__init__(skel, nd)
        ##TODO load evidence
开发者ID:aurora1625,项目名称:sally-bn,代码行数:14,代码来源:DiscreteBayesianNetworkExt.py

示例7: TestDynDiscBayesianNetwork

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
class TestDynDiscBayesianNetwork(unittest.TestCase):

    def setUp(self):
        self.nd = NodeData.load("unittestdyndict.txt")
        self.skel = GraphSkeleton()
        self.skel.load("unittestdyndict.txt")
        self.skel.toporder()
        self.d = DynDiscBayesianNetwork(self.skel, self.nd)

    def test_randomsample(self):
        sample = self.d.randomsample(10)
        for i in range(1, 10):
            self.assertEqual(sample[0]['Difficulty'], sample[i]['Difficulty'])
开发者ID:Anaphory,项目名称:libpgm,代码行数:15,代码来源:run_unit_tests.py

示例8: TestHyBayesianNetwork

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
class TestHyBayesianNetwork(unittest.TestCase):

    def setUp(self):
        self.nd = HybridNodeData.load("unittesthdict.txt")
        self.nd.entriestoinstances()
        self.skel = GraphSkeleton()
        self.skel.load("unittestdict.txt")
        self.skel.toporder()
        self.hybn = HyBayesianNetwork(self.skel, self.nd)

    def test_randomsample(self):
        sample = self.hybn.randomsample(1)[0]
        self.assertTrue(isinstance(sample['Grade'], float))
        self.assertTrue(isinstance(sample['Intelligence'], str))
        self.assertEqual(sample["SAT"][-12:], 'blueberries!')
开发者ID:Anaphory,项目名称:libpgm,代码行数:17,代码来源:run_unit_tests.py

示例9: createData

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
def createData():
   nd = NodeData()
   skel = GraphSkeleton()
   fpath = "job_interview.txt"
   nd.load(fpath)
   skel.load(fpath)
   skel.toporder()
   bn = DiscreteBayesianNetwork(skel, nd)

   learner = PGMLearner()
   data = bn.randomsample(1000)
   X, Y = 'Grades', 'Offer'
   c,p,w=learner.discrete_condind(data, X, Y, ['Interview'])
   print "independence between X and Y: ", c, " p-value ", p, " witness node: ", w
   result = learner.discrete_constraint_estimatestruct(data)
   print result.E
开发者ID:gregory2000,项目名称:pycharm_projects,代码行数:18,代码来源:learn_structure.py

示例10: net2

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
def net2():
    nd = NodeData()
    skel = GraphSkeleton()
    nd.load("net.txt")  # an input file
    skel.load("net.txt")

    # topologically order graphskeleton
    skel.toporder()

    # load bayesian network
    lgbn = LGBayesianNetwork(skel, nd)

    in_data=read_data.getdata2()
    learner = PGMLearner()
    bn=learner.lg_mle_estimateparams(skel,in_data)

    p=cal_prob(in_data[300:500],bn)
    print p
    return 0
开发者ID:hendrikTpl,项目名称:Bayesian_TrafficPrediction,代码行数:21,代码来源:model2.py

示例11: TestGraphSkeleton

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
class TestGraphSkeleton(unittest.TestCase):

    def setUp(self):
        self.instance = GraphSkeleton()
        self.instance.V = [1,2,3,4,5]
        self.instance.E = [[5,1],[1,2]]

    def test_getparents(self):
        self.assertEqual(self.instance.getparents(1), [5])
        self.assertEqual(self.instance.getparents(4), [])

    def test_getchildren(self):
        self.assertEqual(self.instance.getchildren(5), [1])
        self.assertEqual(self.instance.getchildren(4), [])

    def test_toporder(self):
        self.instance.toporder()
        self.assertTrue(self.instance.V.index(5)<self.instance.V.index(1))
        self.assertTrue(self.instance.V.index(5)<self.instance.V.index(2))
开发者ID:CyberPoint,项目名称:libpgm,代码行数:21,代码来源:run_unit_tests.py

示例12: test_structure_estimation

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
    def test_structure_estimation(self):
        req = DiscreteStructureEstimationRequest()

        skel = GraphSkeleton()
        skel.load(self.data_path)
        skel.toporder()
        teacher_nd = NodeData()
        teacher_nd.load(self.teacher_data_path)
        bn = DiscreteBayesianNetwork(skel, teacher_nd)
        data = bn.randomsample(8000)
        for v in data:
            gs = DiscreteGraphState()
            for k_s, v_s in v.items():
                gs.node_states.append(DiscreteNodeState(node=k_s, state=v_s))
            req.states.append(gs)

        res = self.struct_estimate(req)
        self.assertIsNotNone(res.graph)
        self.assertEqual(len(res.graph.nodes), 5)
        self.assertGreater(len(res.graph.edges), 0)
开发者ID:1224830613,项目名称:jsk_3rdparty,代码行数:22,代码来源:test_discrete_bn.py

示例13: test_param_estimation

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
    def test_param_estimation(self):
        req = DiscreteParameterEstimationRequest()

        # load graph structure
        skel = GraphSkeleton()
        skel.load(self.data_path)
        req.graph.nodes = skel.V
        req.graph.edges = [GraphEdge(k, v) for k,v in skel.E]
        skel.toporder()

        # generate trial data
        teacher_nd = NodeData()
        teacher_nd.load(self.teacher_data_path)
        bn = DiscreteBayesianNetwork(skel, teacher_nd)
        data = bn.randomsample(200)
        for v in data:
            gs = DiscreteGraphState()
            for k_s, v_s in v.items():
                gs.node_states.append(DiscreteNodeState(node=k_s, state=v_s))
            req.states.append(gs)

        self.assertEqual(len(self.param_estimate(req).nodes), 5)
开发者ID:1224830613,项目名称:jsk_3rdparty,代码行数:24,代码来源:test_discrete_bn.py

示例14: main

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
def main():

    in_data=read_data.getdata()
    f_data=format_data(in_data)
    nd = NodeData()
    nd.load("net4.txt")    # an input file
    skel = GraphSkeleton()
    skel.load("net4.txt")
    skel.toporder()
    bn=DiscreteBayesianNetwork(skel,nd)


#training dataset:70%
    bn2=em(f_data[1:6000],bn,skel)

    pr_training = precision(f_data[1:6000],bn2)

    print "Prediction accuracy for training data:" , pr_training[1]

#testing dataset:30%
    pr=precision(f_data[6700:6800],bn2)
    print "Prediction accuracy for test data:", pr[1]
开发者ID:hendrikTpl,项目名称:Bayesian_TrafficPrediction,代码行数:24,代码来源:model2.py

示例15: train

# 需要导入模块: from libpgm.graphskeleton import GraphSkeleton [as 别名]
# 或者: from libpgm.graphskeleton.GraphSkeleton import toporder [as 别名]
    def train(self):
        """Train the associated module for one epoch."""
        assert len(self.ds) > 0, "Dataset cannot be empty."


            
        gbds = []
        
        ds2 = []
        for seq in self.ds:
            for state_, action_, reward_ in seq:

                #sample = dict(theta=state_[0],thetaV=state_[1],s=state_[2],sV=state_[3],Action=action_[0],Reward=reward_[0])
                sample = dict(StateA=state_[0],StateB=state_[2],StateC=state_[1],StateD=state_[3],Action=action_[0],Reward=reward_[0])

                 #print state_, action_, reward_
#                sample = dict(StateA=state_[0],StateB=state_[2],StateC=state_[1],StateD=state_[3],Action=action_[0],Reward=reward_[0])
                #sample = dict(theta=state_[0],thetaPrime=state_[2],s=state_[1],sPrime=state_[3],Action=action_[0],Reward=reward_[0])

                if sample["Reward"] >= 0:
                    gbds.append(sample)
                    
                if sample["Reward"] == -1:
                    ds2.append(sample)
                #print sample["Reward"]

        # sort samples for highest reward
#        bdss = sorted(gbds, key=lambda tup: tup["Reward"],reverse=True)
#        
        #print "BDS: "
        #print json.dumps(gbds, indent=2)
#        print "BDSS: "
#        print json.dumps(bdss, indent=2)
        
        #tokeep = bdss[:max(2,len(bdss)/2)]
        
        #print bds
        # estimate parameters
#        print "data size: ", len(bds),  len(gbds)
        N = 200
        if len(gbds) < N:
            l = N - len(gbds)
            n = len(ds2)
            
            t = len(ds2[n-l:])
            gbds.extend(ds2[n-l:])
            
        print "ds:, ", len(gbds), len(ds2)
        
        
        if len(gbds) < 100:
#            print "burn"
            self.module.burn = True
            return
        else:
            self.module.burn = False
            
        
        if len(gbds) < 5: #there was no rewarding action, so nothing to learn
          self.module.burn = True
          return
          
        N = 200
        if len(gbds) > N:
            #only take the newest N samples

            l = len(gbds)
            gbds = gbds[l-N:]
#            print "new effective set", len(gbds)
        
        skel = GraphSkeleton()
        #load network topology
        skel.load("net2.txt")
#        skel.load("workfile")
        skel.toporder()


        # estimate parameters
        self.module.net = self.learner.lg_mle_estimateparams(skel, gbds)
开发者ID:nairboon,项目名称:bnrl,代码行数:81,代码来源:learner.py


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