Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/cycles.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#' a specific cycle.
#'
#' @param graph The input graph.
#' @inheritParams rlang::args_dots_empty
#' @param mode Character constant specifying how to handle directed graphs.
#' `out` follows edge directions, `in` follows edges in the reverse direction,
#' and `all` ignores edge directions. Ignored in undirected graphs.
Expand Down
134 changes: 132 additions & 2 deletions R/embedding.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#' spectral embedding. Should be smaller than the number of vertices. The
#' largest `no`-dimensional non-zero singular values are used for the
#' spectral embedding.
#' @inheritParams rlang::args_dots_empty
#' @param weights Optional positive weight vector for calculating a weighted
#' embedding. If the graph has a `weight` edge attribute, then this is
#' used by default. In a weighted embedding, the edge weights are used instead
Expand Down Expand Up @@ -104,12 +105,47 @@
embed_adjacency_matrix <- function(
graph,
no,
...,
weights = NULL,
which = c("lm", "la", "sa"),
scaled = TRUE,
cvec = strength(graph, weights = weights) / (vcount(graph) - 1),
options = arpack_defaults()
) {
# BEGIN GENERATED ARG_HANDLE: embed_adjacency_matrix, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(
weights = weights,
which = which,
scaled = scaled,
cvec = cvec,
options = options
),
recover_new = c("weights", "which", "scaled", "cvec", "options"),
recover_old = c("weights", "which", "scaled", "cvec", "options"),
match_names = c("weights", "which", "scaled", "cvec", "options"),
match_to = c("weights", "which", "scaled", "cvec", "options"),
defaults = list(
weights = NULL,
which = c("lm", "la", "sa"),
scaled = TRUE,
cvec = strength(graph, weights = weights) / (vcount(graph) - 1),
options = arpack_defaults()
),
head_args = c("graph", "no"),
fn_name = "embed_adjacency_matrix"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

