-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from astamm/nvd-class
Improved nvd constructor and added embedding to graph space
- Loading branch information
Showing
37 changed files
with
701 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ codecov.yml | |
^CRAN-RELEASE$ | ||
^data-raw$ | ||
^CRAN-SUBMISSION$ | ||
^vignettes/\.quarto$ | ||
^vignettes/*_files$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
.DS_Store | ||
inst/doc | ||
docs | ||
**/.quarto/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#' Graph Sample Embeddings | ||
#' | ||
#' A collection of functions to embed a sample of graphs into suitable spaces | ||
#' for further statistical analysis. | ||
#' | ||
#' @param obj An object of class [`nvd`] containing the sample of graphs. | ||
#' | ||
#' @return An object of class [`nvd`] containing the sample of graphs in graph space. | ||
#' | ||
#' @export | ||
#' @examples | ||
#' x <- nvd(sample_size = 5L, model = "gnp", n = 24L, p = 1/3) | ||
#' x <- push_to_graph_space(x) | ||
push_to_graph_space <- function(obj) { | ||
if (!is_nvd(obj)) | ||
cli::cli_abort("Input should be an object of class {.cls nvd}.") | ||
|
||
# Here we handle graphs of different orders by adding as many vertices as | ||
# necessary to match the order of the largest graph (a.k.a pushing graphs into | ||
# graph space structure). | ||
num_vertices <- purrr::map_int(obj, igraph::gorder) | ||
cli::cli_alert_info("Graphs have the following number of vertices: {num_vertices}") | ||
max_num_vertices <- max(num_vertices) | ||
n_chars <- nchar(max_num_vertices) | ||
obj <- purrr::map2(obj, num_vertices, \(g, n) { | ||
g <- dplyr::mutate( | ||
g, | ||
name = paste0("O", formatC(1:dplyr::n(), width = n_chars, flag = "0")) | ||
) | ||
n_extra <- max_num_vertices - n | ||
if (n_extra == 0) | ||
return(g) | ||
extra_nodes <- data.frame( | ||
name = paste0("V", formatC(1:n_extra, width = n_chars, flag = "0")) | ||
) | ||
tidygraph::bind_nodes(g, extra_nodes) | ||
}) | ||
|
||
obj | ||
} |
Oops, something went wrong.