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 )
0 commit comments