Skip to content

Instantly share code, notes, and snippets.

View davibarreira's full-sized avatar

Davi Sales Barreira davibarreira

View GitHub Profile
@davibarreira
davibarreira / ckb_juliagraph4.jl
Created November 7, 2020 15:36
MST with Julia
g_mst = SimpleWeightedGraph(ncol(df))
for i in kruskal_mst(g,minimize=false)
add_edge!(g_mst,i.src,i.dst,i.weight)
end
gplot(g_mst,nodelabel=names(df))
@davibarreira
davibarreira / ckb_juliagraph3.jl
Created November 7, 2020 15:18
Visualizing graph centrality
centrality = betweenness_centrality(g,normalize=false).+1
alphas = centrality./maximum(centrality).*10
nodefillc = [RGBA(0.0,0.8,0.8,i) for i in alphas]
gplot(g,nodelabel=names(df),edgelinewidth=ew,nodefillc=nodefillc)
@davibarreira
davibarreira / ckb_juliagraph2.jl
Last active November 7, 2020 15:04
Adding edges to graph
ew = Int[]
for i in 1:ncol(df), j in i+1:ncol(df) # iterate over all combinations of columns
w = dot(df[!, i], df[!, j]) # calculate how many times (i,j) occurs
if w > 0
push!(ew, w)
add_edge!(g, i, j, w)
end
end
@davibarreira
davibarreira / ckb_juliagraph1.jl
Last active September 26, 2022 08:32
Importing Data and Creating Graph
using GraphPlot, SimpleWeightedGraphs, LinearAlgebra, DataFrames, Random, CSV, Colors
Random.seed!(7)
df = DataFrame(rand([0,1],10,20),:auto);
g = SimpleWeightedGraph(ncol(df))