Skip to content

Commit 46d1d35

Browse files
committed
subnetwork_templates() now has a subset= argument that enables a subset of constituent networks to be extracted prior to propagating the specified %ergmlhs% settings.
1 parent 1e3307e commit 46d1d35

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

R/InitErgmTerm.dgw_sp.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ no_layer_err <- function(instead){
6767

6868
wrap_ergm_sp_call <- function(ergm_name, nw, a, has_base, d0 = FALSE, cache.sp = TRUE, ...) {
6969
# A "representative" layer network.
70-
nw1 <- subnetwork_templates(nw)[[1]]
70+
nw1 <- subnetwork_templates(nw, copy.ergmlhs = c())[[1]]
7171

7272
# Construct and call the ergm term with only the arguments it
7373
# supports.

R/InitErgmTerm.multilayer.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,13 @@ InitErgmTerm.L <- function(nw, arglist, ...){
7979

8080
assert_combined_network(nw, "Layer")
8181

82-
nwl <- subnetwork_templates(nw, copy.ergmlhs = c())
83-
8482
Ls <- ergm_LayerLogics(a$Ls, nw)
8583

8684
w <- rep(1, length(Ls))
8785
have.LHS <- lengths(Ls) == 3
8886
w[have.LHS] <- as.numeric(sapply(lapply(Ls[have.LHS], "[[", 2), eval, environment(Ls[[1]])))
8987

90-
nw1 <- nwl[[1]]
88+
nw1 <- subnetwork_templates(nw, copy.ergmlhs = c())[[1L]]
9189
m <- ergm_model(a$formula, nw1, ..., offset.decorate=FALSE)
9290

9391
## FIXME: Is this consistent with extended state API, or do we need to have a different "model" for each layer?

R/InitErgmTerm.multinet.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,8 @@ InitErgmTerm.N <- function(nw, arglist, ..., N.compact_stats=TRUE, .combiner = "
162162

163163
auxiliaries <- base_env(~.subnets)
164164

165-
nwl <- subnetwork_templates(nw)
166-
nwnames <- names(nwl)
167-
nn <- length(nwl)
168165
nattrs <- as_tibble(nw, unit="networks")
166+
nn <- nrow(nattrs)
169167

170168
lmi <- get_lminfo(nattrs, lm=a$lm, subset=a$subset, contrasts=a$contrasts, offset=a$offset, weights=a$weights)
171169

@@ -175,7 +173,7 @@ InitErgmTerm.N <- function(nw, arglist, ..., N.compact_stats=TRUE, .combiner = "
175173
weights <- lmi$weights
176174
offset <- lmi$offset
177175
nm <- sum(subset)
178-
nwl <- nwl[subset]
176+
nwl <- subnetwork_templates(nw, subset = subset)
179177
rm(lmi)
180178

181179
ms <- lapply(nwl, function(nw1){

R/combine.networks.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,16 @@ ergm.multi_combiner <- local({
252252
#' This utility uncombines a [combine_networks()] network using subnetwork cache (which contains only empty networks). It is used primarily by initialisation functions.
253253
#'
254254
#' @param nw see [uncombine_network()].
255-
#'
256-
#' @param copy.ergmlhs a character vector of [`%ergmlhs%`] settings that are to be copied into the constituent networks.
255+
#' @param copy.ergmlhs a character vector of [`%ergmlhs%`] settings
256+
#' that are to be copied into the constituent networks.
257+
#' @param subset indices of the constituent networks to return.
257258
#'
258259
#' @return A list of [`network`]s.
259260
#'
260261
#' @keywords internal
261262
#' @export
262-
subnetwork_templates <- function(nw, copy.ergmlhs = c("response")){
263-
nwl <- uncombine_network(nw, populate = FALSE)
263+
subnetwork_templates <- function(nw, copy.ergmlhs = c("response"), subset = TRUE) {
264+
nwl <- uncombine_network(nw, populate = FALSE)[subset]
264265

265266
if (length(copy.ergmlhs)) nwl <- map(nwl, function(nw1) {
266267
for (name in copy.ergmlhs) nw1%ergmlhs%name <- nw%ergmlhs%name

man/subnetwork_templates.Rd

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)