コード例 #1
0
net_p = ntc.newnet('BNZeebrugge', env)

# define nodes
nodeBC1 = ntc.newnode('PeakWaterLevel', 5, net_p)
ntc.setnodelevels(nodeBC1, 5,
                  np.asarray([6.35, 7.1, 7.4, 7.8, 7.9], dtype='float64'))
ntc.setnodetitle(nodeBC1, 'Peak Water Level (m)')

nodeBC2 = ntc.newnode('MaxSignificantWaveHeight', 5, net_p)
ntc.setnodelevels(nodeBC2, 5,
                  np.asarray([5.2, 5.7, 5.9, 6.08, 6.2], dtype='float64'))
ntc.setnodetitle(nodeBC2, 'Max. significant wave height (m)')

nodeR1 = ntc.newnode('Location_Houses', 4, net_p)
ntc.setnodetitle(nodeR1, 'Houses - Location')
ntc.setnodestatenames(nodeR1, "Area1, Area2, Area3, Area4")
ntc.setnodestatetitle(nodeR1, 0, 'Area 1 (has 283 houses)')
ntc.setnodestatetitle(nodeR1, 1, 'Area 2 (has 759 houses)')
ntc.setnodestatetitle(nodeR1, 2, 'Area 3 (has 383 houses)')
ntc.setnodestatetitle(nodeR1, 3, 'Area 4 (has 273 houses)')

nodeH1_R1 = ntc.newnode('MaxInundation_Houses', 0, net_p)
ntc.setnodelevels(nodeH1_R1, 4, np.asarray([0, 0, 0.5, 1, 2], dtype='float64'))
ntc.setnodetitle(nodeH1_R1, 'Houses - Max. Inundation depth (m)')

nodeC1_R1 = ntc.newnode('RelativeDamage_Houses', 0, net_p)
ntc.setnodelevels(nodeC1_R1, 4,
                  np.asarray([0, 0, 23.5, 47, 50], dtype='float64'))
ntc.setnodetitle(nodeC1_R1, 'Houses - Relative Damage (%)')

# define links
コード例 #2
0
ファイル: netica_Demo.py プロジェクト: cedavidyang/pyNetica
env = ntc.newenv()
# initialize environment
ntc.initenv(env)
# create new net
net_p = ntc.newnet('ChestClinic', env)
 
# define nodes
VisitAsia = ntc.newnode("VisitAsia", 2, net_p)
Tuberculosis = ntc.newnode ("Tuberculosis", 2, net_p)
Smoking =      ntc.newnode ("Smoking", 2, net_p)
Cancer =       ntc.newnode ("Cancer", 2, net_p)
TbOrCa =       ntc.newnode ("TbOrCa", 2, net_p)
XRay =         ntc.newnode ("XRay", 2, net_p)

# set node names
ntc.setnodestatenames(VisitAsia,   "visit,   no_visit");
ntc.setnodestatenames(Tuberculosis,"present, absent");
ntc.setnodestatenames(Smoking,     "smoker,  nonsmoker");
ntc.setnodestatenames(Cancer,      "present, absent");
ntc.setnodestatenames(TbOrCa,      "true,    false");
ntc.setnodestatenames(XRay,        "abnormal,normal");

# define links
ntc.addlink(parent=VisitAsia,    child=Tuberculosis)
ntc.addlink(parent=Smoking,      child=Cancer)
ntc.addlink(parent=Tuberculosis, child=TbOrCa)
ntc.addlink(parent=Cancer,       child=TbOrCa)
ntc.addlink(parent=TbOrCa,       child=XRay)

# set node probs
コード例 #3
0
ファイル: __init__.py プロジェクト: wsjager/PythonNetica
class UnitTests(unittest.TestCase):
    def setUp(self):
        from netica import Netica
        self.netica = Netica()
        self.netfilename = 'curvnet.dne'
        self.env = self.netica.newenv()
        self.netica.initenv(self.env)
        self.net = self.netica.opennet(self.env, self.netfilename)
        self.nl_p = self.netica.getnetnodes(self.net)
        self.netica.compilenet(self.net)

    def test_enternodelikelyhood(self):
        self.netica.retractnetfindings(self.net)
        node_p = self.netica.getnodenamed('radius', self.net)
        self.netica.enternodelikelyhood(node_p, [1, 0, 0, 0, 0, 0])


