Sensitivity analysis for Bayesian networks using credal networks
![]() | ![]() |
There are several sensitivity analysis frameworks for Bayesian networks. A fairly efficient method is certainly to use credal networks to do this analysis.
Creating a Bayesian network
Section titled “Creating a Bayesian network”import pyagrum as gumimport pyagrum.lib.notebook as gnbbn = gum.fastBN("A->B->C<-D->E->F<-B")gnb.flow.row(bn, gnb.getInference(bn))Building a credal network from a BN
Section titled “Building a credal network from a BN”It is easy to build a credal network from a Bayesian network by indicating the ‘noise’ on each parameter.
cr = gum.CredalNet(bn, bn)gnb.show(cr)cr.bnToCredal(1e-10, False, False)cr.computeBinaryCPTMinMax()print(cr)A:Range([0,1])<> : [[0.960602 , 0.0393976]]
B:Range([0,1])<A:0> : [[0.656802 , 0.343198] , [0.656793 , 0.343207]] <A:1> : [[0.929183 , 0.0708164]]
C:Range([0,1])<B:0|D:0> : [[0.796228 , 0.203772] , [0.796227 , 0.203773]] <B:1|D:0> : [[0.296307 , 0.703693] , [0.293682 , 0.706318]] <B:0|D:1> : [[0.866449 , 0.13355]] <B:1|D:1> : [[0.365068 , 0.634932] , [0.364288 , 0.635712]]
D:Range([0,1])<> : [[0.296323 , 0.703677] , [0.293699 , 0.706301]]
E:Range([0,1])<D:0> : [[0.216518 , 0.783482] , [0.203086 , 0.796914]] <D:1> : [[0.314793 , 0.685207] , [0.312918 , 0.687082]]
F:Range([0,1])<E:0|B:0> : [[0.439406 , 0.560594] , [0.439178 , 0.560822]] <E:1|B:0> : [[0.56696 , 0.43304] , [0.566927 , 0.433073]] <E:0|B:1> : [[0.608625 , 0.391375] , [0.00899224 , 0.991008]] <E:1|B:1> : [[0.887344 , 0.112656]]
Testing difference hypothesis about the global precision on the parameters
Section titled “Testing difference hypothesis about the global precision on the parameters”We can therefore easily conduct a sensitivity analysis based on an assumption of error on all the parameters of the network.
def showNoisy(bn, beta): cr = gum.CredalNet(bn, bn) cr.bnToCredal(beta, False, False) cr.computeBinaryCPTMinMax() ielbp = gum.CNLoopyPropagation(cr) return gnb.getInference(cr, engine=ielbp)for eps in [1, 1e-1, 1e-2, 1e-3, 1e-10]: gnb.flow.add(showNoisy(bn, eps), caption=f"noise={eps}")gnb.flow.display()
