我正在尝试重现我之前在 GeNie 中创建的网络,但我收到一个错误,即节点概率的某些条件概率分布的总和不等于 1。
# create empty BN
HazardNet <- empty.graph(nodes = c("scenario", "probability", "intensity", "hazard"))
HazardNet
# dependencies
HazardNet <- set.arc(HazardNet, from = "scenario", to = "probability")
HazardNet <- set.arc(HazardNet, from = "scenario", to = "intensity")
HazardNet <- set.arc(HazardNet, from = "intensity", to = "hazard")
HazardNet <- set.arc(HazardNet, from = "probability", to = "hazard")
HazardNet
# define states - global distribution
lmh <- c("low", "moderate", "high")
scenario.lv <- c("30 year", "100 year", "300year", "none")
intensity.lv <- lmh
probability.lv <- lmh
hazard.lv <- lmh
# create conditional probability tables
scenario.prob <- array(c(0.01, 0.03, 0.05, 0.91), dim = 4,
dimnames = list(scenario = scenario.lv))
probability.prob <- array(c(rep(1/3, 12)), dim = c(4,3),
dimnames = list(scenario =scenario.lv, probability = probability.lv))
intensity.prob <- array(c(0, 0.5, 0.5, 0, 0.3, 0.7, 0, 0.1, 0.9, 0.98, 0.019, 0.001), dim = c(3, 4),
dimnames = list(intensity = intensity.lv, scenario = scenario.lv ))
hazard.prob <- array(c(0, 1, 0, 0.5, 0.5, 0, 1, 0, 0, 0.5, 0.5, 0, 0, 1, 0, 0, 0.5, 0.5, 0, 0, 1, 0, 0, 1, 0, 0, 1 ),
dim = c(3, 3, 4),
dimnames = list( intensity = intensity.lv, hazard= hazard.lv, scenario = scenario.lv))
cpt <- list(scenario = scenario.prob, probability = probability.prob, intensity = intensity.prob, hazard = hazard.lv)
bn <- custom.fit(HazardNet, cpt)
我认为问题是节点场景?如果我没看错,我其他的cpt都很好。
我如何为具有 3 个状态的节点编码相等概率?
> scenario.prob
scenario
30 year 100 year 300year none
0.01 0.03 0.05 0.91
> probability.prob
probability
scenario low moderate high
30 year 0.3333333 0.3333333 0.3333333
100 year 0.3333333 0.3333333 0.3333333
300year 0.3333333 0.3333333 0.3333333
none 0.3333333 0.3333333 0.3333333
> intensity.prob
scenario
intensity 30 year 100 year 300year none
low 0.0 0.0 0.0 0.980
moderate 0.5 0.3 0.1 0.019
high 0.5 0.7 0.9 0.001
> hazard.prob
, , scenario = 30 year
hazard
intensity low moderate high
low 0 0.5 1
moderate 1 0.5 0
high 0 0.0 0
, , scenario = 100 year
hazard
intensity low moderate high
low 0.5 0 0.0
moderate 0.5 1 0.5
high 0.0 0 0.5
, , scenario = 300year
hazard
intensity low moderate high
low 0 0 0
moderate 0 0 0
high 1 1 1
, , scenario = none
hazard
intensity low moderate high
low 0 0.5 1
moderate 1 0.5 0
high 0 0.0 0