Skip to content

Commit

Permalink
Merge pull request #19 from astamm/nvd-class
Browse files Browse the repository at this point in the history
Improved nvd constructor and added embedding to graph space
  • Loading branch information
astamm authored Dec 11, 2024
2 parents 19fb496 + 0078f6f commit 05ac9d1
Show file tree
Hide file tree
Showing 37 changed files with 701 additions and 421 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ codecov.yml
^CRAN-RELEASE$
^data-raw$
^CRAN-SUBMISSION$
^vignettes/\.quarto$
^vignettes/*_files$
15 changes: 11 additions & 4 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check
name: R-CMD-check.yaml

permissions: read-all

jobs:
R-CMD-check:
Expand All @@ -29,7 +30,7 @@ jobs:
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -41,9 +42,15 @@ jobs:

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
extra-packages: |
any::rcmdcheck
any::devtools
needs: check

- run: devtools::install(build_vignettes = FALSE)
shell: Rscript {0}

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
9 changes: 5 additions & 4 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown
name: pkgdown.yaml

permissions: read-all

jobs:
pkgdown:
Expand All @@ -22,7 +23,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

Expand All @@ -41,7 +42,7 @@ jobs:

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
uses: JamesIves/github-pages-deploy-action@v4.5.0
with:
clean: false
branch: gh-pages
Expand Down
27 changes: 19 additions & 8 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage
name: test-coverage.yaml

permissions: read-all

jobs:
test-coverage:
Expand All @@ -15,36 +16,46 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
extra-packages: any::covr, any::xml2
needs: coverage

- name: Test coverage
run: |
covr::codecov(
cov <- covr::package_coverage(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package")
)
covr::to_cobertura(cov)
shell: Rscript {0}

- uses: codecov/codecov-action@v4
with:
# Fail if error if not on PR, or if on PR and token is given
fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }}
file: ./cobertura.xml
plugin: noop
disable_search: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.DS_Store
inst/doc
docs
**/.quarto/
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ Imports:
tsne,
umap,
furrr,
rgeomstats
RoxygenNote: 7.2.3
rgeomstats,
tidygraph
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
URL: https://astamm.github.io/nevada/,
https://github.com/astamm/nevada/
BugReports: https://github.com/astamm/nevada/issues/
Suggests:
knitr,
rmarkdown,
covr
VignetteBuilder: knitr
covr,
quarto
VignetteBuilder: quarto
LinkingTo: Rcpp, RcppArmadillo
6 changes: 5 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export(edge_count_global_variables)
export(generate_sigma_algebra)
export(ipro_frobenius)
export(nvd)
export(play_binomial)
export(play_exponential)
export(play_poisson)
export(power2)
export(push_to_graph_space)
export(rbinom_network)
export(repr_adjacency)
export(repr_graphon)
Expand All @@ -27,7 +31,6 @@ export(repr_modularity)
export(repr_nvd)
export(rexp_network)
export(rpois_network)
export(rsbm)
export(sample2_sbm)
export(stat_generalized_edge_count)
export(stat_original_edge_count)
Expand All @@ -46,5 +49,6 @@ importFrom(ggplot2,autoplot)
importFrom(graphics,plot)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
importFrom(rlang,`:=`)
importFrom(tibble,tibble)
useDynLib(nevada, .registration = TRUE)
16 changes: 8 additions & 8 deletions R/distances.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#' Root-Euclidean distance can used only with the laplacian matrix
#' representation.
#'
#' @param x An [`igraph::igraph`] object or a matrix representing an underlying
#' @param x A [`tidygraph::tbl_graph`] object or a matrix representing an underlying
#' network.
#' @param y An [`igraph::igraph`] object or a matrix representing an underlying
#' @param y A [`tidygraph::tbl_graph`] object or a matrix representing an underlying
#' network. Should have the same number of vertices as `x`.
#' @param representation A string specifying the desired type of representation,
#' among: \code{"adjacency"}, \code{"laplacian"}, \code{"modularity"} or
Expand Down Expand Up @@ -189,9 +189,9 @@ ipro_frobenius <- function(x, y, representation = "laplacian") {
#' elements of the two samples put together. The cardinality of the fist sample
#' is denoted by \eqn{n_1} and that of the second one is denoted by \eqn{n_2}.
#'
#' @param x A [`base::list`] of [`igraph::igraph`] objects or matrix
#' @param x A [`base::list`] of [`tidygraph::tbl_graph`] objects or matrix
#' representations of underlying networks from a given first population.
#' @param y A [`base::list`] of [`igraph::igraph`] objects or matrix
#' @param y A [`base::list`] of [`tidygraph::tbl_graph`] objects or matrix
#' representations of underlying networks from a given second population.
#' @param representation A string specifying the desired type of representation,
#' among: \code{"adjacency"}, \code{"laplacian"}, \code{"modularity"} or
Expand All @@ -215,10 +215,10 @@ ipro_frobenius <- function(x, y, representation = "laplacian") {
#' @export
#'
#' @examples
#' gnp_params <- list(p = 1/3)
#' k_regular_params <- list(k = 8L)
#' x <- nvd(model = "gnp", n = 10L, model_params = gnp_params)
#' y <- nvd(model = "k_regular", n = 10L, model_params = k_regular_params)
#' gnp_params <- list(n = 24L, p = 1/3)
#' degree_params <- list(out_degree = rep(2, 24L), method = "configuration")
#' x <- nvd(sample_size = 10L, model = "gnp", !!!gnp_params)
#' y <- nvd(sample_size = 10L, model = "degree", !!!degree_params)
#' dist_nvd(x, y, "adjacency", "spectral")
dist_nvd <- function(x,
y = NULL,
Expand Down
40 changes: 40 additions & 0 deletions R/embeddings.R
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
}
Loading

0 comments on commit 05ac9d1

Please sign in to comment.