2016-11-15 4 views

답변

0

내 시도는 modelstring 기능을 사용했습니다. 문자열을 가져온다. 내가 알고있는 노드를 제거한다. (손으로 직접한다.) 새로운 수정 된 문자열을 저장하고 문자열을 다시 model2network 명령으로 네트워크로 변환한다.

model.string <- modelstring(mymodel) 
model.string 
new.string <- "your string except the node you want to remove from the output above" 
new.model <- model2network(new.string) 

난 당신이 총 노드 수 (나는 22를 가지고)하지 않고 그냥 목록에서 몇 가지를 제거 할 경우 문제가 해결 것 같아요 여기에 명령의 순서는 다음과 같습니다.

희망 하시겠습니까?

0

파비올라의 답변이 많이 도움이됩니다.

여기서는 모델 문자열을 직접 변경하지 않고도 동일한 작업을 수행 할 수 있습니다.

질문에 대한 답변은 처음입니다. 형식에 관해서는 제발 쉬워주세요.

"net"은 내 네트워크이고 "TARGET_NODE"는 예상하고 싶은 노드입니다 (삭제하지 않기 위해 목록에 포함시키고 있음). "uniq"는 내 데이터 집합입니다.

model.string <- modelstring(net) 
final_nodes <- unique(c(unlist(list(net$arcs)), TARGET_NODE)) 
nodes_to_delete <- paste("\\[",setdiff(names(net$nodes), final_nodes),"]", sep = "") 
for (i in 1:length(nodes_to_delete)) {model.string <- gsub(nodes_to_delete[i], "", model.string)} 
net <- model2network(model.string) 

cols <- c(match(final_nodes, names(uniq))) 
uniq <- uniq[,cols] 
+0

멋진 Mery 작품! 잘 했어! –

+0

bnlearn에 내장 된 drop.arc()를 사용하십시오. 내 답변 [here] (https://stackoverflow.com/a/48676996/4549682)을 참조하십시오. – wordsforthewise

1

bnlearn가 내장되어 그냥이 만들어 arc operations (문서도 here). 이 함수는 또한 베이지안 네트워크가 비순환 (directed acyclic graphs 또는 DAG)해야하기 때문에 그래프의 사이클을 확인하는 이점이 있습니다. 그렇지 않으면 무한 루프가 발생하고 조건부 확률을 계산할 수 없기 때문입니다. 호를 추가 할 때 모델의 다른 위반을 확인하는 인수는 check.illegal입니다 (문서 참조).

그러나 그 예는 훌륭하지 않으며 문서도 아닙니다. 작업은 모델을 반환하므로 이전 모델을 반환 된 모델로 덮어 써야합니다. set.arc 세트 가장자리를 향하는 동안

data(learning.test) 
# model ends up the same every time here, but may want 
# to set random seed for reproducibility in other cases 
set.seed(42) 
model = tabu(learning.test) # tabu is a better algo than hc I think 
plot(model) 

model <- set.arc(model, "A", "F") 
plot(model) 
model <- drop.arc(model, "A", "F") 
plot(model) 

set.edge 세트는 에지 방향성이.