From d4c11a89af83bea869e6d815b4f8c98f3176d7db Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Thu, 22 Dec 2022 13:12:40 +0100 Subject: [PATCH] Translated neighbors() --- R/neighbors.R | 13 ++++++------- R/triangulate.R | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/R/neighbors.R b/R/neighbors.R index 777ff7c..9192827 100644 --- a/R/neighbors.R +++ b/R/neighbors.R @@ -1,9 +1,8 @@ -neighbors <- function(add_mat, i) { - stop("needs translation") - # function ns = neighbors(adj_mat, i) - # % NEIGHBORS Find the parents and children of a node in a graph. - # % ns = neighbors(adj_mat, i) +neighbors <- function(adj_mat, i) { + # NEIGHBORS Find the parents and children of a node in a graph. + # ns <- neighbors(adj_mat, i) - # %ns = myunion(children(adj_mat, i), parents(adj_mat, i)); - # ns = find(adj_mat(i,:)); + # ns <- myunion(children(adj_mat, i), parents(adj_mat, i)) + ns <- find(adj_mat[i, ]) + return(ns) } diff --git a/R/triangulate.R b/R/triangulate.R index 145869e..7976fc1 100644 --- a/R/triangulate.R +++ b/R/triangulate.R @@ -14,7 +14,7 @@ triangulate <- function(G, order) { for (i in 1:n) { u <- order[i] U <- find(!eliminated)# uneliminated - nodes <- myintersect(neighbors(G, u), U)# look up neighbors in the partially filled - in graph # TODO: translate neighbors + nodes <- myintersect(neighbors(G, u), U)# look up neighbors in the partially filled - in graph nodes <- myunion(nodes, u)# the clique will always contain at least u # TODO: translate myunion G[nodes, nodes] <- 1# make them all connected to each other G <- setdiag(G, 0) # TODO: translate setdiag