Skip to content

Commit

Permalink
Removed the cache.sp term option: shared partner cache is always active.
Browse files Browse the repository at this point in the history
fixes statent/ergm#529
  • Loading branch information
krivit committed Dec 29, 2024
1 parent 581f93a commit 1d03ca9
Show file tree
Hide file tree
Showing 16 changed files with 331 additions and 633 deletions.
20 changes: 8 additions & 12 deletions R/InitErgmTerm.R
Original file line number Diff line number Diff line change
Expand Up @@ -934,13 +934,12 @@ InitErgmTerm.b1degree <- function(nw, arglist, ..., version=packageVersion("ergm
#'
#' @param d a vector of distinct integers.
#'
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @concept bipartite
#' @concept undirected
InitErgmTerm.b1dsp <- function(nw, arglist, cache.sp=TRUE, ...){
.d_sp_impl("b1", nw, arglist, cache.sp,
InitErgmTerm.b1dsp <- function(nw, arglist, ...){
.d_sp_impl("b1", nw, arglist,
function(d, nw, ...) replace(numeric(length(d)), d==0, (nw%n%"bipartite")*(nw%n%"bipartite"-1)/2),
...)
}
Expand Down Expand Up @@ -1522,13 +1521,12 @@ InitErgmTerm.b2degree <- function(nw, arglist, ..., version=packageVersion("ergm
#'
#' @param d a vector of distinct integers
#'
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @concept bipartite
#' @concept undirected
InitErgmTerm.b2dsp <- function(nw, arglist, cache.sp=TRUE, ...){
.d_sp_impl("b2", nw, arglist, cache.sp,
InitErgmTerm.b2dsp <- function(nw, arglist, ...){
.d_sp_impl("b2", nw, arglist,
function(d, nw, ...) replace(numeric(length(d)), d==0, (network.size(nw)-nw%n%"bipartite")*(network.size(nw)-nw%n%"bipartite"-1)/2),
...)
}
Expand Down Expand Up @@ -2605,14 +2603,13 @@ InitErgmTerm.gwb1degree<-function(nw, arglist, gw.cutoff=30, ..., version=packag
#' @templateVar underlying b1dsp
#' @template ergmTerm-gw-cutoff
#'
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @concept bipartite
#' @concept undirected
#' @concept curved
InitErgmTerm.gwb1dsp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
.dgw_sp_impl("b1", nw, arglist, cache.sp, gw.cutoff=gw.cutoff, ...)
InitErgmTerm.gwb1dsp<-function(nw, arglist, gw.cutoff=30, ...) {
.dgw_sp_impl("b1", nw, arglist, gw.cutoff=gw.cutoff, ...)
}

################################################################################
Expand Down Expand Up @@ -2661,14 +2658,13 @@ InitErgmTerm.gwb2degree<-function(nw, arglist, gw.cutoff=30, ..., version=packag
#' @templateVar underlying b2dsp
#' @template ergmTerm-gw-cutoff
#'
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @concept bipartite
#' @concept undirected
#' @concept curved
InitErgmTerm.gwb2dsp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
.dgw_sp_impl("b2", nw, arglist, cache.sp, gw.cutoff=gw.cutoff, ...)
InitErgmTerm.gwb2dsp<-function(nw, arglist, gw.cutoff=30, ...) {
.dgw_sp_impl("b2", nw, arglist, gw.cutoff=gw.cutoff, ...)
}

################################################################################
Expand Down
40 changes: 17 additions & 23 deletions R/InitErgmTerm.dgw_sp.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ SPTYPE_CODE <- c(UTP = 0L, OTP = 1L, ITP = 2L, RTP = 3L, OSP = 4L, ISP = 5L)
type
}

.d_sp_impl <- function(sp, nw, arglist, cache.sp, emptynwstats = function(...)NULL, ...){
.d_sp_impl <- function(sp, nw, arglist, emptynwstats = function(...)NULL, ...){
if(sp %in% c("b1","b2")){
bip <- sp
sp <- "d"
Expand All @@ -74,10 +74,10 @@ SPTYPE_CODE <- c(UTP = 0L, OTP = 1L, ITP = 2L, RTP = 3L, OSP = 4L, ISP = 5L)

list(name=if(nchar(bip)) "ddspbwrap" else paste0("d",utermname), coef.names=paste(conam,d,sep=""), iinputs=c(SPTYPE_CODE[type],d),
minval=0, emptynwstats=emptynwstats(nw=nw, a=a, d=d, type=type),
auxiliaries=if(cache.sp) .spcache.aux(type) else NULL)
auxiliaries=.spcache.aux(type))
}

.dgw_sp_impl <- function(sp, nw, arglist, cache.sp, gw.cutoff, ...){
.dgw_sp_impl <- function(sp, nw, arglist, gw.cutoff, ...){
if(sp %in% c("b1","b2")){
bip <- sp
sp <- "d"
Expand Down Expand Up @@ -111,10 +111,10 @@ SPTYPE_CODE <- c(UTP = 0L, OTP = 1L, ITP = 2L, RTP = 3L, OSP = 4L, ISP = 5L)
c(list(name=if(nchar(bip)) "ddspdistbwrap" else paste0("d",sp,"spdist"),
coef.names=if(type=="UTP" || nchar(bip)) paste0(bip,sp,"sp#",d) else paste0(bip,sp,"sp.",type,"#",d),
cutoff.message = ergm_cutoff_message(maxsp, termname, sprintf("number of %ss on some %s", SPTYPE_DESC[type], c(e="edge", d="dyad", n="nonedge")[sp]), "cutoff", "gw.cutoff"),
iinputs=SPTYPE_CODE[type], params=params, auxiliaries=if(cache.sp) .spcache.aux(type) else NULL), GWDECAY)
iinputs=SPTYPE_CODE[type], params=params, auxiliaries=.spcache.aux(type)), GWDECAY)
}else{
coef.names <- paste(statname,"fixed",decay,sep=".")
list(name=if(nchar(bip)) "dgwdspbwrap" else termname, coef.names=coef.names, inputs=decay, iinputs=SPTYPE_CODE[type], auxiliaries=if(cache.sp) .spcache.aux(type) else NULL)
list(name=if(nchar(bip)) "dgwdspbwrap" else termname, coef.names=coef.names, inputs=decay, iinputs=SPTYPE_CODE[type], auxiliaries=.spcache.aux(type))
}
}

Expand Down Expand Up @@ -159,7 +159,6 @@ SPTYPE_CODE <- c(UTP = 0L, OTP = 1L, ITP = 2L, RTP = 3L, OSP = 4L, ISP = 5L)
#' @param d a vector of distinct integers
#' @template ergmTerm-sp-type
#'
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @template ergmTerm-directed
Expand All @@ -168,8 +167,8 @@ SPTYPE_CODE <- c(UTP = 0L, OTP = 1L, ITP = 2L, RTP = 3L, OSP = 4L, ISP = 5L)
#'
#' @concept directed
#' @aliases desp-ergmTerm
InitErgmTerm.desp<-function(nw, arglist, cache.sp=TRUE, ...) {
.d_sp_impl("e", nw, arglist, cache.sp, ...)
InitErgmTerm.desp<-function(nw, arglist, ...) {
.d_sp_impl("e", nw, arglist, ...)
}


Expand Down Expand Up @@ -204,7 +203,6 @@ InitErgmTerm.desp<-function(nw, arglist, cache.sp=TRUE, ...) {
#' @template ergmTerm-gw-cutoff
#' @template ergmTerm-sp-type
#'
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @template ergmTerm-sp-types
Expand All @@ -213,8 +211,8 @@ InitErgmTerm.desp<-function(nw, arglist, cache.sp=TRUE, ...) {
#'
#' @concept directed
#' @aliases dgwesp-ergmTerm
InitErgmTerm.dgwesp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
.dgw_sp_impl("e", nw, arglist, cache.sp, gw.cutoff, ...)
InitErgmTerm.dgwesp<-function(nw, arglist, gw.cutoff=30, ...) {
.dgw_sp_impl("e", nw, arglist, gw.cutoff, ...)
}


Expand Down Expand Up @@ -243,7 +241,6 @@ InitErgmTerm.dgwesp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
#' @param d a vector of distinct integers
#' @template ergmTerm-sp-type
#'
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @template ergmTerm-directed
Expand All @@ -252,8 +249,8 @@ InitErgmTerm.dgwesp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
#'
#' @concept directed
#' @aliases ddsp-ergmTerm
InitErgmTerm.ddsp<-function(nw, arglist, cache.sp=TRUE, ...) {
.d_sp_impl("d", nw, arglist, cache.sp, emptynwstats=.dsp_emptynwstats, ...)
InitErgmTerm.ddsp<-function(nw, arglist, ...) {
.d_sp_impl("d", nw, arglist, emptynwstats=.dsp_emptynwstats, ...)
}


Expand All @@ -273,7 +270,6 @@ InitErgmTerm.ddsp<-function(nw, arglist, cache.sp=TRUE, ...) {
#' @template ergmTerm-gw-cutoff
#' @template ergmTerm-sp-type
#'
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @template ergmTerm-sp-types
Expand All @@ -284,8 +280,8 @@ InitErgmTerm.ddsp<-function(nw, arglist, cache.sp=TRUE, ...) {
#'
#' @concept directed
#' @aliases dgwdsp-ergmTerm
InitErgmTerm.dgwdsp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
.dgw_sp_impl("d", nw, arglist, cache.sp, gw.cutoff, ...)
InitErgmTerm.dgwdsp<-function(nw, arglist, gw.cutoff=30, ...) {
.dgw_sp_impl("d", nw, arglist, gw.cutoff, ...)
}


Expand Down Expand Up @@ -317,7 +313,6 @@ InitErgmTerm.dgwdsp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
#' @param d a vector of distinct integers
#' @template ergmTerm-sp-type
#'
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @template ergmTerm-directed
Expand All @@ -326,8 +321,8 @@ InitErgmTerm.dgwdsp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
#'
#' @concept directed
#' @aliases dnsp-ergmTerm
InitErgmTerm.dnsp<-function(nw, arglist, cache.sp=TRUE, ...) {
.d_sp_impl("n", nw, arglist, cache.sp, emptynwstats=.dsp_emptynwstats, ...)
InitErgmTerm.dnsp<-function(nw, arglist, ...) {
.d_sp_impl("n", nw, arglist, emptynwstats=.dsp_emptynwstats, ...)
}


Expand All @@ -347,15 +342,14 @@ InitErgmTerm.dnsp<-function(nw, arglist, cache.sp=TRUE, ...) {
#' @template ergmTerm-sp-type
#'
#' @template ergmTerm-sp-types
#' @template ergmTerm-cache-sp
#' @template ergmTerm-general
#'
#' @template ergmTerm-gw-alpha-to-decay
#'
#' @concept directed
#' @aliases dgwnsp-ergmTerm
InitErgmTerm.dgwnsp<-function(nw, arglist, cache.sp=TRUE, gw.cutoff=30, ...) {
.dgw_sp_impl("n", nw, arglist, cache.sp, gw.cutoff, ...)
InitErgmTerm.dgwnsp<-function(nw, arglist, gw.cutoff=30, ...) {
.dgw_sp_impl("n", nw, arglist, gw.cutoff, ...)
}

################################################################################
Expand Down
2 changes: 1 addition & 1 deletion R/ergm-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#'
#' \item{`gw.cutoff`}{In geometrically weighted terms (`gwesp`, `gwdegree`, etc.) the highest number of shared partners, degrees, etc. for which to compute the statistic. This usually defaults to 30.}
#'
#' \item{`cache.sp`}{Whether the \ergmTerm{ergm}{gwesp}{}, \ergmTerm{ergm}{dgwesp}{}, and similar terms need should use a cache for the dyadwise number of shared partners. This usually improves performance significantly at a modest memory cost, and therefore defaults to `TRUE`, but it can be disabled.}
#' \item{`cache.sp`}{Deprecated: Whether the \ergmTerm{ergm}{gwesp}{}, \ergmTerm{ergm}{dgwesp}{}, and similar terms need should use a cache for the dyadwise number of shared partners. This usually improves performance significantly at a modest memory cost, and therefore defaults to `TRUE`, but it can be disabled.}
#'
#' \item{`interact.dependent`}{Whether to allow and how to handle the user attempting to interact dyad-dependent terms (e.g., `absdiff("age"):triangles` or `absdiff("age")*triangles` as opposed to `absdiff("age"):nodefactor("sex")`). Possible values are `"error"` (the default), `"message"`, and `"warning"`, for their respective actions, and `"silent"` for simply processing the term.}
#'
Expand Down
6 changes: 0 additions & 6 deletions man/b1dsp-ergmTerm-f3ebeba1.Rd

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

6 changes: 0 additions & 6 deletions man/b2dsp-ergmTerm-e9e03312.Rd

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

5 changes: 0 additions & 5 deletions man/dsp-ergmTerm-1a10473d.Rd

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

2 changes: 1 addition & 1 deletion man/ergm-options.Rd

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

5 changes: 0 additions & 5 deletions man/esp-ergmTerm-d2e07fc8.Rd

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

6 changes: 0 additions & 6 deletions man/gwb1dsp-ergmTerm-0bf628f4.Rd

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

6 changes: 0 additions & 6 deletions man/gwb2dsp-ergmTerm-2d408a5d.Rd

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

5 changes: 0 additions & 5 deletions man/gwdsp-ergmTerm-4e3dfd97.Rd

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

5 changes: 0 additions & 5 deletions man/gwesp-ergmTerm-3d6fb5a8.Rd

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

5 changes: 0 additions & 5 deletions man/gwnsp-ergmTerm-6def2a32.Rd

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

5 changes: 0 additions & 5 deletions man/nsp-ergmTerm-4586ea4f.Rd

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

Loading

0 comments on commit 1d03ca9

Please sign in to comment.