From 17a5ff66d6b588a4b2d6089f392c162bdc2f97c6 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Thu, 22 Dec 2022 08:29:50 +0100 Subject: [PATCH] Translated findCliques() + subfunctions --- NAMESPACE | 1 + R/cliques_to_jtree.R | 1 + R/elim_order.R | 1 + R/findCliques.R | 46 +++++++++++++++++++++++++++++++++++++++++++- R/myintersect.R | 1 + R/triangulate.R | 1 + 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 R/cliques_to_jtree.R create mode 100644 R/elim_order.R create mode 100644 R/myintersect.R create mode 100644 R/triangulate.R diff --git a/NAMESPACE b/NAMESPACE index 3b8b822..f0dc387 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -74,3 +74,4 @@ importFrom(stats,runif) importFrom(stats,sd) importFrom(utils,read.delim) importFrom(vcfR,read.vcfR) +importFrom(zeallot,"%<-%") diff --git a/R/cliques_to_jtree.R b/R/cliques_to_jtree.R new file mode 100644 index 0000000..6b3fd18 --- /dev/null +++ b/R/cliques_to_jtree.R @@ -0,0 +1 @@ +cliques_to_jtree <- function(cliques, ns) {} diff --git a/R/elim_order.R b/R/elim_order.R new file mode 100644 index 0000000..fe89c56 --- /dev/null +++ b/R/elim_order.R @@ -0,0 +1 @@ +elim_order <- function(G, node_sizes) {} diff --git a/R/findCliques.R b/R/findCliques.R index eea6d3c..4ff1d8b 100644 --- a/R/findCliques.R +++ b/R/findCliques.R @@ -1,3 +1,47 @@ findCliques <- function(M) { - # TODO: translate findCliques() from matlab/spatial/findCliques.m + # Muuttaa graafin M kolmioituvaksi ja laskee siitה klikit ja + # separaattorit. + # Hyצdynnetההn Kevin Murphyn algoritmeja Graph Theory toolboxista. + # Pהivitetty 12.8.2005 + order <- elim_order(M, ones(length(M))) # TODO: translate from findCliques.m + c(G, cliques) %<-% triangulate(M, order) # TODO: translate from findCliques.m + c(jtree, root) %<-% cliques_to_jtree(cliques, ones(length(M))) # TODO: translate from findCliques.m + ncliq <- length(cliques) + separators <- cell(ncliq - 1, 1) # n - solmuisessa puussa n - 1 viivaa + + jono <- zeros(length(ncliq)) + jono[1] <- root + i <- 1 + pointer <- 2 # Seuraava tyhjה paikka + + while (!is.null(find(jono != 0))) { # Puun leveyssuuntainen lהpikהynti) { + lapset <- find(jtree[jono[i], ] != 0) + jtree[, jono[i]] <- 0 # Klikki kהsitelty + jono[pointer:(pointer + length(lapset) - 1)] <- lapset + for (j in 1:length(lapset)) { + ehdokas <- myintersect(cliques[[jono[i]]], cliques[[lapset[j]]]) + kelpaa <- 1 + for (k in 1:(pointer + j - 3)) { + # Tutkitaan, ettה separaattoriehdokasta ei vielה kהsitelty + if (ehdokas == separators[[k]]) { + kelpaa <- 0 + } + } + if (kelpaa) { + separators[[pointer + j - 2]] <- ehdokas + } + } + jono[i] <- 0 + pointer <- pointer + length(lapset) + i <- i + 1 + } + notEmpty <- zeros(ncliq - 1, 1) + for (i in 1:(ncliq - 1)) { + if (!is.null(separators[[i]])) { + notEmpty[i] <- 1 + } + } + notEmpty <- find(notEmpty == 1) + separators <- separators(notEmpty) + return(list("cliques" = cliques, "separators" = separators, "G" = G)) } diff --git a/R/myintersect.R b/R/myintersect.R new file mode 100644 index 0000000..b2c19f1 --- /dev/null +++ b/R/myintersect.R @@ -0,0 +1 @@ +myintersect <- function(A, B) {} diff --git a/R/triangulate.R b/R/triangulate.R new file mode 100644 index 0000000..0280b21 --- /dev/null +++ b/R/triangulate.R @@ -0,0 +1 @@ +triangulate <- function(G, order) {}