Object-Oriented Probabilistic Relational Model¶
In [1]:
import os
os.chdir("res")
import pyAgrum as gum
import pyAgrum.lib.notebook as gnb
O3PRM is inspired by relational language, directly based on the BN and improved by object oriented paradigms, where the focus is set on classes of objects and by defining relations among these objects (see http://o3prm.gitlab.io/ for more details)
O3PRM syntax¶
In [2]:
with open('./Asia.o3prm','r') as prm:
for line in prm.readlines():
print(line,end="")
class Asia { boolean visitToAsia { [ 0.99, // False 0.01 ] // True }; boolean tuberculosis dependson visitToAsia { // False | True [ 0.99, 0.95, // False 0.01, 0.05 ] // True }; boolean smoking { [ 0.50, // False 0.50 ] // True }; boolean lungCancer dependson smoking { // False | True => smoking [ 0.99, 0.90, // False 0.01, 0.10 ] // True }; boolean bronchitis dependson smoking { // False | True => smoking [ 0.70, 0.40, // False 0.30, 0.60 ] // True }; boolean tubOrCancer dependson tuberculosis, lungCancer { // False || True => tuberculosis // False | True || False | True => lungCancer [ 1.00, 0.00, 0.00, 0.00, // False 0.00, 1.00, 1.00, 1.00 ] // True }; boolean positiveXRay dependson tubOrCancer { // False | True => tubOrCancer [ 0.95, 0.02, // False 0.05, 0.98 ] // True }; boolean dyspnea dependson tubOrCancer, bronchitis { // False || True => tubOrCancer // False | True || False | True => bronchitis [ 0.90, 0.20, 0.30, 0.10, // False 0.10, 0.80, 0.70, 0.90 ] // True }; }
Using o3prm syntax for creating BayesNet¶
In [3]:
bn=gum.loadBN("./Asia.o3prm",verbose=False)
bn
Out[3]:
In [4]:
bn=gum.loadBN("./aSys.o3prm")
bn
Out[4]:
In [5]:
classpath="./ComplexPrinters"
filename="./ComplexPrinters/fr/lip6/printers/system.o3prm"
system="Work"
bn=gum.loadBN(filename,system=system,classpath=classpath)
In [6]:
# the inference will take place in a rather large junction tree
gnb.showJunctionTreeMap(bn,scaleClique=0.1,scaleSep=0.05,lenEdge=1.2,size="8!")
In [7]:
gnb.showInference(bn,size="25!")