-
Notifications
You must be signed in to change notification settings - Fork 22
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
Refactor rdiffnet #46
Conversation
…-test-discussion too.
… in rdiffnet function
…fnet_check_seed_graph fixed.
…ication following the merge of the 41... branch
…net_make_threshold. Some modification in rdiffnet too. Not expecting to work yet.
…ose functions are pass.
R/rdiffnet.r
Outdated
} else if (class(seed.nodes) == "character") { | ||
|
||
stop("-character- class not supported for multi-diffusion. It must be a -list-.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following code is causing an error here:
z <- rdiffnet(100,10, seed.p.adopt = list(.1, .05), seed.nodes=c(1,2,3,4))
The option -copy.first- is set to TRUE. In this case, the first graph will be treated as a baseline, and thus, networks after T=1 will be replaced with T-1.TRUE
Message: Multi-diffusion behavior simulation selected. Number of behaviors: 2
Error in rdiffnet_validate_args(seed.p.adopt, seed.nodes, behavior) :
-character- class not supported for multi-diffusion. It must be a -list-.
> traceback()
3: stop("-character- class not supported for multi-diffusion. It must be a -list-.") at rdiffnet.r#567
2: rdiffnet_validate_args(seed.p.adopt, seed.nodes, behavior) at rdiffnet.r#381
1: rdiffnet(100, 10, seed.p.adopt = list(0.01, 0.03))
Tagging @twvalente for a potential model of adoption/disadoption: We could also make disadoption to happen randomly. |
… from -list-. For example: rdiffnet(100,10, seed.p.adopt = list(.1, .05)), or adding seed.nodes=c(1,2,3,4), seed.nodes=random, or seed.nodes=c(random,central). Respective tests added.
… work to be done to display a line saying 'number of behaviors', and to fix the summary() function.
… work to be done to display a line saying 'number of behaviors', and to fix the summary() function.
… of behaviors-, and
… to something more simple later
R/adjmat.r
Outdated
@@ -462,31 462,52 @@ adjmat_to_edgelist.list <- function(graph, undirected, keep.isolates) { | |||
#' @keywords manip | |||
#' @include graph_data.r | |||
#' @author George G. Vega Yon & Thomas W. Valente | |||
toa_mat <- function(obj, labels=NULL, t0=NULL, t1=NULL) { | |||
toa_mat <- function(obj, num_of_behaviors=1, labels=NULL, t0=NULL, t1=NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of behaviors should be implicit (so you can figure that out from diffnet object). So don't ask the user of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just deleted the 'num_of_behaviors' dependency in toa_mat and other functions.
R/diffnet-class.r
Outdated
@@ -547,7 547,8 @@ new_diffnet <- function(graph, toa, t0=min(toa, na.rm = TRUE), t1=max(toa, na.rm | |||
self = getOption("diffnet.self"), | |||
multiple = getOption("diffnet.multiple"), | |||
name = "Diffusion Network", | |||
behavior = "Unspecified" | |||
behavior = "Unspecified", | |||
num_of_behaviors = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The num of behaviors should be guessed from the data.
R/diffnet-class.r
Outdated
"using -t0- and -t- (see ?toa_mat).") | ||
} else { | ||
|
||
# This should be reviewed !! (here the graph becomes 'dynamic') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a while realize that, at Step 1.1 in new_diffnet, a graph will never be 'static'. This is because, if I give as an input a single 'slice' of graph ('static'), that will be converted to a list of graph before this step anyway, so it become a 'dynamic' graph whatever the circumstance. This implies that the type of graph is shown as 'dynamic':
n <- 100
nper <- 5
static_graph <- rgraph_er(n = n, t = 1, p = 0.1)
diffnet <- rdiffnet(
seed.graph = static_graph,
t = 5,
seed.p.adopt = 0.1,
rewire = FALSE,
seed.nodes = 'central',
threshold.dist = runif(n, .1, .4)
)
str(diffnet) # always meta$type == dinamic !!
Since the code never really uses those lines (neither single diff nor multi diff), it's "working."
class(rdiffnet_args$seed.p.adopt) == "list" | ||
class(rdiffnet_args$seed.nodes) == "list" | ||
class(rdiffnet_args$behavior) == "list" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class(rdiffnet_args$seed.p.adopt) == "list" | |
class(rdiffnet_args$seed.nodes) == "list" | |
class(rdiffnet_args$behavior) == "list" |
Or add an expectation from testthat
class(rdiffnet_args$seed.p.adopt) == "list" | ||
class(rdiffnet_args$seed.nodes) == "list" | ||
class(rdiffnet_args$behavior) == "list" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class(rdiffnet_args$seed.p.adopt) == "list" | |
class(rdiffnet_args$seed.nodes) == "list" | |
class(rdiffnet_args$behavior) == "list" |
class(rdiffnet_args$seed.p.adopt) == "list" | ||
class(rdiffnet_args$seed.nodes) == "list" | ||
class(rdiffnet_args$behavior) == "list" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
tests/testthat/test-rdiffnet.R
Outdated
#single | ||
rdiffnet(100, 5) | ||
rdiffnet(100, 5, seed.p.adopt = 0.1) | ||
rdiffnet(100, 5, seed.p.adopt = 0.1, seed.nodes = 'random') | ||
rdiffnet(100, 5, seed.nodes = c(1,3,5)) | ||
net_1 <- rdiffnet(100, 5, seed.nodes = c(1,3,5)) | ||
summary(net_1) | ||
|
||
#multi | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08)) | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08), behavior = c('tabacco', 'alcohol')) | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08), seed.nodes = 'random') | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08), seed.nodes = c('random', 'central')) | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08), threshold.dist = 0.3) | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08), threshold.dist = list(0.1,0.2)) | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08), threshold.dist = rexp(100)) | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08), threshold.dist = list(rexp(100),runif(100))) | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08), threshold.dist = function(x) 0.3) | ||
rdiffnet(100, 5, seed.p.adopt = list(0.1,0.08), threshold.dist = list(function(x) 0.3, function(x) 0.2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, add expectations of of the sort of "expect class" something like that so you ensure it returns diffnet objects.
…d matrix objects. The same tests for single behavior were adapted.
No description provided.