#        self.netica.savenet(env, net, 'test.dne')

    def test_equationtotable(self):
        node_p = self.netica.getnodenamed('radius', self.net)
        self.netica.equationtotable(node_p, 10, True, True)

    def test_revisecptsbycasefile(self):
        casefilename = 'wavedir.cas'
        file_p = self.netica._newstream(self.env, casefilename)
        self.netica.revisecptsbycasefile(file_p, self.nl_p, 0, 1)

    def test_getnodeequation(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        eqn = self.netica.getnodeequation(node_p)
        print eqn
        # the radius node has no equation, thus should result in an empty string
        node_p = self.netica.getnodenamed('radius', self.net)
        eqn = self.netica.getnodeequation(node_p)
        self.assertEqual(eqn, '')

    def test_setnodeequation(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        eqn_in = 'phi (theta, wavedir) = theta - wavedir'
        self.netica.setnodeequation(node_p, eqn_in)
        eqn_out = self.netica.getnodeequation(node_p)
        self.assertEqual(eqn_in, eqn_out)

    def test_newnode(self):
        nodename = 'test'
        node_p = self.netica.newnode(nodename, 3, self.net)
        self.assertEqual(self.netica.getnodename(node_p), nodename)

    def test_deletenode(self):
        nodename = 'test'
        node_p = self.netica.newnode(nodename, 3, self.net)
        self.netica.deletenode(node_p)

    def test_addlink(self):
        parent = self.netica.getnodenamed('wavedir', self.net)
        child = self.netica.getnodenamed('erosionfactor', self.net)
        link_index = self.netica.addlink(parent, child)
        print 'index', link_index

    def test_deletelink(self):
        child = self.netica.getnodenamed('erosionfactor', self.net)
        link_index = 1
        self.netica.deletelink(link_index, child)

    def test_getnodelevels_continuous(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        print self.netica.getnodelevels(node_p)

    def test_getnodelevels_discrete(self):
        node_p = self.netica.newnode('Time_horizon', 3, self.net)
        #self.netica.setnodestatenames(node_p, "one, five, ten")
        self.netica.getnodelevels(node_p)

    def test_getnodestatename(self):
        node_p = self.netica.newnode('Time_horizon', 3, self.net)
        self.netica.setnodestatenames(node_p, "one, five, ten")
        print 'STATE: "' + self.netica.getnodestatename(node_p, 0) + '"'

    def test_enterfinding(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        self.netica.enterfinding(node_p, 0)

    def test_getnodeexpectedvalue(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        expval = self.netica.getnodeexpectedvalue(node_p)
        print 'expval = ', expval
コード例 #4
0
ファイル: __init__.py プロジェクト: wiebkejaeger/PythonNetica
class UnitTests(unittest.TestCase):
    def setUp(self):
        from netica import Netica
        self.netica = Netica()
        self.netfilename = 'curvnet.dne'
        self.env = self.netica.newenv()
        self.netica.initenv(self.env)
        self.net = self.netica.opennet(self.env, self.netfilename)
        self.nl_p = self.netica.getnetnodes(self.net)
        self.netica.compilenet(self.net)
    def test_enternodelikelyhood(self):
        self.netica.retractnetfindings(self.net)
        node_p = self.netica.getnodenamed('radius', self.net)
        self.netica.enternodelikelyhood(node_p, [1,0,0,0,0,0])
#        self.netica.savenet(env, net, 'test.dne')
    def test_equationtotable(self):
        node_p = self.netica.getnodenamed('radius', self.net)
        self.netica.equationtotable(node_p, 10, True, True)
    def test_revisecptsbycasefile(self):
        casefilename = 'wavedir.cas'
        file_p = self.netica._newstream(self.env, casefilename)
        self.netica.revisecptsbycasefile(file_p, self.nl_p, 0, 1)
    def test_getnodeequation(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        eqn = self.netica.getnodeequation(node_p)
        print eqn
        # the radius node has no equation, thus should result in an empty string
        node_p = self.netica.getnodenamed('radius', self.net)
        eqn = self.netica.getnodeequation(node_p)
        self.assertEqual(eqn, '')
    def test_setnodeequation(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        eqn_in = 'phi (theta, wavedir) = theta - wavedir'
        self.netica.setnodeequation(node_p, eqn_in)
        eqn_out = self.netica.getnodeequation(node_p)
        self.assertEqual(eqn_in, eqn_out)
    def test_newnode(self):
        nodename = 'test'
        node_p = self.netica.newnode(nodename, 3, self.net)
        self.assertEqual(self.netica.getnodename(node_p), nodename)
    def test_deletenode(self):
        nodename = 'test'
        node_p = self.netica.newnode(nodename, 3, self.net)
        self.netica.deletenode(node_p)
    def test_addlink(self):
        parent = self.netica.getnodenamed('wavedir', self.net)
        child = self.netica.getnodenamed('erosionfactor', self.net)
        link_index = self.netica.addlink(parent, child)
        print 'index',link_index
    def test_deletelink(self):
        child = self.netica.getnodenamed('erosionfactor', self.net)
        link_index = 1
        self.netica.deletelink(link_index, child)
    def test_getnodelevels_continuous(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        print self.netica.getnodelevels(node_p)
    def test_getnodelevels_discrete(self):
        node_p = self.netica.newnode('Time_horizon', 3, self.net)
        #self.netica.setnodestatenames(node_p, "one, five, ten")
        self.netica.getnodelevels(node_p)
    def test_getnodestatename(self):
        node_p = self.netica.newnode('Time_horizon', 3, self.net)
        self.netica.setnodestatenames(node_p, "one, five, ten")
        print 'STATE: "' + self.netica.getnodestatename(node_p, 0) + '"'
    def test_enterfinding(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        self.netica.enterfinding(node_p, 0)
    def test_getnodeexpectedvalue(self):
        node_p = self.netica.getnodenamed('phi', self.net)
        expval = self.netica.getnodeexpectedvalue(node_p)
        print 'expval = ',expval
コード例 #5
0
env = ntc.newenv()
# initialize environment
ntc.initenv(env)
# create new net
net_p = ntc.newnet('ChestClinic', env)

# define nodes
VisitAsia = ntc.newnode("VisitAsia", 2, net_p)
Tuberculosis = ntc.newnode("Tuberculosis", 2, net_p)
Smoking = ntc.newnode("Smoking", 2, net_p)
Cancer = ntc.newnode("Cancer", 2, net_p)
TbOrCa = ntc.newnode("TbOrCa", 2, net_p)
XRay = ntc.newnode("XRay", 2, net_p)

# set node names
ntc.setnodestatenames(VisitAsia, "visit,   no_visit")
ntc.setnodestatenames(Tuberculosis, "present, absent")
ntc.setnodestatenames(Smoking, "smoker,  nonsmoker")
ntc.setnodestatenames(Cancer, "present, absent")
ntc.setnodestatenames(TbOrCa, "true,    false")
ntc.setnodestatenames(XRay, "abnormal,normal")

# define links
ntc.addlink(parent=VisitAsia, child=Tuberculosis)
ntc.addlink(parent=Smoking, child=Cancer)
ntc.addlink(parent=Tuberculosis, child=TbOrCa)
ntc.addlink(parent=Cancer, child=TbOrCa)
ntc.addlink(parent=TbOrCa, child=XRay)

# set node probs
コード例 #6
0
ntc.initenv(env)
# create new net
net_p = ntc.newnet('BNZeebrugge', env)
 
# define nodes
nodeBC1 = ntc.newnode('PeakWaterLevel', 5, net_p)
ntc.setnodelevels(nodeBC1, 5, np.asarray([6.35, 7.1, 7.4, 7.8, 7.9], dtype='float64'))
ntc.setnodetitle(nodeBC1,'Peak Water Level (m)')

nodeBC2 = ntc.newnode('MaxSignificantWaveHeight', 5, net_p)
ntc.setnodelevels(nodeBC2, 5, np.asarray([5.2, 5.7, 5.9, 6.08, 6.2], dtype='float64'))
ntc.setnodetitle(nodeBC2,'Max. significant wave height (m)')

nodeR1 = ntc.newnode('Location_Houses', 4, net_p)
ntc.setnodetitle(nodeR1,'Houses - Location')
ntc.setnodestatenames(nodeR1, "Area1, Area2, Area3, Area4")
ntc.setnodestatetitle(nodeR1, 0, 'Area 1 (has 283 houses)')
ntc.setnodestatetitle(nodeR1, 1, 'Area 2 (has 759 houses)')
ntc.setnodestatetitle(nodeR1, 2, 'Area 3 (has 383 houses)')
ntc.setnodestatetitle(nodeR1, 3, 'Area 4 (has 273 houses)')

nodeH1_R1 = ntc.newnode('MaxInundation_Houses', 0, net_p)
ntc.setnodelevels(nodeH1_R1, 4, np.asarray([0, 0, 0.5, 1, 2], dtype='float64'))
ntc.setnodetitle(nodeH1_R1,'Houses - Max. Inundation depth (m)')

nodeC1_R1 = ntc.newnode('RelativeDamage_Houses', 0, net_p)
ntc.setnodelevels(nodeC1_R1, 4, np.asarray([0, 0, 23.5, 47, 50], dtype='float64')) 
ntc.setnodetitle(nodeC1_R1,'Houses - Relative Damage (%)') 	
 
# define links
ntc.addlink(parent=nodeBC1, child=nodeH1_R1)