diff options
| author | Ben Green <bgreen@g.harvard.edu> | 2015-06-08 15:21:51 -0400 |
|---|---|---|
| committer | Ben Green <bgreen@g.harvard.edu> | 2015-06-08 15:21:51 -0400 |
| commit | 1739e9f5706bb8a73de5dbf0b467de49ea040898 (patch) | |
| tree | 6f1d0f166986c5f0757be9b40d8eeb3409ab022c /R Scripts/-generate-dag-dat-sim.R | |
| parent | e5dada202c34521618bf82a086093c342841e5e8 (diff) | |
| download | criminal_cascades-1739e9f5706bb8a73de5dbf0b467de49ea040898.tar.gz | |
added my R scripts
Diffstat (limited to 'R Scripts/-generate-dag-dat-sim.R')
| -rwxr-xr-x | R Scripts/-generate-dag-dat-sim.R | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/R Scripts/-generate-dag-dat-sim.R b/R Scripts/-generate-dag-dat-sim.R new file mode 100755 index 0000000..a6d115d --- /dev/null +++ b/R Scripts/-generate-dag-dat-sim.R @@ -0,0 +1,50 @@ +library(igraph) +setwd("/Users/Ben/Documents/Harvard/Fall 2014/CS 284r Social Data Mining/Cascade Project/") +load('Data/lcc_sim2a.RData') + +# d = remove.edge.attribute(person,'weight') +# lcc = induced.subgraph(d,which(clusters(d)$membership==which.max(clusters(d)$csize))) +# vic_ids = which(V(lcc)$vic==TRUE) +# dag = graph.empty(vcount(lcc)) +# dag = set.edge.attribute(dag,'weight',value=0) + +lcc = lcc.sim +vic_ids = vic_ids.sim +ei = 1 + +dag_dat = matrix(0,253096,5) +for (1 in 1:length(vic_ids)){ + if (i %% 100)==0) print(which(vic_ids==u)) + + u = vic_ids[i] + nbhd = unlist(neighborhood(lcc, nodes=u, order=3)) # get nodes within neighborhood + nbhd = intersect(vic_ids,nbhd) # only want victim nodes + nbhd = setdiff(nbhd,u) # don't want to include u in the neighborhood + + tu = as.numeric(V(lcc)$vic_date[u]) + tvs = as.numeric(V(lcc)$vic_date[nbhd]) + Es = tu<tvs + tvs = tvs[Es] + + if (sum(Es)>0){ + nbhd = nbhd[Es] + dists = as.numeric(shortest.paths(lcc,u,nbhd)) + + for (j in 1:sum(Es)){ + v = nbhd[j] + d = dists[j] + tv = tvs[j] +# dag_dat[ei,] = c(u,v,d,tu,tv) + dag_dat = rbind(dag_dat,c(u,v,d,tu,tv)) +# f = time(tu,tv) +# h = structural(d) +# weight[ei] = f*h + ei = ei+1 + } + } +} + +dag_dat = dag_dat[rowSums(dag_dat)>0,] +dag_dat = as.data.frame(dag_dat) +colnames(dag_dat) = c('from','to','dist','t1','t2') +# save(dag_dat,file='Data/dag_dat_sim2a.RData') |
