Skip to content

Commit

Permalink
Merge branch 'master' into control3
Browse files Browse the repository at this point in the history
  • Loading branch information
krivit committed Dec 24, 2024
2 parents 86288f9 + d0c5e5c commit 762f582
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 89 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: ergm
Version: 4.8.0-7026
Version: 4.8.0-7505
Date: 2024-12-22
Title: Fit, Simulate and Diagnose Exponential-Family Models for Networks
Authors@R: c(
Expand Down
25 changes: 13 additions & 12 deletions R/InitErgmConstraint.R
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ InitErgmConstraint.observed <- function(nw, arglist, ...){
}

warn_netsize <- function(.n, ...){
mismatch <- vapply(list(...), function(x) is.network(x) && network.size(x) != .n, logical(1))
mismatch <- map_lgl(list(...), function(x) (is.network(x) && network.size(x) != .n) || (is(x, "rlebdm") && nrow(x) != .n))
if(any(mismatch))
ergm_Init_warning("Network size of argument(s) ", paste.and(sQuote(...names()[mismatch])), " differs from that of the response network.")
}
Expand Down Expand Up @@ -477,7 +477,7 @@ InitErgmConstraint.fixedas<-function(nw, arglist,...){
#'
#' @usage
#' # fixallbut(free.dyads)
#' @param free.dyads edgelist or network. Networks will be converted to the corresponding edgelist.
#' @param free.dyads a two-column edge list, a [`network`], or an [`rlebdm`]. Networks will be converted to the corresponding edgelist.
#'
#' @template ergmConstraint-general
#'
Expand All @@ -487,23 +487,24 @@ InitErgmConstraint.fixedas<-function(nw, arglist,...){
InitErgmConstraint.fixallbut<-function(nw, arglist,...){
a <- check.ErgmTerm(nw, arglist,
varnames = c("free.dyads"),
vartypes = c("network,matrix"),
vartypes = c("network,matrix,rlebdm"),
defaultvalues = list(NULL),
required = c(TRUE))
free.dyads <- a$free.dyads

warn_netsize(network.size(nw), free.dyads = free.dyads)

list(
free_dyads = function(){
if(is.network(free.dyads)) free.dyads <- as.edgelist(free.dyads)
else free.dyads <- as.edgelist(free.dyads,
n=nw%n%"n",
directed=nw%n%"directed",
bipartite=nw%n%"bipartite",
loops=nw%n%"loops")
as.rlebdm(free.dyads)
},
free_dyads =
if(is(free.dyads, "rlebdm")) free.dyads
else function()
as.rlebdm(if(is.network(free.dyads)) as.edgelist(free.dyads)
else as.edgelist(free.dyads,
n=nw%n%"n",
directed=nw%n%"directed",
bipartite=nw%n%"bipartite",
loops=nw%n%"loops")
),
dependence = FALSE)
}

Expand Down
4 changes: 1 addition & 3 deletions R/InitErgmTerm.operator.R
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,6 @@ InitErgmTerm.Sum <- function(nw, arglist,...){
nparam <- nparams[1]

inputs <- unlist(wl%>%map(t))
inputs <- c(nf, length(inputs), inputs)


if(is.function(a$label)){
cns <- lapply(ms, param_names, canonical=TRUE)
Expand Down Expand Up @@ -770,7 +768,7 @@ InitErgmTerm.Sum <- function(nw, arglist,...){
}
}else offset <- FALSE

c(list(name="Sum", coef.names = coef.names, inputs=inputs, submodels=ms, emptynwstats=gs,
c(list(name="Sum", coef.names = coef.names, inputs=inputs, iinputs=nf, submodels=ms, emptynwstats=gs,
dependence=dependence, offset=offset,
ext.encode = if(ms %>% map("terms") %>% unlist(FALSE) %>% map("ext.encode") %>% compact %>% length)
function(el, nw0)
Expand Down
2 changes: 1 addition & 1 deletion R/ergm.R
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ ergm <- function(formula, response=NULL,
model.obs <- NULL
if(identical(proposal$auxiliaries, proposal.obs$auxiliaries)){
## Reuse auxiliaries from the unconstrained proposal if identical.
proposal.obs$slots.extra.aux <- model$slots.extra.aux$proposal
proposal.obs$aux.slots <- model$slots.extra.aux$proposal
}else if(!is.null(proposal.obs$auxiliaries)){
if (verbose) message("Constrained proposal requires different auxiliaries: reinitializing model...")
model.obs <- ergm_model(formula, nw, extra.aux = NVL3(proposal.obs$auxiliaries,list(proposal=.)), term.options=control$term.options)
Expand Down
110 changes: 98 additions & 12 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
\title{NEWS file for the \code{\link[=ergm-package]{ergm}} package}
\encoding{UTF-8}


%% Note: This needs to be kept in sync with man/macros/ergmTerm.Rd
\newcommand{\ergmTerm}{\code{\link[#1:#2-ergmTerm]{#2#3}}}
\newcommand{\ergmConstraint}{\code{\link[#1:#2-ergmConstraint]{#2#3}}}
\newcommand{\ergmReference}{\code{\link[#1:#2-ergmReference]{#2#3}}}
\newcommand{\ergmHint}{\code{\link[#1:#2-ergmHint]{#2#3}}}
\newcommand{\ergmProposal}{\code{\link[#1:#2-ergmProposal]{#2#3}}}


% When a release is forked, copy the sections to a new release and
% delete unused sections.

Expand Down Expand Up @@ -65,6 +74,83 @@
%% }


\section{Changes in version 4.8.0}{

\subsection{NEW FEATURES}{
\itemize{
\item{
A new bipartite term operator \ergmTerm{ergm}{Project}{()}, with aliases \ergmTerm{ergm}{Proj1}{()} and \ergmTerm{ergm}{Proj2}{()}, evaluating the statistics on an undirected valued network of counts constructed by projecting the bipartite network onto one of its modes.
}
\item{
A new family of terms, \ergmTerm{ergm}{nodecovrange}{()}, \ergmTerm{ergm}{nodeocovrange}{()}, \ergmTerm{ergm}{nodeicovrange}{()}, \ergmTerm{ergm}{b1covrange}{()}, and \ergmTerm{ergm}{b2covrange}{()}, to evaluate the sum over the nodes of the range of the specified quantitative attribute value among the node's neighbors. (Thanks to Marion Hoffman for the idea!)
}
\item{
A new family of terms, \ergmTerm{ergm}{nodefactordistinct}{()}, \ergmTerm{ergm}{nodeofactordistinct}{()}, \ergmTerm{ergm}{nodeifactordistinct}{()}, \ergmTerm{ergm}{b1factordistinct}{()}, and \ergmTerm{ergm}{b2factordistinct}{()}, to evaluate the sum over the nodes of the number of distinct values of a categorical factor among the node's neighbors. (Thanks to Marion Hoffman for the idea!)
}
\item{
The \ergmConstraint{ergm}{fixallbut}{()} now supports an \code{\link{rlebdm}} (in addition to an edge list matrix and a \code{\link[network]{network}}) for its argument.
}
}
}


\subsection{BUG FIXES}{
\itemize{
\item{
Fix in stochastic approximation code for compatibility with most recent \CRANpkg{coda}.
}
\item{
In \code{\link[ergm]{ergm()}}, a bug in initialization of MH proposals for constrained sampling requesting auxiliaries has been fixed.
}
}
}


\subsection{OTHER USER-VISIBLE CHANGES}{
\itemize{
\item{
Precision of geometrically weighted statistics (degrees and shared partners) has been improved, particularly for large decay parameters.
}
\item{
Dynamic term documentation is now more robust to extension developer error.
}
\item{
A new \code{\link[=as.rle.rlebdm]{as.rle()}} method for \code{\link{rlebdm}} objects to cast it back to an \code{\link{rle}}.
}
}
}

\subsection{C-LEVEL FACILITIES}{
\itemize{
\item{
Degree-conditioned proposals are now exported in \file{inst/include/}.
}
\item{
The M-H proposal API now makes lengths of input vectors available to the proposals, paralleling the change statistics API.
}
}
}

%% \subsection{UTILITIES}{
%% \itemize{
%% \item Likewise, "UTILITIES" is probably unnecessary.
%% }
%% }

%% \subsection{INSTALLATION}{
%% \itemize{
%% \item ... as is "INSTALLATION".
%% }
%% }

%% \subsection{PACKAGE INSTALLATION}{
%% \itemize{
%% \item ditto.
%% }
%% }

}


\section{Changes in version 4.7.5}{

Expand Down Expand Up @@ -105,7 +191,7 @@
\code{\link[=blockdiag-ergmConstraint]{blockdiag}} constraint initialization now detects when blocks are non-contiguous and stops with an error. (Previously, it would behave in undefined ways.)
}
\item{
\code{\link[=Sum-ergmTerm]{Sum}} operator now handles \code{\link{I}()} label specifications correctly; this also fixes an error in the \code{\link[=Prod-ergmTerm]{Prod}} term.
\ergmTerm{ergm}{Sum}{} operator now handles \code{\link{I}()} label specifications correctly; this also fixes an error in the \ergmTerm{ergm}{Prod}{} term.
}
\item{
Detection of dyadic dependence now ignores dyadic dependence of hints (since they do not affect the sample space) and auxiliaries (since they do not, in and of themselves, add dyad-dependent statistics).
Expand All @@ -123,7 +209,7 @@
In proposal help, listing of proposal table entries works again.
}
\item{
\code{\link[=nodemix-ergmTerm]{nodemix}()} now uses correct parameter names.
\ergmTerm{ergm}{nodemix}{()} now uses correct parameter names.
}
\item{
Godambe information for the MPLE now works if the model has an offset. (Thanks, Cornelius Fritz for reporting and Michał Bojanowski for fixing.)
Expand All @@ -132,7 +218,7 @@
When constructing the starting networks for missing data MCMC, imputation of dyads is skipped if the constraints are dyad-dependent, since inserting edges may break the constraint.
}
\item{
\code{\link[=edgecov-ergmTerm]{edgecov}()} and \code{\link[=dyadcov-ergmTerm]{dyadcov}()} now handle \code{\link[network]{network}}-format input correctly.
\ergmTerm{ergm}{edgecov}{()} and \ergmTerm{ergm}{dyadcov}{()} now handle \code{\link[network]{network}}-format input correctly.
}
\item{
Missing data MLE code can now handle the scenarios in which the statistics in the constrained sample are constant and/or the statistics in the unconstrained sample are highly correlated.
Expand All @@ -144,10 +230,10 @@
Likelihood calculation is now robust to dropped parameters and parameters fixed at infinity.
}
\item{
\code{\link[Label-ergmTerm]{Label}()} operator now documents its behavior when the model is curved more clearly.
\ergmTerm{ergm}{Label}{()} operator now documents its behavior when the model is curved more clearly.
}
\item{
Invalid \code{levels2} specification for \code{\link[=mm-ergmTerm]{mm()}} no longer causes memory errors.
Invalid \code{levels2} specification for \ergmTerm{ergm}{mm}{()} no longer causes memory errors.
}
\item{
Valued proposal updater function was not being passed the current edge state.
Expand All @@ -167,7 +253,7 @@
\code{\link{LARGEST}}, \code{\link{SMALLEST}}, and \code{\link{COLLAPSE_SMALLEST}} now break ties lexicographically with a warning.
}
\item{
\code{\link[=absdiffcat-ergmTerm]{absdiffcat}} is now more memory-efficient during initialization.
\ergmTerm{ergm}{absdiffcat}{} is now more memory-efficient during initialization.
}
\item{
MCMLE estimation code for missing data MLE with high missingness fraction is more robust.
Expand All @@ -191,7 +277,7 @@
\code{\link{ergm_Init_stop}()}, \code{\link{ergm_Init_warning}()}, and \code{\link{ergm_Init_message}()} that behave more like their \pkg{base} counterparts have been added to the API. \code{\link{ergm_Init_abort}()}, \code{\link{ergm_Init_warn}()}, and \code{\link{ergm_Init_info}()} will eventually change to use their \CRANpkg{rlang} semantics.
}
\item{
\code{\link[=edgecov-ergmTerm]{edgecov}()} and \code{\link[=dyadcov-ergmTerm]{dyadcov}()} now check that their covariate matrix has the correct dimension.
\ergmTerm{ergm}{edgecov}{()} and \ergmTerm{ergm}{dyadcov}{()} now check that their covariate matrix has the correct dimension.
}
\item{
Constraints \code{\link[fixedas-ergmConstraint]{fixedas}()} and \code{\link[fixedas-ergmConstraint]{fixallbut}()} now warn when given a network whose size does not match the LHS network's.
Expand Down Expand Up @@ -493,7 +579,7 @@
New functions \code{\link{search.ergmHints}()} and \code{\link{search.ergmReferences}()} can now be used to search available \code{\link{ergmHints}} and \code{\link{ergmReferences}}, respectively.
}
\item{
A new \code{\link[=For-ergmTerm]{For}()} term operator to construct a list of terms with some varying parameter.
A new \ergmTerm{ergm}{For}{()} term operator to construct a list of terms with some varying parameter.
}
\item{
Term API vignette is now more complete, and includes all API elements, not just the post-4.0 ones.
Expand Down Expand Up @@ -594,7 +680,7 @@
\subsection{NEW FEATURES}{
\itemize{
\item{
In terms \code{\link[=edgecov-ergmTerm]{edgecov}()} and \code{\link[=dyadcov-ergmTerm]{dyadcov}()}, the argument can now be a network.
In terms \ergmTerm{ergm}{edgecov}{()} and \ergmTerm{ergm}{dyadcov}{()}, the argument can now be a network.
}
}
}
Expand Down Expand Up @@ -704,7 +790,7 @@
}

\item{
Term \code{\link[=nodemix-ergmTerm]{nodemix}} can now be passed a \code{levels2} argument that is a \code{\link{factor}} or \code{\link{character}} and optionally a matrix, allowing multiple cells to be mapped to the same statistic. (Joyce Cheng)
Term \ergmTerm{ergm}{nodemix}{} can now be passed a \code{levels2} argument that is a \code{\link{factor}} or \code{\link{character}} and optionally a matrix, allowing multiple cells to be mapped to the same statistic. (Joyce Cheng)
}

\item{
Expand Down Expand Up @@ -733,7 +819,7 @@
}

\item{
\code{\link[=edgecov-ergmTerm]{edgecov}} and \code{\link[=dyadcov-ergmTerm]{dyadcov}} now detect and stop with an error when the specified network attribute is not found.
\ergmTerm{ergm}{edgecov}{} and \ergmTerm{ergm}{dyadcov}{} now detect and stop with an error when the specified network attribute is not found.
}

\item{
Expand Down Expand Up @@ -813,7 +899,7 @@
}

\item{
\code{\link{check.ErgmTerm}()} helper function can now also capture the expressions resulting in term arguments. This incidentally fixes a regression in statistic naming of \code{\link{edgecov-ergmTerm}} and \code{\link{dyadcov-ergmTerm}} effects.
\code{\link{check.ErgmTerm}()} helper function can now also capture the expressions resulting in term arguments. This incidentally fixes a regression in statistic naming of \ergmTerm{ergm}{edgecov}{()} and \ergmTerm{ergm}{dyadcov}{()} effects.
}

\item{
Expand Down
9 changes: 7 additions & 2 deletions inst/include/ergm_MHproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ typedef struct MHProposalstruct {
Vertex *togglehead;
double logratio;
int status;
double *inputs; /* may be used if needed, ignored if not. */
int *iinputs; /* may be used if needed, ignored if not. */
int ninputs;
double *inputs;
int niinputs;
int *iinputs;
void *storage;
void **aux_storage;
unsigned int n_aux;
Expand All @@ -79,8 +81,11 @@ MHProposal *MHProposalInitialize(SEXP pR, Network *nwp, void **aux_storage);
void MHProposalDestroy(MHProposal *MHp, Network *nwp);

/* Helper macros */
#define MH_N_DINPUTS MHp->ninputs
#define MH_DINPUTS MHp->inputs
#define MH_N_INPUTS MH_N_DINPUTS
#define MH_INPUTS MH_DINPUTS
#define MH_N_IINPUTS MHp->niinputs
#define MH_IINPUTS MHp->iinputs

#define Mtail (MHp->toggletail)
Expand Down
2 changes: 1 addition & 1 deletion inst/include/ergm_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Macros indicating the version of the C API.
#define ERGM_API_MAJOR 4
#define ERGM_API_MINOR 7
#define ERGM_API_MINOR 8

typedef enum MCMCStatus_enum {
MCMC_OK = 0,
Expand Down
9 changes: 7 additions & 2 deletions inst/include/ergm_wtMHproposal.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ typedef struct WtMHProposalstruct {
double *toggleweight;
double logratio;
int status;
double *inputs; /* may be used if needed, ignored if not. */
int *iinputs; /* may be used if needed, ignored if not. */
int ninputs;
double *inputs;
int niinputs;
int *iinputs;
void *storage;
void **aux_storage;
unsigned int n_aux;
Expand All @@ -79,8 +81,11 @@ WtMHProposal *WtMHProposalInitialize(SEXP pR, WtNetwork *nwp, void **aux_storage
void WtMHProposalDestroy(WtMHProposal *MH, WtNetwork *nwp);

/* Helper macros */
#define MH_N_DINPUTS MHp->ninputs
#define MH_DINPUTS MHp->inputs
#define MH_N_INPUTS MH_N_DINPUTS
#define MH_INPUTS MH_DINPUTS
#define MH_N_IINPUTS MHp->niinputs
#define MH_IINPUTS MHp->iinputs

#define Mtail (MHp->toggletail)
Expand Down
2 changes: 1 addition & 1 deletion man/fixallbut-ergmConstraint-ea96b2e0.Rd

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

6 changes: 4 additions & 2 deletions src/MHproposal.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ MHProposal *MHProposalInitialize(SEXP pR, Network *nwp, void **aux_storage){
MHp->x_func=(void (*)(unsigned int, void *, MHProposal*, Network*)) R_FindSymbol(fn,sn,NULL);

SEXP tmp = getListElement(pR, "inputs");
MHp->inputs=length(tmp) ? REAL(tmp) : NULL;
MHp->ninputs = length(tmp);
MHp->inputs = MHp->ninputs ? REAL(tmp) : NULL;
tmp = getListElement(pR, "iinputs");
MHp->iinputs=length(tmp) ? INTEGER(tmp) : NULL;
MHp->niinputs = length(tmp);
MHp->iinputs = MHp->niinputs ? INTEGER(tmp) : NULL;

/*Clean up by freeing sn and fn*/
R_Free(fn);
Expand Down
Loading

0 comments on commit 762f582

Please sign in to comment.