Skip to content

Commit e443eea

Browse files
committed
Extracted upper-triangular RLEBDM construction code out of the upper_tri constraint and into its own function upper_tri_rlebdm().
1 parent 89b4a0c commit e443eea

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ergm.multi
2-
Version: 0.3.0-4254
3-
Date: 2026-03-14
2+
Version: 0.3.0-4260
3+
Date: 2026-03-18
44
Title: Fit, Simulate and Diagnose Exponential-Family Models for Multiple or Multilayer Networks
55
Authors@R: c(person(c("Pavel", "N."), "Krivitsky", role=c("aut","cre"), email="pavel@statnet.org", comment=c(ORCID="0000-0002-9101-3362")),
66
person(c("Mark", "S."), "Handcock", role=c("ctb"), email="handcock@stat.ucla.edu"),

R/InitErgmConstraint.R

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,28 @@
2121
#
2222
##########################################################################################
2323

24+
# Extracted, since it's useful elsewhere; which is a logical vector
25+
# indicating which nodes should enforce the constraint. This
26+
# constraint
27+
upper_tri_rlebdm <- function(n, which = rep.int(TRUE, n)) {
28+
# The pattern is TRUE,...,TRUE,FALSE,...,FALSE for those
29+
# columns i where restrict[i]==TRUE, and it's just
30+
# TRUE,...,TRUE,TRUE,...,TRUE where restrict[i]==FALSE.
31+
do.call(c, map(seq_len(n), function(i) {
32+
rep(c(rle(TRUE), rle(!which[i])),
33+
c(i, n - i), scale = "run")
34+
})) |>
35+
compress() |>
36+
rlebdm(n)
37+
}
38+
2439
#' @templateVar name upper_tri
2540
#' @title Only dyads in the upper-triangle of the sociomatrix may be
2641
#' toggled
2742
#' @description For a directed network, only dyads \eqn{(i,j)} for
28-
#' which \eqn{i < j} may be toggled. Optional argument `attr`
29-
#' controls which subgraphs are thus restricted.
43+
#' which \eqn{i \le j} may be toggled (though \eqn{i = j} is usually
44+
#' excluded by other constraints). Optional argument `attr` controls
45+
#' which subgraphs are thus restricted.
3046
#'
3147
#' @usage
3248
#' # upper_tri(attr = NULL)
@@ -48,11 +64,7 @@ InitErgmConstraint.upper_tri<-function(nw, arglist, ...){
4864
list(attr=a$attr,
4965
free_dyads = {
5066
restrict <- if(is.null(a$attr)) rep(TRUE, n) else ergm_get_vattr(a$attr, nw, accept = "logical")
51-
# The pattern is TRUE,...,TRUE,FALSE,...,FALSE for those
52-
# columns i where restrict[i]==TRUE, and it's just
53-
# TRUE,...,TRUE,TRUE,...,TRUE where restrict[i]==FALSE.
54-
d <- do.call(c, lapply(seq_len(n), function(i) rep(c(rle(TRUE),rle(!restrict[i])), c(i-1, n-i+1),scale="run")))
55-
rlebdm(compress(d), n)
67+
upper_tri_rlebdm(n, restrict)
5668
},
5769
dependence = FALSE
5870
)

man/upper_tri-ergmConstraint-f7ecd164.Rd

Lines changed: 3 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)