summaryrefslogtreecommitdiffstats
path: root/R Scripts/generate-dag-dat.R
diff options
context:
space:
mode:
authorBen Green <bgreen@g.harvard.edu>2015-08-23 12:40:54 -0400
committerBen Green <bgreen@g.harvard.edu>2015-08-23 12:40:57 -0400
commit33560c3370ff1f53f2adf9af46ea3a80daeeed44 (patch)
tree279e7b4b0571c30d6fc727d43911e0f570d8170c /R Scripts/generate-dag-dat.R
parenta07ce388d7bd18ecba99593f49832f4f70c7c776 (diff)
downloadcriminal_cascades-33560c3370ff1f53f2adf9af46ea3a80daeeed44.tar.gz
get dag-dat for dist=2 edges
Diffstat (limited to 'R Scripts/generate-dag-dat.R')
-rwxr-xr-xR Scripts/generate-dag-dat.R10
1 files changed, 8 insertions, 2 deletions
diff --git a/R Scripts/generate-dag-dat.R b/R Scripts/generate-dag-dat.R
index adef5f6..3e8b495 100755
--- a/R Scripts/generate-dag-dat.R
+++ b/R Scripts/generate-dag-dat.R
@@ -9,7 +9,7 @@ registerDoMC(cores=4)
edgeWeights = function(eis){return(c(lcc_edges$weight[eis],Inf,Inf)[1:3])}
lcc2 = remove.edge.attribute(lcc,'weight')
-vics = split(vic_ids, ceiling(seq_along(vic_ids)/98))
+vics = split(vic_ids, ceiling(seq_along(vic_ids)/40))
dag_dat_lcc = c()
for(i in 1:length(vics)){
ptm = proc.time()
@@ -19,10 +19,11 @@ for(i in 1:length(vics)){
ddl = foreach (u = vic_ids, .combine=rbind) %dopar% {
if ((which(vic_ids==u) %% 100)==0) print(which(vic_ids==u))
- nbhd = unlist(neighborhood(lcc,nodes=u,order=1)) # get nodes within neighborhood
+ nbhd = unlist(neighborhood(lcc,nodes=u,order=2)) # get nodes within neighborhood
nbhd = nbhd[-1] # don't want to include u in the neighborhood
dists = as.numeric(shortest.paths(lcc2,u,nbhd))
+ nbhd = nbhd[dists==2]; dists = dists[dists==2] #####
es = get.shortest.paths(lcc2,u,nbhd,output='epath')$epath
weights = matrix(unlist(lapply(es,edgeWeights),use.names = F),ncol=3,byrow=T)
@@ -58,3 +59,8 @@ write.csv(dag_dat_lcc, file='Results/dag_dat_lcc.csv')
####
# create lcc_vic_times
+vic_times_lcc = lcc_verts[,c('name','nonfatal_day_1','nonfatal_day_2',
+ 'nonfatal_day_3','nonfatal_day_4',
+ 'nonfatal_day_5','fatal_day')]
+save(vic_times_lcc, file='Results/vic_times_lcc.RData')
+write.csv(vic_times_lcc, file='Results/vic_times_lcc.csv')