Skip to content

Commit

Permalink
Merge pull request #2 from ranjanan/demo
Browse files Browse the repository at this point in the history
Demo
  • Loading branch information
ranjanan committed Mar 15, 2016
2 parents 7b98419 + cef1ed0 commit d82173b
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
69 changes: 63 additions & 6 deletions graph/demo.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using JLD
using Gunrock

function init_parts()
a = load("../graph.jld")["T"]
function init_parts(a::SparseMatrixCSC)
I, J, V = findnz(a)
len = Int(length(I)/2)
i1 = I[1:len]
Expand All @@ -27,11 +26,12 @@ function makesquare(a::SparseMatrixCSC)
amod = amod + amod'
end

function main()
function setup()
a = load("../graph.jld")["T"]
info("Reading input . . .")
a1, a2 = init_parts()
a1, a2 = init_parts(a)
info("Done.")
scores = Array(Float32, size(a1, 1))
scores = Array(Float32, size(a, 1))
info("Calculating pagerank for the first timestep")
n1, r1 = pagerank(a1)
info("Updating scores.")
Expand All @@ -40,5 +40,62 @@ function main()
n2, r2 = pagerank(a2)
info("Updating scores.")
scores[n2] += r2
scores
amod = makesquare(a)
amod , scores
end

function generate_new_graph(l::Integer)
a = sprand(l, l, 1/l)
a + a'
end

function monitor(a_original::SparseMatrixCSC, scores::Vector{Float32})
l = size(a_original, 1)
i = 3
while i<=20
#Normalize scores
scores = scores / sum(scores)

#Iteration
info("Time step $i")

#New set of activity
a_new = generate_new_graph(l)

#Update state
a_updated = a_original + a_new

#perform pagerank
n, r = pagerank(a_updated)

#Normalize scores
r = r / sum(r)

#Difference and normalize
diff = abs(scores[n] - r)

#Find max diff
val, pos = findmax(diff)
@show val

#Check if diff is too much
if val > 0.15
node = n[pos]
info("Alert at node $node !")
break
end

#Update scores
scores = scores + diff

#Update Iteration
i += 1

end
a_original, scores
end

function driver()
a_original, scores = setup()
a, s = monitor(a_original, scores)
end
14 changes: 14 additions & 0 deletions graph/grad.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Gunrock
function vulnerability(a::SparseMatrixCSC, n::Integer)
l = size(a, 1)
d = Dict{Int,Vector{Int}}()
dists = sssp(a, n)
max = maximum(dists)
for i = 0:max
setindex!(d, Int[], i)
end
for i = 1:l
push!(d[dists[i]], i)
end
d
end

0 comments on commit d82173b

Please sign in to comment.