Click here to hide/show the list of notebooks.
  pyAgrum on notebooks   pyAgrum jupyter
☰  aggregators 
pyAgrum 0.15.1   
Zipped notebooks   
generation: 2019-06-16 19:06  

Creative Commons License
This pyAgrum's notebook is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Aggregators

Aggregators are special type of nodes that includes a generic CPT for any numbers of parents.

pyAgrum proposes a list of such aggregators. Some of then are used below.

In [1]:
import numpy as np

import pyAgrum as gum
import pyAgrum.lib.notebook as gnb
In [2]:
bn=gum.BayesNet()
l=[bn.add(gum.RangeVariable(item,item,0,15)) for item in ["a","b","c","d","e","f"]]
In [3]:
nmax=bn.addMAX(gum.RangeVariable("MAX","MAX",0,15))
bn.addArc(l[0],nmax)
bn.addArc(l[1],nmax)
bn.addArc(l[2],nmax)

nmin=bn.addMIN(gum.RangeVariable("MIN","MIN",0,15))
bn.addArc(l[3],nmin)
bn.addArc(l[4],nmin)
bn.addArc(l[5],nmin)

nampl=bn.addAMPLITUDE(gum.RangeVariable("DELTA","DELTA",0,15))
bn.addArc(nmax,nampl)
bn.addArc(nmin,nampl)

nmedian=bn.addMEDIAN(gum.RangeVariable("MEDIAN","MEDIAN",0,15))
for n in [l[0],l[1],l[2],l[3]]:
    bn.addArc(n,nmedian)
#potential for median has a size : 16^5=2^20 double !

nexists=bn.addEXISTS(gum.LabelizedVariable("EXISTS_0","EXISTS"),0)
bn.addArc(l[0],nexists)
bn.addArc(l[1],nexists)
bn.addArc(l[2],nexists)

nforall=bn.addFORALL(gum.LabelizedVariable("FORALL_1","FORALL"),1)
bn.addArc(l[3],nforall)
bn.addArc(l[4],nforall)
bn.addArc(l[5],nforall)

ncount=bn.addCOUNT(gum.RangeVariable("COUNT_1","COUNT_1,",0,3),1)
bn.addArc(l[0],ncount)
bn.addArc(l[1],ncount)
bn.addArc(l[2],ncount)
In [4]:
for nod in l:
    bn.cpt(nod)[:]=np.ones(16)/16
gnb.showInference(bn,size="12")
structs Inference in 273.42ms a MAX a->MAX MEDIAN a->MEDIAN EXISTS_0 a->EXISTS_0 COUNT_1 a->COUNT_1 b b->MAX b->MEDIAN b->EXISTS_0 b->COUNT_1 c c->MAX c->MEDIAN c->EXISTS_0 c->COUNT_1 d MIN d->MIN d->MEDIAN FORALL_1 d->FORALL_1 e e->MIN e->FORALL_1 f f->MIN f->FORALL_1 DELTA MAX->DELTA MIN->DELTA
In [5]:
# if I know that the median is between 8 and 13 ...
gnb.showInference(bn,evs={'MEDIAN':[0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0]},size="12")
structs Inference in 301.26ms a MAX a->MAX MEDIAN a->MEDIAN EXISTS_0 a->EXISTS_0 COUNT_1 a->COUNT_1 b b->MAX b->MEDIAN b->EXISTS_0 b->COUNT_1 c c->MAX c->MEDIAN c->EXISTS_0 c->COUNT_1 d MIN d->MIN d->MEDIAN FORALL_1 d->FORALL_1 e e->MIN e->FORALL_1 f f->MIN f->FORALL_1 DELTA MAX->DELTA MIN->DELTA
In [6]:
# if the roots do not have uniform but random distribution
for nod in l:
    bn.generateCPT(nod)
   
gnb.showInference(bn,size="12")
structs Inference in 292.75ms a MAX <