Skip to content

Commit

Permalink
Rename all.edges.xx and orientations.prob data frames
Browse files Browse the repository at this point in the history
  • Loading branch information
franck-simon committed Aug 27, 2024
1 parent 39fe0bb commit 53bea53
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
18 changes: 9 additions & 9 deletions R/miic.R
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
#'
#' @return A \emph{miic-like} object that contains:
#' \itemize{
#' \item{\emph{all.edges.summary:} a data frame with information about the
#' \item{\emph{summary:} a data frame with information about the
#' relationship between relevant pair of variables.
#'
#' As returning the information on all possible pairs of variables could lead
Expand Down Expand Up @@ -400,7 +400,7 @@
#' retained edges. If the true graph is supplied in the \emph{true_edges}
#' parameter, 'P' becomes 'TP' (True Positive) or 'FP' (False Positive),
#' while 'N' becomes 'TN' (True Negative) or 'FN' (False Negative).
#' Note that, as the \emph{all.edges.summary} does not contain all the
#' Note that, as the \emph{summary} does not contain all the
#' removed edges, edges not present have to be considered as 'N'
#' and, if the true graph is supplied, as 'TN'.}
#' \item{ \emph{ai:} the contributing nodes found by the method which
Expand Down Expand Up @@ -508,7 +508,7 @@
#' the C++ core function. This data frame is used internally by MIIC to
#' produce the summary and contains all pairs of variables (\emph{x, y}). }
#'
#' \item{\emph{orientations.prob:} this data frame lists the orientation
#' \item{\emph{triples:} this data frame lists the orientation
#' probabilities of the two edges of all unshielded triples of the
#' reconstructed network with the structure: node1 -- mid-node -- node2:
#' \itemize{
Expand Down Expand Up @@ -859,7 +859,7 @@ miic <- function(input_data,
# Post-traitment
#
post_start = Sys.time()
res$all.edges.summary <- summarizeResults (
res$summary <- summarizeResults (
observations = input_data,
results = res,
true_edges = true_edges,
Expand All @@ -871,9 +871,9 @@ miic <- function(input_data,

if (!is.null (true_edges))
{
tp = sum (res$all.edges.summary$type == "TP")
fp = sum (res$all.edges.summary$type == "FP")
fn = sum (res$all.edges.summary$type == "FN")
tp = sum (res$summary$type == "TP")
fp = sum (res$summary$type == "FP")
fn = sum (res$summary$type == "FN")
precision = tp / (tp + fp)
recall = tp / (tp + fn)
fscore = (2 * (precision * recall) ) / (precision + recall)
Expand Down Expand Up @@ -907,13 +907,13 @@ miic <- function(input_data,
# The output of the reconstruction is the "raw" temporal graph, without
# edges identical by stationarity. To have the "real" temporal graph,
# we duplicate the edges using the stationary assumption and this "real"
# graph is stored the "all.edges.stationarity" data frame.
# graph is stored the "stationarity" data frame.
#
edges_dup_stat = tmiic_repeat_edges_over_history (res)
res$tmiic <- list (lagged_state_order = state_order,
lagged_black_box = black_box,
lagged_true_edges = true_edges,
all.edges.stationarity = edges_dup_stat)
stationarity = edges_dup_stat)
}

miic_end = Sys.time()
Expand Down
6 changes: 3 additions & 3 deletions R/miic.plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
export <- function (miic_res, method="igraph", pcor_palette=NULL,
display="compact", show_self_loops=TRUE)
{
if ( is.null(miic_res$all.edges.summary) )
if ( is.null(miic_res$summary) )
stop("The inferred network does not exist")
if ( (!is.null(method)) && (method != "igraph") )
stop("Method not supported")
Expand Down Expand Up @@ -180,14 +180,14 @@ export <- function (miic_res, method="igraph", pcor_palette=NULL,
#' plotting parameters and \code{\link[igraph]{layout}} for different layouts.
#-------------------------------------------------------------------------------
getIgraph <- function(miic_res, pcor_palette = NULL) {
if (is.null(miic_res$all.edges.summary)) {
if (is.null(miic_res$summary)) {
stop("The inferred network does not exist.")
}
if (!base::requireNamespace("igraph", quietly = TRUE)) {
stop("Package 'igraph' is required.")
}

summary = miic_res$all.edges.summary[miic_res$all.edges.summary$type %in% c('P', 'TP', 'FP'), ]
summary = miic_res$summary[miic_res$summary$type %in% c('P', 'TP', 'FP'), ]
if (nrow(summary) > 0) {
# Re-order summary so that all edges go from "x" to "y"
for(row in 1:nrow(summary)){
Expand Down
10 changes: 5 additions & 5 deletions R/miic.reconstruct.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ miic.reconstruct <- function(input_data = NULL,
)

# create the data frame of the structures after orientation
orientations_prob <- res$orientations.prob
orientations_prob <- res$triples

if (length(res$orientations.prob) > 0) {
if (length(res$triples) > 0) {
a <- length(orientations_prob[[1]])
b <- length(unlist(orientations_prob))
tmp <- unlist(res$orientations.prob)[1:a]
res1 <- unlist(res$orientations.prob)[(a + 1):b]
tmp <- unlist(res$triples)[1:a]
res1 <- unlist(res$triples)[(a + 1):b]
orientations_prob <- data.frame(matrix(
res1,
nrow = length(orientations_prob) - 1,
Expand All @@ -200,7 +200,7 @@ miic.reconstruct <- function(input_data = NULL,
orientations_prob[, c(8:9)] <- sapply(orientations_prob[, c(8:9)], as.numeric)
}
# update the returned matrix
res$orientations.prob <- orientations_prob
res$triples <- orientations_prob

res$interrupted <- FALSE

Expand Down
18 changes: 9 additions & 9 deletions R/tmiic.plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tmiic_getIgraph <- function (tmiic_res, display="compact",
show_self_loops=TRUE, pcor_palette=NULL)
{
if (display == "lagged")
tmiic_res$all.edges.summary = tmiic_res$tmiic$all.edges.stationarity
tmiic_res$summary = tmiic_res$tmiic$stationarity
else if (display != "raw")
tmiic_res <- tmiic_flatten_network (tmiic_res, flatten_mode=display,
keep_edges_on_same_node=show_self_loops)
Expand All @@ -86,8 +86,8 @@ tmiic_getIgraph <- function (tmiic_res, display="compact",
else
{
igraph::E(graph)$curved = FALSE
if ( "lag" %in% colnames(tmiic_res$all.edges.summary) )
igraph::E(graph)$label <- tmiic_res$all.edges.summary$lag
if ( "lag" %in% colnames(tmiic_res$summary) )
igraph::E(graph)$label <- tmiic_res$summary$lag
}
return(graph)
}
Expand All @@ -108,7 +108,7 @@ tmiic_getIgraph <- function (tmiic_res, display="compact",
#-----------------------------------------------------------------------------
tmiic_prepare_edges_for_plotting <- function (tmiic_res)
{
df_edges <- tmiic_res$all.edges.summary[tmiic_res$all.edges.summary$type %in% c('P', 'TP', 'FP'), ]
df_edges <- tmiic_res$summary[tmiic_res$summary$type %in% c('P', 'TP', 'FP'), ]
if (nrow(df_edges) <= 0)
df_edges$xy = character(0)
else
Expand Down Expand Up @@ -145,7 +145,7 @@ tmiic_prepare_edges_for_plotting <- function (tmiic_res)
}
}
}
tmiic_res$all.edges.summary <- df_edges
tmiic_res$summary <- df_edges
return (tmiic_res)
}

Expand All @@ -165,7 +165,7 @@ tmiic_prepare_edges_for_plotting <- function (tmiic_res)
#-------------------------------------------------------------------------------
tmiic_get_multiple_edges_for_plotting <- function (tmiic_res)
{
df_mult <- tmiic_res$all.edges.summary
df_mult <- tmiic_res$summary
if (nrow(df_mult) <= 0)
df_mult$count <- numeric(0)
else
Expand Down Expand Up @@ -434,7 +434,7 @@ tmiic_compute_row_layout_greedy <- function (tmiic_res)
# Filter out self edges, count and summarize edges regardless their lags
#
tmiic_flat <- tmiic_flatten_network (tmiic_res)
df_edges <- tmiic_flat$all.edges.summary
df_edges <- tmiic_flat$summary
df_edges <- df_edges[(df_edges$x != df_edges$y),]
if (nrow (df_edges) == 0)
df_edges$count <- integer()
Expand Down Expand Up @@ -560,7 +560,7 @@ tmiic_compute_row_layout_sugiyama <- function (tmiic_res)
# Filter out self edges, count and summarize edges regardless their lags
#
tmiic_flat <- tmiic_flatten_network(tmiic_res)
df_edges <- tmiic_flat$all.edges.summary
df_edges <- tmiic_flat$summary
df_edges <- df_edges[(df_edges$x != df_edges$y),]
if (nrow(df_edges) == 0)
df_edges$count <- integer()
Expand Down Expand Up @@ -953,7 +953,7 @@ plot.tmiic = function(x, method='igraph', pcor_palette=NULL,
# If we have a least on case with multiple edges between the same nodes,
# draw iteratively
#
df_edges <- x$all.edges.summary
df_edges <- x$summary
edges_colors_iter <- igraph::E(graph)$color
edges_labels_iter <- igraph::E(graph)$label
#
Expand Down
10 changes: 5 additions & 5 deletions R/tmiic.wrapper.R
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,12 @@ tmiic_flatten_network <- function (tmiic_res, flatten_mode="compact",
#
# Keep only edges found by miic
#
df_edges <- tmiic_res$all.edges.summary[tmiic_res$all.edges.summary$type %in% c('P', 'TP', 'FP'), ]
df_edges <- tmiic_res$summary[tmiic_res$summary$type %in% c('P', 'TP', 'FP'), ]
if (nrow(df_edges) <= 0)
{
if (flatten_mode != "drop")
df_edges$lag = numeric(0)
tmiic_res$all.edges.summary <- df_edges
tmiic_res$summary <- df_edges
return (tmiic_res)
}
#
Expand Down Expand Up @@ -539,7 +539,7 @@ tmiic_flatten_network <- function (tmiic_res, flatten_mode="compact",
{
if (flatten_mode == "drop")
df_edges$lag <- NULL
tmiic_res$all.edges.summary <- df_edges
tmiic_res$summary <- df_edges
return (tmiic_res)
}
#
Expand Down Expand Up @@ -645,7 +645,7 @@ tmiic_flatten_network <- function (tmiic_res, flatten_mode="compact",
#
# returns the tmiic structure where network summary has been flattened
#
tmiic_res$all.edges.summary <- df_edges
tmiic_res$summary <- df_edges
return (tmiic_res)
}

Expand All @@ -668,7 +668,7 @@ tmiic_repeat_edges_over_history <- function (tmiic_res)
{
# Consider only edges found by miic type = "P", "TP", "FP"
#
df_edges <- tmiic_res$all.edges.summary[tmiic_res$all.edges.summary$type %in% c('P', 'TP', 'FP'), ]
df_edges <- tmiic_res$summary[tmiic_res$summary$type %in% c('P', 'TP', 'FP'), ]
if (nrow(df_edges) <= 0)
return (df_edges)
#
Expand Down
4 changes: 2 additions & 2 deletions R/write.cytoscape.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ writeCytoscapeNetwork <- function(g, file, layout = NULL) {
stop("The file path is necessary")
}

if (is.null(g$all.edges.summary)) {
if (is.null(g$summary)) {
stop("The result of the miic execution is required")
}

summary <- g$all.edges.summary
summary <- g$summary
adj_matrix <- g$adj_matrix

if (is.null(layout)) {
Expand Down
6 changes: 3 additions & 3 deletions man/miic.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/reconstruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ List reconstruct(List input_data, List arg_list) {
_["proba_adj_matrix"] = getProbaAdjMatrix(environment.edges),
_["edges"] = getEdgesInfoTable(environment.edges,
environment.nodes),
_["orientations.prob"] = orientations,
_["triples"] = orientations,
_["time"] = vector<double>{time.init, time.iter, time.cut,
time.ori, time.getTotal()},
_["interrupted"] = false);
Expand Down

0 comments on commit 53bea53

Please sign in to comment.