Reference
Utilities
MLNABCDGraphGenerator.MLNConfig — TypeMLNConfig(
seed::Union{Int,Nothing},
n::Int,
edges_cor::String,
layer_params::String,
d_max_iter::Int,
c_max_iter::Int,
t::Int,
eps::Float64,
d::Int,
edges_filename::String,
communities_filename::String)
::MLNConfigCreates MLNABCD configuration struct.
Arguments
filename::Stringconfiguration file name
MLNABCDGraphGenerator.parse_config — Functionparse_config(filename::String)::MLNConfigParse configuration file into MLNABCD configuration struct.
Arguments
filename::Stringconfiguration file name
MLNABCDGraphGenerator.write_edges — Functionwrite_edges(cfg::MLNConfig, edges::Vector{Set{Tuple{Int,Int}}})Saves edges of multilayer network in cfg.edges_filename file.
Arguments
cfg::MLNConfigMLNABCD configurationedges::Vector{Set{Tuple{Int,Int}}}edges between agents in each layer
MLNABCDGraphGenerator.write_communities — Functionwrite_communities(cfg::MLNConfig, coms::Vector{Vector{Int}})Saves communities of multilayer network in cfg.communities_filename file.
Arguments
cfg::MLNConfigMLNABCD configurationcoms::Vector{Vector{Int}}assignment of agents to communities for each layer
Phase 1 - Active Nodes
MLNABCDGraphGenerator.generate_active_nodes — Functiongenerate_active_nodes(cfg::MLNConfig)::Vector{Vector{Int}}Samples active nodes for each layer.
Arguments
cfg::MLNConfigMLNABCD configuration
Phase 2 - Degrees Correlation
MLNABCDGraphGenerator.sample_ranking — Functionsample_ranking(vs::Vector{Int}, n::Int, sigma::AbstractFloat)::Vector{Vector{Int}}Returns ranking of samples of random variables N(v/n,sigma).
Arguments
vs::Vector{Int}vector with IDs of active agentsn::Intnumber of agentssigma::AbstractFloatstandard deviation of normal distribution N(v/n,sigma)
MLNABCDGraphGenerator.find_ranking — Functionfind_ranking(ns::Int, n::Int, tau::AbstractFloat, verbose::Bool=false, limit::Int=20)Finds ordering of labels of agents which has tau Kendall-tau correlation with ordered labels sequence.
Arguments
ns::Intnumber of active agentsn::Intnumber of agentstau::AbstractFloatdesired Kendall-tau correlation valueverbose::Bool=falseverbose logging flaglimit::Int=20number of rankings sampled to find the best correlation match
MLNABCDGraphGenerator.degrees_correlation — Functiondegrees_correlation(
cfg::MLNConfig,
degs::Vector{Vector{Int}},
active_nodes::Vector{Vector{Int}},
verbose::Bool=false)
::Vector{Vector{Int}}Creates correlated sequences of degrees for all layers of the network.
Arguments
cfg::MLNConfigMLNABCD configurationdegs::Vector{Vector{Int}}sorted (input) sequences of degreesactive_nodes::Vector{Vector{Int}}IDs of active nodesverbose::Bool=falseverbose logging flag
MLNABCDGraphGenerator.generate_degrees — Functiongenerate_degrees(cfg::MLNConfig,
active_nodes::Vector{Vector{Int}},
verbose::Bool=false)
::Vector{Vector{Int}}Samples sequences of degrees from truncated power-law distribution and reorder the sequences to correlate layers.
Arguments
cfg::MLNConfigMLNABCD configurationactive_nodes::Vector{Vector{Int}}IDs of active nodesverbose::Bool=falseverbose logging flag
Phase 3 - Communities Correlation
MLNABCDGraphGenerator.sample_points — Functionsample_points(n::Int, d::Int)::Matrix{Float64}Samples normalized points in d-dimensional space.
Arguments
n::Intnumber of pointsd::Intnumber of dimensions
MLNABCDGraphGenerator.assign_points — Functionassign_points(x::Matrix{Float64}, c::Vector{Int})::Vector{Vector{Int}}Assigns points to communities based on the proximity in Euclidian space.
Arguments
x::Matrix{Float64}coordinates of pointsc::Vector{Int}sizes of communities
MLNABCDGraphGenerator.shuffle_communities — Functionshuffle_communities(r::Float64, a::Vector{Vector{Int}})::Vector{Vector{Int}}Shuffles assignment of nodes to communities to introduce correlation r between the layer and reference layer
Arguments
r::Float64desired correlation between the layer and reference layera::Vector{Vector{Int}}assignment of nodes to communities
MLNABCDGraphGenerator.communities_correlation — Functioncommunities_correlation(
n::Int,
coms_sizes::Vector{Vector{Int}},
rs::Vector{Float64},
active_nodes::Vector{Vector{Int}},
d::Int)
::Vector{Vector{Int}}Shuffles communities assignment to match correlations rs between network layers and hidden reference layer.
Arguments
n::Intnumber of agentscoms_sizes::Vector{Vector{Int}}sizes of communitiesrs::Vector{Float64}vector of desired correlations between each network layer and reference layeractive_nodes::Vector{Vector{Int}}IDs of active nodesd::Intnumber of dimensions in reference space
MLNABCDGraphGenerator.generate_communities — Functiongenerate_communities(cfg::MLNConfig, active_nodes::Vector{Vector{Int}})Samples sequences of community sizes from truncated power-law distribution. Then, assigns nodes to communities and shuffles the assignment to correlate layers. Returns sizes of communities and assignment of nodes to communities.
Arguments
cfg::MLNConfigMLNABCD configurationactive_nodes::Vector{Vector{Int}}IDs of active nodes
Phase 4 and 5 - Edges generation
MLNABCDGraphGenerator.generate_abcd — Functiongenerate_abcd(cfg::MLNConfig, degs::Vector{Vector{Int}},
coms_sizes::Vector{Vector{Int}}, coms::Vector{Vector{Int}})
::Vector{Set{Tuple{Int,Int}}}Generates edges of multilayer network using ABCD model.
Arguments
cfg::MLNConfigMLNABCD configurationdegs::Vector{Vector{Int}}degree sequences for active nodescoms_sizes::Vector{Vector{Int}}community sizescoms::Vector{Vector{Int}}assignment of active nodes to communities
Phase 6 - Edges correlation
MLNABCDGraphGenerator.map_edges_to_agents — Functionmap_edges_to_agents(edges::Vector{Set{Tuple{Int64,Int64}}}, active_nodes::Vector{Vector{Int64}})Translates edges to agent-based representation.
Arguments
edges::Vector{Set{Tuple{Int64,Int64}}}edges based on layer-specific node labelsactive_nodes::Vector{Vector{Int64}}IDs of active agents
MLNABCDGraphGenerator.map_communities_to_agents — Functionmap_communities_to_agents(
n_agents::Int,
communities::Vector{Vector{Int64}},
active_nodes::Vector{Vector{Int64}})Translates communities assignment to agent-based representation and imputes 0 for non-active agents.
Arguments
n_agents::Intnumber of agentscommunities::Vector{Vector{Int64}}assignment of nodes to communitiesactive_nodes::Vector{Vector{Int64}}IDs of active agents
MLNABCDGraphGenerator.common_agents_dict — Functioncommon_agents_dict(active_nodes::Vector{Vector{Int64}})Finds common active agents between all pairs of layers.
Arguments
active_nodes::Vector{Vector{Int64}}IDs of active agents
MLNABCDGraphGenerator.common_agents_edges — Functioncommon_agents_edges(
edges_agents::Vector{Set{Tuple{Int64,Int64}}},
common_agents_dict::Dict{Tuple{Int,Int},Set{Int}})Finds edges including only common active agents for all pairs of layers.
Arguments
edges_agents::Vector{Set{Tuple{Int64,Int64}}}agent-based edges of multilayer networkcommon_agents_dict::Dict{Tuple{Int,Int},Set{Int}}mapping of common active agents between layers
MLNABCDGraphGenerator.map_neighbours — Functionmap_neighbours(edges::Set{Tuple{Int,Int}}, coms::Vector{Int})Finds neigbhours of each agent within and outside of given node community.
Arguments
edges::Set{Tuple{Int,Int}}agent-based edges of multilayer networkcoms::Vector{Int}assignment of nodes to communities
MLNABCDGraphGenerator.map_communities — Functionmap_communities(edges::Set{Tuple{Int,Int}}, coms::Vector{Int})Finds edges within communities and background graph.
Arguments
edges::Set{Tuple{Int,Int}}agent-based edges of multilayer networkcoms::Vector{Int}assignment of nodes to communities
MLNABCDGraphGenerator.neighbours_common_agents_edges — Functionneighbours_common_agents_edges(
edges_common_agents::Dict{Tuple{Int,Int},Vector{Set{Tuple{Int,Int}}}},
coms_agents::Vector{Vector{Int64}})Finds neighbours of each agent in graphs induced by common agents between layers.
Arguments
edges_common_agents::Dict{Tuple{Int,Int},Vector{Set{Tuple{Int,Int}}}}graphs induced by common agents between layerscoms_agents::Vector{Vector{Int64}}assignment of nodes to communities in each layer
MLNABCDGraphGenerator.edges_in_communities_common_agents_edges — Functionedges_in_communities_common_agents_edges(
edges_common_agents::Dict{Tuple{Int,Int},Vector{Set{Tuple{Int,Int}}}},
coms_agents::Vector{Vector{Int64}})Finds edges within communities and background graph in graphs induced by common agents between layers.
Arguments
edges_common_agents::Dict{Tuple{Int,Int},Vector{Set{Tuple{Int,Int}}}}graphs induced by common agents between layerscoms_agents::Vector{Vector{Int64}}assignment of nodes to communities in each layer
MLNABCDGraphGenerator.calculate_edges_cor — Functioncalculate_edges_cor(
edges_common_agents::Dict{Tuple{Int,Int},Vector{Set{Tuple{Int,Int}}}},
desired_cor::Matrix{Float64})Calculates correlation between edges in each pair of layers, difference between desired correlation and distance between desired correlation matrix and current correlation matrix.
Arguments
edges_common_agents::Dict{Tuple{Int,Int},Vector{Set{Tuple{Int,Int}}}}graphs induced by common agents between layersdesired_cor::Matrix{Float64}input correlation matrix between layers
MLNABCDGraphGenerator.pick_cor_to_improve — Functionpick_cor_to_improve(cor_diff::Matrix{Float64}, method::String="weighted")Selects entry of correlation matrix to improve in next batch.
Arguments
cor_diff::Matrix{Float64}difference between desired and current correlation matricesmethod::String="weighted"method of entry selection
MLNABCDGraphGenerator.write_cor_diff_to_file — Functionwrite_cor_diff_to_file(io::IOStream, cor_diff::Matrix{Float64}, cor_dist::Float64)Writes differences between current and desired correlation matrices entries to file. Used to track changes in empirical correlation between batches.
Arguments
io::IOStreamIO handler to a filecor_diff::Matrix{Float64}difference between desired and current correlation matricescor_dist::Float64distance between desired and current correlation matrices
MLNABCDGraphGenerator.increase_edges_correlation! — Functionincrease_edges_correlation!(layers::Tuple{Int,Int},
edges::Vector{Set{Tuple{Int,Int}}},
edges_common::Vector{Set{Tuple{Int,Int}}},
neighbours::Vector{Dict{Int,Set{Int}}},
coms_agents::Vector{Vector{Int}},
perc_rewire::Float64,
verbose::Bool=false)Increases correlation between edges in two selected layers.
Arguments
layers::Tuple{Int,Int}IDs of modified layersedges::Vector{Set{Tuple{Int,Int}}}edges of multilayer network modified in-place to keep state between batchesedges_common::Vector{Set{Tuple{Int,Int}}}edges on common active agents between layersneighbours::Vector{Dict{Int,Set{Int}}}mapping of neighbours of agentscoms_agents::Vector{Vector{Int}}assignment of agents to communitiesperc_rewire::Float64fraction of edges to be used for rewiring attemptverbose::Bool=falseverbose logging flag
MLNABCDGraphGenerator.decrease_edges_correlation! — Functiondecrease_edges_correlation!(layers::Tuple{Int,Int},
edges::Vector{Set{Tuple{Int,Int}}},
edges_common::Vector{Set{Tuple{Int,Int}}},
neighbours::Vector{Dict{Int,Set{Int}}},
coms_agents::Vector{Vector{Int}},
perc_rewire::Float64,
verbose::Bool=false)Decreases correlation between edges in two selected layers.
Arguments
layers::Tuple{Int,Int}IDs of modified layersedges::Vector{Set{Tuple{Int,Int}}}edges of multilayer network modified in-place to keep state between batchesedges_common::Vector{Set{Tuple{Int,Int}}}edges on common active agents between layersedges_in_coms::Vector{Dict{Int,Set{Tuple{Int,Int}}}}mapping of edges withing communities and background graphcoms_agents::Vector{Vector{Int}}assignment of agents to communitiesperc_rewire::Float64fraction of edges to be used for rewiring attemptverbose::Bool=falseverbose logging flag
MLNABCDGraphGenerator.adjust_edges_correlation — Functionadjust_edges_correlation(cfg::MLNConfig,
edges::Vector{Set{Tuple{Int,Int}}},
coms::Vector{Vector{Int}},
active_nodes::Vector{Vector{Int}},
verbose::Bool=false,
save_cor_change_to_file::Bool=false)Run cfg.t rewiring batches to match edges correlation between layers with desired cfg.edges_cor_matrix correlation matrix.
Arguments
cfg::MLNConfigMLNABCD configurationedges::Vector{Set{Tuple{Int,Int}}}agent-based edges of multilayer network before rewiringcoms::Vector{Vector{Int}}assignment of nodes to communities in each layeractive_nodes::Vector{Vector{Int}}IDs of active agentsverbose::Bool=falseverbose logging flagsave_cor_change_to_file::Bool=falsecorrelation changes file logging flag