-
Notifications
You must be signed in to change notification settings - Fork 2
/
DEMO.jl
116 lines (91 loc) · 3.19 KB
/
DEMO.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
####################
####### DEMO #######
####################
## import required packages ##
using Distributions
import LightGraphs
import Gadfly
import Plots
Plots.gr()
using LaTeXStrings
include("rw_smc.jl")
include("utils.jl")
include("rand_rw.jl")
include("gibbs_updates.jl")
# set seed
srand(0)
########################
######### DATA #########
########################
######### SYNTHETIC #########
syn_data = true
# set synthetic data parameters
n_edges_data = 25 # number of edges
α = 0.25 # parameter for new vertex probability
λ = 4.0 # paramter for random walk length distribution
ld = Poisson(λ) # random walk length distribution (automatically shifted by +1 if minimum is zero)
sb = true # degree-biased distribution for first vertex at each step (false for uniform distribution)
# sample simple graph (returns edge list)
g = randomWalkSimpleGraph(n_edges=n_edges_data,alpha_prob=α,length_distribution=ld,sizeBias=sb)
# convert edge list to adjacency matrix
A = edgelist2adj(g)
Gadfly.spy(A)
######### REAL DATA #########
syn_data = false
# SJS
# g = readcsv("data/sjsAdj.csv",Int64)
# NIPS
g = readcsv("data/nipsAdj_02_03.csv",Int64)
# PPI
# g = readcsv("data/interactomeAdj.csv",Int64)
n_edges_data = size(g,1)
# convert edge list to adjacency matrix
A = edgelist2adj(g)
Gadfly.spy(A)
######################################
# INTERFACE WITH LIGHTGRAPHS PACKAGE #
######################################
# create LightGraphs.Graph object for use with LightGraphs functions
lg = LightGraphs.Graph(A)
# Examples:
lg_conn = LightGraphs.is_connected(lg)
lg_diam = LightGraphs.diameter(lg)
#######################################
#### RUN SMC WITH FIXED PARAMETERS ####
#######################################
n_particles = 100
α_fixed = α
λ_fixed = λ
particle_paths,log_marginal = SMC(g,n_particles,α_fixed,λ_fixed,sb)
############################
#### RUN PARTICLE GIBBS ####
############################
# set sampler parameters
n_particles = 100
n_mcmc_iter = 500 # total number of iterations; includes burn-in
n_burn = 100 # burn-in
n_collect = 10 # collect a sample every n_collect iterations
k_trunc = 10*lg_diam # truncation for support of latent K distribution
# set starting values for sampling (can be anything)
α_start = convert(Float64,0.5*(maximum(g)-1)/(n_edges_data-1))
λ_start = convert(Float64,sqrt(lg_diam))
# set prior parameters
a_α = 1.0
b_α = 1.0
a_λ = 1.0
b_λ = 0.25
n_print = 1 # print progress updates every n_print iterations
samples = ParticleGibbs(g,n_particles,
a_α,b_α,a_λ,b_λ,
α_start,λ_start,sb,k_trunc,
n_mcmc_iter,n_burn,n_collect,n_print)
# plot samples
Plots.scatter(samples["lambda"],samples["alpha"],legend=false,
ylims=[0,1],xlims=[0,15],
markershape=:circle,markersize=5.5,markeralpha=0.7,markercolor=:grey,markerstrokewidth=0.0,
xlabel=L"\lambda",ylabel=L"\alpha")
if syn_data
Plots.scatter!([λ],[α],legend=false,marker=(:star4,12.0,1.0,:black))
end
# plot edge sequence
Plots.plot(samples["edge_sequence"]',legend=false,xlabel="Sampled arrival order",ylabel="Edge index")