adjacency_spectral_embedding_impl(
graph = graph,
no = no,
Expand Down Expand Up @@ -203,6 +239,7 @@ dim_select <- function(sv) {
#' spectral embedding. Should be smaller than the number of vertices. The
#' largest `no`-dimensional non-zero singular values are used for the
#' spectral embedding.
#' @inheritParams rlang::args_dots_empty
#' @param weights Optional positive weight vector for calculating a weighted
#' embedding. If the graph has a `weight` edge attribute, then this is
#' used by default. For weighted embedding, edge weights are used instead
Expand Down Expand Up @@ -278,12 +315,47 @@ dim_select <- function(sv) {
embed_laplacian_matrix <- function(
graph,
no,
...,
weights = NULL,
which = c("lm", "la", "sa"),
type = c("default", "D-A", "DAD", "I-DAD", "OAP"),
scaled = TRUE,
options = arpack_defaults()
) {
# BEGIN GENERATED ARG_HANDLE: embed_laplacian_matrix, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(
weights = weights,
which = which,
type = type,
scaled = scaled,
options = options
),
recover_new = c("weights", "which", "type", "scaled", "options"),
recover_old = c("weights", "which", "type", "scaled", "options"),
match_names = c("weights", "which", "type", "scaled", "options"),
match_to = c("weights", "which", "type", "scaled", "options"),
defaults = list(
weights = NULL,
which = c("lm", "la", "sa"),
type = c("default", "D-A", "DAD", "I-DAD", "OAP"),
scaled = TRUE,
options = arpack_defaults()
),
head_args = c("graph", "no"),
fn_name = "embed_laplacian_matrix"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

laplacian_spectral_embedding_impl(
graph = graph,
no = no,
Expand All @@ -307,6 +379,7 @@ embed_laplacian_matrix <- function(
#'
#' @param dim Integer scalar, the dimension of the random vectors.
#' @param n Integer scalar, the sample size.
#' @inheritParams rlang::args_dots_empty
#' @param radius Numeric scalar, the radius of the sphere to sample.
#' @param positive Logical, whether to sample from the positive orthant
#' of the sphere.
Expand All @@ -324,7 +397,35 @@ embed_laplacian_matrix <- function(
#' sum(x^2)
#' })
#' vec.norm
sample_sphere_surface <- function(dim, n = 1, radius = 1, positive = TRUE) {
sample_sphere_surface <- function(
dim,
n = 1,
...,
radius = 1,
positive = TRUE
) {
# BEGIN GENERATED ARG_HANDLE: sample_sphere_surface, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(radius = radius, positive = positive),
recover_new = c("radius", "positive"),
recover_old = c("radius", "positive"),
match_names = c("radius", "positive"),
match_to = c("radius", "positive"),
defaults = list(radius = 1, positive = TRUE),
head_args = c("dim", "n"),
fn_name = "sample_sphere_surface"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

# Use the _impl function
sample_sphere_surface_impl(
dim = dim,
Expand All @@ -345,6 +446,7 @@ sample_sphere_surface <- function(dim, n = 1, radius = 1, positive = TRUE) {
#'
#' @param dim Integer scalar, the dimension of the random vectors.
#' @param n Integer scalar, the sample size.
#' @inheritParams rlang::args_dots_empty
#' @param radius Numeric scalar, the radius of the sphere to sample.
#' @param positive Logical, whether to sample from the positive orthant
#' of the sphere.
Expand All @@ -362,7 +464,35 @@ sample_sphere_surface <- function(dim, n = 1, radius = 1, positive = TRUE) {
#' sum(x^2)
#' })
#' vec.norm
sample_sphere_volume <- function(dim, n = 1, radius = 1, positive = TRUE) {
sample_sphere_volume <- function(
dim,
n = 1,
...,
radius = 1,
positive = TRUE
) {
# BEGIN GENERATED ARG_HANDLE: sample_sphere_volume, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(radius = radius, positive = positive),
recover_new = c("radius", "positive"),
recover_old = c("radius", "positive"),
match_names = c("radius", "positive"),
match_to = c("radius", "positive"),
defaults = list(radius = 1, positive = TRUE),
head_args = c("dim", "n"),
fn_name = "sample_sphere_volume"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

# Use the _impl function
sample_sphere_volume_impl(
dim = dim,
Expand Down
83 changes: 82 additions & 1 deletion R/hrg.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ NULL
#' @param hrg A hierarchical random graph model, in the form of an
#' `igraphHRG` object. `fit_hrg()` allows this to be `NULL`, in
#' which case a random starting point is used for the fitting.
#' @inheritParams rlang::args_dots_empty
#' @param start Logical, whether to start the fitting/sampling from the
#' supplied `igraphHRG` object, or from a random starting point.
#' @param steps The number of MCMC steps to make. If this is zero, then the
Expand Down Expand Up @@ -232,7 +233,35 @@ NULL
#' predict_edges(g2)
#' @export
#' @family hierarchical random graph functions
fit_hrg <- function(graph, hrg = NULL, start = FALSE, steps = 0) {
fit_hrg <- function(
graph,
hrg = NULL,
...,
start = FALSE,
steps = 0
) {
# BEGIN GENERATED ARG_HANDLE: fit_hrg, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(start = start, steps = steps),
recover_new = c("start", "steps"),
recover_old = c("start", "steps"),
match_names = c("start", "steps"),
match_to = c("start", "steps"),
defaults = list(start = FALSE, steps = 0),
head_args = c("graph", "hrg"),
fn_name = "fit_hrg"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

# Argument checks
ensure_igraph(graph)
if (is.null(hrg)) {
Expand Down Expand Up @@ -281,6 +310,7 @@ fit_hrg <- function(graph, hrg = NULL, start = FALSE, steps = 0) {
#' `igraphHRG` object. `consensus_tree()` allows this to be
#' `NULL` as well, then a HRG is fitted to the graph first, from a
#' random starting point.
#' @inheritParams rlang::args_dots_empty
#' @param start Logical, whether to start the fitting/sampling from the
#' supplied `igraphHRG` object, or from a random starting point.
#' @param num.samples Number of samples to use for consensus generation or
Expand All @@ -307,9 +337,32 @@ fit_hrg <- function(graph, hrg = NULL, start = FALSE, steps = 0) {
consensus_tree <- function(
graph,
hrg = NULL,
...,
start = FALSE,
num.samples = 10000
) {
# BEGIN GENERATED ARG_HANDLE: consensus_tree, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(start = start, num.samples = num.samples),
recover_new = c("start", "num.samples"),
recover_old = c("start", "num.samples"),
match_names = c("start", "num.samples"),
match_to = c("start", "num.samples"),
defaults = list(start = FALSE, num.samples = 10000),
head_args = c("graph", "hrg"),
fn_name = "consensus_tree"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

hrg_consensus_impl(
graph = graph,
hrg = hrg,
Expand Down Expand Up @@ -403,6 +456,7 @@ sample_hrg <- function(hrg) {
#' `igraphHRG` object. `predict_edges()` allow this to be
#' `NULL` as well, then a HRG is fitted to the graph first, from a
#' random starting point.
#' @inheritParams rlang::args_dots_empty
#' @param start Logical, whether to start the fitting/sampling from the
#' supplied `igraphHRG` object, or from a random starting point.
#' @param num.samples Number of samples to use for consensus generation or
Expand Down Expand Up @@ -448,10 +502,37 @@ sample_hrg <- function(hrg) {
predict_edges <- function(
graph,
hrg = NULL,
...,
start = FALSE,
num.samples = 10000,
num.bins = 25
) {
# BEGIN GENERATED ARG_HANDLE: predict_edges, do not edit, see tools/generate-migrations.R
if (...length() > 0L) {
.arg_handle <- migrate_recover_args(
list(...),
current = list(
start = start,
num.samples = num.samples,
num.bins = num.bins
),
recover_new = c("start", "num.samples", "num.bins"),
recover_old = c("start", "num.samples", "num.bins"),
match_names = c("start", "num.samples", "num.bins"),
match_to = c("start", "num.samples", "num.bins"),
defaults = list(start = FALSE, num.samples = 10000, num.bins = 25),
head_args = c("graph", "hrg"),
fn_name = "predict_edges"
)
list2env(.arg_handle$values, environment())
lifecycle::deprecate_soft(
"3.0.0",
what = I(.arg_handle$what),
details = .arg_handle$details
)
}
# END GENERATED ARG_HANDLE

res <- hrg_predict_impl(
graph = graph,
hrg = hrg,
Expand Down
4 changes: 3 additions & 1 deletion man/consensus_tree.Rd

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

3 changes: 3 additions & 0 deletions man/embed_adjacency_matrix.Rd

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

3 changes: 3 additions & 0 deletions man/embed_laplacian_matrix.Rd

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

Loading
Loading