API reference
Docstrings
IndexedFactorGraphs.FactorGraph — TypeFactorGraph{T}A type representing a factor graph.
IndexedFactorGraphs.FactorGraph — MethodFactorGraph(A::AbstractMatrix)Construct a FactorGraph from adjacency matrix A with the convention that rows are factors, columns are variables.
IndexedFactorGraphs.FactorGraphVertex — TypeFactorGraphVertexA type to represent a vertex in a bipartite graph, to be passed as an argument to neighbors, inedges, outedges, see examples therein. It is recommended to use the v_vertex and f_vertex constructors.
IndexedFactorGraphs.InfiniteRegularFactorGraph — TypeInfiniteRegularFactorGraph <: AbstractFactorGraphA type to represent an infinite regular factor graph with fixed factor and variable degree
IndexedFactorGraphs.InfiniteRegularFactorGraph — MethodInfiniteRegularFactorGraph(kᵢ, kₐ)Construct an InfiniteRegularFactorGraph with variable degree kᵢ and factor degree kₐ
Graphs.edges — Methodedges(g::FactorGraph)Return a lazy iterator to the edges of g, with the convention that the source is the factor and the destination is the variable
julia> using IndexedFactorGraphs
julia> g = FactorGraph([0 1 1 0;
1 0 0 0;
0 0 1 1])
FactorGraph{Int64} with 4 variables, 3 factors, and 5 edges
julia> collect(edges(g))
5-element Vector{IndexedGraphs.IndexedEdge{Int64}}:
Indexed Edge 2 => 1 with index 1
Indexed Edge 1 => 2 with index 2
Indexed Edge 1 => 3 with index 3
Indexed Edge 3 => 3 with index 4
Indexed Edge 3 => 4 with index 5Graphs.neighbors — MethodIndexedGraphs.neighbors(g::FactorGraph, v::FactorGraphVertex)Return a lazy iterators to the neighbors of vertex v.
Examples
julia> using IndexedFactorGraphs
julia> g = FactorGraph([0 1 1 0;
1 0 0 0;
0 0 1 1])
FactorGraph{Int64} with 4 variables, 3 factors, and 5 edges
julia> collect(neighbors(g, v_vertex(3)))
2-element Vector{Int64}:
1
3
julia> collect(neighbors(g, f_vertex(2)))
1-element Vector{Int64}:
1IndexedFactorGraphs.eachfactor — Methodeachfactor(g::FactorGraph)Return a lazy iterator to the indices of factor vertices in g.
IndexedFactorGraphs.eachvariable — Methodeachvariable(g::FactorGraph)Return a lazy iterator to the indices of variable vertices in g.
IndexedFactorGraphs.edge_indices — Methodedge_indices(g::FactorGraph)Return a lazy iterator to the indices of the edges in g
IndexedFactorGraphs.edge_indices — Methodedge_indices(g::FactorGraph, v::FactorGraphVertex)Return a lazy iterator to the indices of the edges incident on vertex v, with v.
The output of edge_indices does not allocate and it can be used to index external arrays of properties directly
Examples
julia> using IndexedFactorGraphs, Test
julia> g = FactorGraph([0 1 1 0;
1 0 0 0;
0 0 1 1])
FactorGraph{Int64} with 4 variables, 3 factors, and 5 edges
julia> edgeprops = randn(ne(g));
julia> indices = (idx(e) for e in outedges(g, v_vertex(3)));
julia> indices_noalloc = edge_indices(g, v_vertex(3));
julia> @assert edgeprops[collect(indices)] == edgeprops[indices_noalloc]
julia> @test_throws ArgumentError edgeprops[indices]
Test Passed
Thrown: ArgumentErrorIndexedFactorGraphs.f_vertex — Methodf_vertex(a::Integer)Wraps index a in a container such that other functions like neighbors, inedges, outedges, knowing that it indices a factor vertex.
IndexedFactorGraphs.nfactors — Methodnactors(g::FactorGraph)Return the number of actors vertices in g.
IndexedFactorGraphs.nvariables — Methodnvariables(g::FactorGraph)Return the number of variables vertices in g.
IndexedFactorGraphs.pairwise_interaction_graph — Methodpairwise_interaction_graph(g::IndexedGraph)Construct a factor graph whose factors are the pair-wise interactions encoded in g.
IndexedFactorGraphs.rand_factor_graph — Methodrand_factor_graph([rng=default_rng()], nvar, nfact, ned)Create a factor graph with nvar variables, nfact factors and ned edges taken uniformly at random.
IndexedFactorGraphs.rand_factor_graph — Methodrand_factor_graph([rng=default_rng()], nvar, nfact, p)Create a factor graph with nvar variables, nfact factors and edges taken independently with probability p.
IndexedFactorGraphs.rand_regular_factor_graph — Methodrand_regular_factor_graph([rng=default_rng()], nvar, nfact, k)Create a factor graph with nvar variables and nfact factors, where all factors have degree k.
IndexedFactorGraphs.rand_tree_factor_graph — Methodrand_tree_factor_graph([rng=default_rng()], n)Create a tree factor graph with n vertices in total. The proportion of variables/factors is casual.
IndexedFactorGraphs.v_vertex — Methodv_vertex(i::Integer)Wraps index i in a container such that other functions like neighbors, inedges, outedges, knowing that it indices a variable vertex.
IndexedGraphs.inedges — MethodIndexedGraphs.inedges(g::FactorGraph, v::FactorGraphVertex)Return a lazy iterators to the edges incident on vertex v, with v as the destination.
Examples
julia> using IndexedFactorGraphs
julia> g = FactorGraph([0 1 1 0;
1 0 0 0;
0 0 1 1])
FactorGraph{Int64} with 4 variables, 3 factors, and 5 edges
julia> collect(inedges(g, f_vertex(2)))
1-element Vector{IndexedGraphs.IndexedEdge{Int64}}:
Indexed Edge 1 => 2 with index 1
julia> collect(inedges(g, v_vertex(3)))
2-element Vector{IndexedGraphs.IndexedEdge{Int64}}:
Indexed Edge 1 => 3 with index 3
Indexed Edge 3 => 3 with index 4IndexedGraphs.outedges — MethodIndexedGraphs.outedges(g::FactorGraph, v::FactorGraphVertex)Return a lazy iterators to the edges incident on vertex v, with v as the source.
Examples
julia> using IndexedFactorGraphs
julia> g = FactorGraph([0 1 1 0;
1 0 0 0;
0 0 1 1])
FactorGraph{Int64} with 4 variables, 3 factors, and 5 edges
julia> collect(outedges(g, f_vertex(2)))
1-element Vector{IndexedGraphs.IndexedEdge{Int64}}:
Indexed Edge 2 => 1 with index 1
julia> collect(outedges(g, v_vertex(3)))
2-element Vector{IndexedGraphs.IndexedEdge{Int64}}:
Indexed Edge 3 => 1 with index 3
Indexed Edge 3 => 3 with index 4RecipesBase.plot — Methodplot(g::FactorGraph; kwargs...)Plot factor graph g with boxes for factor nodes and circles for variable nodes. It is based on GraphRecipes.graphplot.
Optional arguments
shownames: if set totrue, displays the index on every node- optional arguments to
graphplot
Examples
julia> using IndexedFactorGraphs
julia> using Plots, GraphRecipes
julia> g = FactorGraph([0 1 1 0;
1 0 1 0;
0 0 1 1])
FactorGraph{Int64} with 3 factors, 4 variables and 6 edges
julia> plot(g)Index
IndexedFactorGraphs.FactorGraphIndexedFactorGraphs.FactorGraphIndexedFactorGraphs.FactorGraphVertexIndexedFactorGraphs.InfiniteRegularFactorGraphIndexedFactorGraphs.InfiniteRegularFactorGraphGraphs.edgesGraphs.neighborsIndexedFactorGraphs.eachfactorIndexedFactorGraphs.eachvariableIndexedFactorGraphs.edge_indicesIndexedFactorGraphs.edge_indicesIndexedFactorGraphs.f_vertexIndexedFactorGraphs.nfactorsIndexedFactorGraphs.nvariablesIndexedFactorGraphs.pairwise_interaction_graphIndexedFactorGraphs.rand_factor_graphIndexedFactorGraphs.rand_factor_graphIndexedFactorGraphs.rand_regular_factor_graphIndexedFactorGraphs.rand_tree_factor_graphIndexedFactorGraphs.v_vertexIndexedGraphs.inedgesIndexedGraphs.outedgesRecipesBase.plot