Skip to content

Sensitivity analysis for Bayesian networks using credal networks

Creative Commons LicenseaGrUMinteractive online version

There are several sensitivity analysis frameworks for Bayesian networks. A fairly efficient method is certainly to use credal networks to do this analysis.

import pyagrum.credal_net as gum
import pyagrum.lib.notebook as gnb
bn = gum.fastBN("A->B->C<-D->E->F<-B")
gnb.flow.row(bn, gnb.getInference(bn))
anonymousBN A A B B A->B C C B->C F F B->F D D D->C E E D->E E->F
structs Inference in   0.37ms A 2026-10-27T15:22:15.551307 image/svg+xml Matplotlib v3.11.2, B 2026-10-27T15:22:15.570132 image/svg+xml Matplotlib v3.11.2, A->B C 2026-10-27T15:22:15.593015 image/svg+xml Matplotlib v3.11.2, B->C F 2026-10-27T15:22:15.660053 image/svg+xml Matplotlib v3.11.2, B->F D 2026-10-27T15:22:15.617366 image/svg+xml Matplotlib v3.11.2, D->C E 2026-10-27T15:22:15.642172 image/svg+xml Matplotlib v3.11.2, D->E E->F

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)

svg

cr.bnToCredal(1e-10, False, False)
cr.computeBinaryCPTMinMax()
print(cr)
A:Range([0,1])
<> : [[0.85829 , 0.14171]]
B:Range([0,1])

<A:0> : [[0.584418 , 0.415582] , [0.584393 , 0.415607]] <A:1> : [[0.689437 , 0.310563] , [0.689431 , 0.310569]]

C:Range([0,1])

<B:0|D:0> : [[0.327479 , 0.672521] , [0.325983 , 0.674017]] <B:1|D:0> : [[0.251309 , 0.748691] , [0.245061 , 0.754939]] <B:0|D:1> : [[0.595901 , 0.404099] , [0.595879 , 0.404121]] <B:1|D:1> : [[0.222965 , 0.777035] , [0.211442 , 0.788558]]

D:Range([0,1])
<> : [[0.189279 , 0.810721] , [0.101921 , 0.898079]]
E:Range([0,1])

<D:0> : [[0.298901 , 0.701099] , [0.296399 , 0.703601]] <D:1> : [[0.233778 , 0.766222] , [0.224742 , 0.775258]]

F:Range([0,1])

<E:0|B:0> : [[0.40629 , 0.59371] , [0.405899 , 0.594101]] <E:1|B:0> : [[0.245385 , 0.754615] , [0.238326 , 0.761674]] <E:0|B:1> : [[0.851654 , 0.148345]] <E:1|B:1> : [[0.182017 , 0.817983] , [0.132245 , 0.867755]]

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()
anonymousBN A A B B A->B C C B->C F F B->F D D D->C E E D->E E->F
structs Inference in   0.37ms A 2026-10-27T15:22:15.551307 image/svg+xml Matplotlib v3.11.2, B 2026-10-27T15:22:15.570132 image/svg+xml Matplotlib v3.11.2, A->B C 2026-10-27T15:22:15.593015 image/svg+xml Matplotlib v3.11.2, B->C F 2026-10-27T15:22:15.660053 image/svg+xml Matplotlib v3.11.2, B->F D 2026-10-27T15:22:15.617366 image/svg+xml Matplotlib v3.11.2, D->C E 2026-10-27T15:22:15.642172 image/svg+xml Matplotlib v3.11.2, D->E E->F
structs Inference in   0.25ms A 2026-10-27T15:22:16.243850 image/svg+xml Matplotlib v3.11.2, B 2026-10-27T15:22:16.260287 image/svg+xml Matplotlib v3.11.2, A->B C 2026-10-27T15:22:16.282404 image/svg+xml Matplotlib v3.11.2, B->C F 2026-10-27T15:22:16.343219 image/svg+xml Matplotlib v3.11.2, B->F D 2026-10-27T15:22:16.300580 image/svg+xml Matplotlib v3.11.2, D->C E 2026-10-27T15:22:16.323428 image/svg+xml Matplotlib v3.11.2, D->E E->F
noise=1
structs Inference in   0.12ms A 2026-10-27T15:22:16.517290 image/svg+xml Matplotlib v3.11.2, B 2026-10-27T15:22:16.541619 image/svg+xml Matplotlib v3.11.2, A->B C 2026-10-27T15:22:16.560604 image/svg+xml Matplotlib v3.11.2, B->C F 2026-10-27T15:22:16.630038 image/svg+xml Matplotlib v3.11.2, B->F D 2026-10-27T15:22:16.594791 image/svg+xml Matplotlib v3.11.2, D->C E 2026-10-27T15:22:16.612035 image/svg+xml Matplotlib v3.11.2, D->E E->F
noise=0.1
structs Inference in   0.26ms A 2026-10-27T15:22:16.799929 image/svg+xml Matplotlib v3.11.2, B 2026-10-27T15:22:16.823187 image/svg+xml Matplotlib v3.11.2, A->B C 2026-10-27T15:22:16.853169 image/svg+xml Matplotlib v3.11.2, B->C F 2026-10-27T15:22:16.913452 image/svg+xml Matplotlib v3.11.2, B->F D 2026-10-27T15:22:16.877091 image/svg+xml Matplotlib v3.11.2, D->C E 2026-10-27T15:22:16.894326 image/svg+xml Matplotlib v3.11.2, D->E E->F
noise=0.01
structs Inference in   1.25ms A 2026-10-27T15:22:17.187529 image/svg+xml Matplotlib v3.11.2, B 2026-10-27T15:22:17.213417 image/svg+xml Matplotlib v3.11.2, A->B C 2026-10-27T15:22:17.234604 image/svg+xml Matplotlib v3.11.2, B->C F 2026-10-27T15:22:17.299733 image/svg+xml Matplotlib v3.11.2, B->F D 2026-10-27T15:22:17.255194 image/svg+xml Matplotlib v3.11.2, D->C E 2026-10-27T15:22:17.278502 image/svg+xml Matplotlib v3.11.2, D->E E->F
noise=0.001
structs Inference in   0.86ms A 2026-10-27T15:22:17.454850 image/svg+xml Matplotlib v3.11.2, B 2026-10-27T15:22:17.475133 image/svg+xml Matplotlib v3.11.2, A->B C 2026-10-27T15:22:17.499841 image/svg+xml Matplotlib v3.11.2, B->C F 2026-10-27T15:22:17.563431 image/svg+xml Matplotlib v3.11.2, B->F D 2026-10-27T15:22:17.521412 image/svg+xml Matplotlib v3.11.2, D->C E 2026-10-27T15:22:17.544274 image/svg+xml Matplotlib v3.11.2, D->E E->F
noise=1e-10