how to set background knowledge by pysmile

The engine.
Post Reply
Yang Yajie
Posts: 34
Joined: Thu Mar 19, 2020 11:49 am

how to set background knowledge by pysmile

Post by Yang Yajie »

Dear sir or madam,

I am using pysmile to create BBN in python. I have two types of background knowledge to set. type one is forbid "A" to "B", forbid "C" to "B". type two is for temporal nodes forbid "A_1" to "A, "B_1" to "B, "C_1" to "C, "D_1" to "D, "A_1" to "B_1".
I code like the below, I always get errors when I use the below type 1 or type 2, or type 3 to add background. it told me : SMILEException: Invalid variable index for arc start: -1
could you please tell me where I code wrong when I set background knowledge? when I delete background knowledge, my code can create a network xdsl file, so the problems may exist in the set background part.

could you please tell me how to set background knowledge in python when learning the structure of BBN?

thank you very much!


import pysmile
import pysmile_license
ds = pysmile.learning.DataSet()
ds.read_file("mydatafile.txt")
baySearch = pysmile.learning.BayesianSearch()
baySearch.set_iteration_count(10)
baySearch.set_max_parents(4)
# ADD BACKGROUND KNOWLEDGE
bkk = pysmile.learning.BkKnowledge()
#type1 -- error
baySearch.set_bk_knowledge('A' ,'B')

#type2-- error
baySearch.set_bk_knowledge(bkk.add_forbidden_arc('A' ,'B'))

#type3-- error
baySearch.set_bk_knowledge(bkk.add_forbidden_arc(1,2)

net = baySearch.learn(ds)
piotr [BayesFusion]
Site Admin
Posts: 60
Joined: Mon Nov 06, 2017 6:41 pm

Re: how to set background knowledge by pysmile

Post by piotr [BayesFusion] »

You can set Background Knowledge before calling learn method of chosen algorithm.

Code: Select all

...
bkk = pysmile.learning.BkKnowledge()
bkk.match_data(self.ds)
bkk.add_forbidden_arc("node_id", "outcome_id")
bkk.add_forced_arc("node_id", "outcome_id")
baySearch.set_bk_knowledge(bkk)
net = baySearch.learn(self.ds)
Post Reply