Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do operators need to propagate ext.decode as well? #325

Open
chad-klumb opened this issue Jun 14, 2021 · 3 comments
Open

do operators need to propagate ext.decode as well? #325

chad-klumb opened this issue Jun 14, 2021 · 3 comments

Comments

@chad-klumb
Copy link
Contributor

It seems like these lines

ergm/R/ergm_state.R

Lines 275 to 280 in 1eba069

if(is.null(trm$ext.decode)){
reencode[i] <- !is.null(trm$ext.encode)
next
}
o <- trm$ext.decode(object$ext.state[[i]], object$el, object$nw0)

won't work for ext.decodes that are only in the operator's submodel, and not brought up to the top level term.

To give an extremely contrived example,

require(tergm)
nw <- network.initialize(10, dir = F)
nw %n% "lasttoggle" <- NULL

nws <- simulate(nw ~ Passthrough(~edges + mean.age), coef = c(0.1, 0.1), dynamic = FALSE)
nws %n% "time"
nws %n% "lasttoggle"

nws <- simulate(nw ~ edges + mean.age, coef = c(0.1, 0.1), dynamic = FALSE)
nws %n% "time"
nws %n% "lasttoggle"

produces

> require(tergm)
> nw <- network.initialize(10, dir = F)
> nw %n% "lasttoggle" <- NULL
> 
> nws <- simulate(nw ~ Passthrough(~edges + mean.age), coef = c(0.1, 0.1), dynamic = FALSE)
> nws %n% "time"
NULL
> nws %n% "lasttoggle"
NULL
> 
> nws <- simulate(nw ~ edges + mean.age, coef = c(0.1, 0.1), dynamic = FALSE)
> nws %n% "time"
[1] 0
> nws %n% "lasttoggle"
     [,1] [,2] [,3]

The defaults get written in the second case, when mean.age is at the top level, but not in the first case, when it's inside Passthrough. Of course, in this example, those values are junk anyway.

But, hypothetically, if we had a non-auxiliary term (can't use .lasttoggle as an example, since that's only an auxiliary) that had both ext.encode and ext.decode functions, and we put that term inside Passthrough, it seems like it wouldn't work correctly.

@chad-klumb
Copy link
Contributor Author

Actually, I don't think it really matters if the term is an auxiliary or not, but .lasttoggle can't serve as a compelling example here because it's included in the system auxiliaries in tergm simulation (the only time it behaves nontrivially).

@krivit
Copy link
Member

krivit commented Jun 15, 2021

I need to update the API docs, but way it works at the moment is that while a term using extended state can "expect" its ext.encode to be propagated (provided the operator can safely do it, which is not always the case), only the top-level terms will have their w_ function and their ext.decode called. This is because we don't want, say, .lasttoggle at every level modifying the network.

@chad-klumb
Copy link
Contributor Author

Okay. I can imagine situations where we would want to propagate, but those are just hypotheticals, nothing that exists right now.

This seems related to the problem of "contexts", where a given term with given arguments means different things e.g. at the top level vs. inside some operator. For full generality it seems we should allow a different state in each context, so that, e.g., a .lasttoggle at the top level and a .lastoggle inside a Form at the top level could each maintain their own network history. It seems like something along those lines may be necessary if we want arbitrary hierarchies of operator terms and arbitrary terms inside of them to function properly; every time you step into a new operator, you change contexts, and, potentially, states. In this sense the "full" state would be structured analogously to the nesting of operators in the overall formula, a tree with root node corresponding to the "top level" context, and descendant nodes moving into operators from there on down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants