簡體   English   中英

BNLearn:如何將高斯貝葉斯網絡的估計參數與其條件結構合並?

[英]BNLearn: How to merge the estimating parameters of a Gaussian Bayesian network with its conditional structure?

我使用iamb函數定義了高斯貝葉斯網絡的結構,然后使用bn.fit估計了節點的系數。


圖書館

library(bnlearn)

數據

{  C       E       G       N       V       W
48.83   51.48   42.64   54.1    42.96   41.96
48.85   73.43   40.97   60.07   65.29   48.96
67.01   71.1    52.52   51.64   63.22   62.03
37.83   49.33   56.15   49.01   47.75   38.77
55.3    49.27   63.55   54.62   60.57   56.66
56.12   48.72   66.02   43.95   55.54   52.39}

# Definition of mandatory and forbidden nodes - here the white list
wl = data.frame(from = c("E","G","V","W","N"), to = c("V", "V","W","C","C"))

# Definition of the constrained network
network <- iamb(Data, test = "cor", whitelist = wl)

# Estimation of the coefficients according to the structure of the network
est.para <- bn.fit(network, data = Data)

問題是est.para是一個列表,而不是可以繪制的GBN等。 我想知道如何合並網絡和估計的參數?

如果要使某些網絡圖顯示除連接之外的其他信息,則可以使用strength.plot 按照您的示例:

library(Rgraphviz)

strength <- arc.strength(network, Data)
strength.plot(network, strength, shape = "ellipse")

如果絕對需要使用GBN est.para參數的結果,則可以使用graphviz.plot參數突出顯示邊緣和節點(可以使用edgeRenderInfonodeRenderInfo )。 僅作為示例,您可以使用參數選擇邊緣的寬度:

library(data.table) 

plot <- graphviz.plot(network, shape = "ellipse")

arc.sizes <- data.table(network$arcs)
arc.sizes[, edge.name := paste0(arc.sizes$from, "~", arc.sizes$to)]
arc.sizes[, param := abs(est.para[[to]]$coefficients[[from]]), by = .(from, to)]
arc.sizes[, lwd := 5*((param - min(param))/(max(param) - min(param)))]

lwd <- as.vector(arc.sizes$lwd)
names(lwd) <- arc.sizes$edge.name
edgeRenderInfo(plot) <- list(lwd = lwd)

renderGraph(plot)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM