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

Change appears to malfunction with isolates #59

Closed
chad-klumb opened this issue Jun 20, 2021 · 5 comments
Closed

Change appears to malfunction with isolates #59

chad-klumb opened this issue Jun 20, 2021 · 5 comments

Comments

@chad-klumb
Copy link
Contributor

e.g.

require(tergm)
set.seed(0)
nw0 <- network.initialize(100, dir = FALSE)
nw1 <- simulate(nw0 ~ edges, coef = c(-4), dynamic = TRUE, monitor = ~Change(~edges + isolates), output = "final")
attributes(nw1)$stats

produces

> attributes(nw1)$stats
Markov Chain Monte Carlo (MCMC) output:
Start = 1 
End = 1 
Thinning interval = 1 
     Change~edges Change~isolates
[1,]           78             120
@krivit
Copy link
Member

krivit commented Jun 20, 2021

I'll look into it.

@krivit
Copy link
Member

krivit commented Jun 20, 2021

Looks like an issue in the handling of empty network statistics.

@krivit
Copy link
Member

krivit commented Jun 20, 2021

require(tergm)
set.seed(0)
nw0 <- network.initialize(100, dir = FALSE)
# Correct values: 100, 100, -100, 100
summary(nw0 ~ Form(~isolates) + Persist(~isolates) + Diss(~isolates) + Change(~isolates), dynamic=TRUE)
#>    Form~isolates Persist~isolates    Diss~isolates  Change~isolates 
#>              200              100              100              200

Created on 2021-06-21 by the reprex package (v2.0.0)

krivit added a commit that referenced this issue Jun 21, 2021
…hange() are now handled entirely in C; *_negate_on_intersect_lt_net_Network() functions have been simplified by calling *_on_intersect_lt_net_Network() and negating the result; and Change()'s C implementation for empty network statistics has been fixed.

references #59
@krivit
Copy link
Member

krivit commented Jun 21, 2021

library(tergm)
nw <- network.initialize(100, dir = FALSE)

# y0, y1 empty.

# Correct values: 0, 100, 0, 100, 0, -100, 0, 100
summary(nw ~ Form(~edges+isolates) + Persist(~edges+isolates) + Diss(~edges+isolates) + Change(~edges+isolates), dynamic=TRUE)
#>       Form~edges    Form~isolates    Persist~edges Persist~isolates 
#>                0              100                0              100 
#>       Diss~edges    Diss~isolates     Change~edges  Change~isolates 
#>                0             -100                0              100

# y0, y1 both have (1,2)
nw[1,2] <- TRUE
# Correct values: 1, 98, 1, 98, -1, -98, 0, 100
summary(nw ~ Form(~edges+isolates) + Persist(~edges+isolates) + Diss(~edges+isolates) + Change(~edges+isolates), dynamic=TRUE)
#>       Form~edges    Form~isolates    Persist~edges Persist~isolates 
#>                1               98                1               98 
#>       Diss~edges    Diss~isolates     Change~edges  Change~isolates 
#>               -1              -98                0              100


# y1 has (1,2), y0 has (1,2) and (3,4)
nw %n% "time" <- 1
nw %n% "lasttoggle" <- cbind(3,4,1)

# Correct values: 2, 96, 1, 98, -1, -98, 1, 98
summary(nw ~ Form(~edges+isolates) + Persist(~edges+isolates) + Diss(~edges+isolates) + Change(~edges+isolates), dynamic=TRUE)
#>       Form~edges    Form~isolates    Persist~edges Persist~isolates 
#>                2               96                1               98 
#>       Diss~edges    Diss~isolates     Change~edges  Change~isolates 
#>               -1              -98                1               98


# y1 has (1,2), y0 has (1,2), (2,3), and (3,4)
nw %n% "lasttoggle" <- rbind(nw %n% "lasttoggle", cbind(2,3,1))

# Correct values: 3, 96, 1, 98, -1, -98, 2, 97
summary(nw ~ Form(~edges+isolates) + Persist(~edges+isolates) + Diss(~edges+isolates) + Change(~edges+isolates), dynamic=TRUE)
#>       Form~edges    Form~isolates    Persist~edges Persist~isolates 
#>                3               96                1               98 
#>       Diss~edges    Diss~isolates     Change~edges  Change~isolates 
#>               -1              -98                2               97

Created on 2021-06-21 by the reprex package (v2.0.0)

@krivit
Copy link
Member

krivit commented Jun 21, 2021

@chad-klumb, seems to be better now. Can you please turn these into unit tests?

chad-klumb added a commit that referenced this issue Jun 21, 2021
chad-klumb added a commit that referenced this issue Jun 21, 2021
chad-klumb added a commit that referenced this issue Jun 21, 2021
chad-klumb added a commit that referenced this issue Jun 21, 2021
This issue was closed.
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