Skip to content

Commit 2e769fa

Browse files
committed
Merge branch 'master' into fix/3Q19/56
2 parents 857439a + 35db02e commit 2e769fa

File tree

28 files changed

+848
-371
lines changed

28 files changed

+848
-371
lines changed

Project.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
77
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
88
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
99
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
10+
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
1011
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1112
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
1213
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
1314
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1415
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
15-
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
1616
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1717
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1818
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -28,6 +28,8 @@ julia = "0.7, 1"
2828

2929
[extras]
3030
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
31+
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
32+
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
3133

3234
[targets]
33-
test = ["Test"]
35+
test = ["Test", "GraphPlot", "Neo4j"]

docs/src/func_ref.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ getSubgraphAroundNode
5858
getSubgraph
5959
```
6060

61-
### Visualization
61+
### Summaries
62+
```@docs
63+
getSummary
64+
getSummaryGraph
65+
```
66+
67+
### Visualization and Plotting
6268
```@docs
6369
toDot
6470
toDotFile
71+
dfgplot
6572
```

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,11 +789,11 @@ end
789789

790790
function getAdjacencyMatrixSparse(dfg::CloudGraphsDFG)::Tuple{SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
791791
varLabels = getVariableIds(dfg)
792-
factLabels = sort(getFactorIds(dfg))
793-
vDict = Dict(varLabels .=> [1:length(varLabels)...].+1)
794-
fDict = Dict(factLabels .=> [1:length(factLabels)...].+1)
792+
factLabels = getFactorIds(dfg)
793+
vDict = Dict(varLabels .=> [1:length(varLabels)...])
794+
fDict = Dict(factLabels .=> [1:length(factLabels)...])
795795

796-
adjMat = spzeros(Int, length(factLabels)+1, length(varLabels)+1)
796+
adjMat = spzeros(Int, length(factLabels), length(varLabels))
797797

798798
# Now ask for all relationships for this session graph
799799
loadtx = transaction(dfg.neo4jInstance.connection)

src/Common.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export sortVarNested
1+
2+
export sortVarNested, sortDFG
23
export isPrior, lsfPriors
34
export getVariableType, getSofttype
45
export getFactorType, getfnctype
@@ -88,6 +89,24 @@ function sortVarNested(vars::Vector{Symbol})::Vector{Symbol}
8889
return retvars
8990
end
9091

92+
"""
93+
$SIGNATURES
94+
95+
Sort variable (factor) lists in a meaningful way, for example `[:april;:x1_3;:x1_6;]`
96+
97+
Notes
98+
- Not fool proof, but does better than native sort.
99+
100+
Example
101+
102+
`sortDFG(ls(dfg))`
103+
104+
Related
105+
106+
ls, lsf
107+
"""
108+
sortDFG(vars::Vector{Symbol})::Vector{Symbol} = sortVarNested(vars)
109+
91110
"""
92111
$SIGNATURES
93112

src/DFGPlots/DFGPlots.jl

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Colors
44
using LightGraphs
55
using MetaGraphs
66
using GraphPlot
7+
using DocStringExtensions
78
import GraphPlot: gplot
89

910
using ...DistributedFactorGraphs
@@ -28,6 +29,26 @@ DFGPlotProps() = DFGPlotProps( (var=colorant"seagreen", fac=colorant"cyan3"),
2829
true)
2930

3031

32+
33+
"""
34+
$(SIGNATURES)
35+
Plots the structure of the factor graph. GraphPlot must be imported before DistributedFactoGraphs for these functions to be available.
36+
Returns the plot context.
37+
38+
E.g.
39+
```
40+
using GraphPlot
41+
using DistributedFactorGraphs, DistributedFactorGraphs.DFGPlots
42+
# ... Make graph...
43+
# Using GraphViz plotting
44+
dfgplot(fg)
45+
# Save to PDFG
46+
using Compose
47+
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(fg))
48+
```
49+
50+
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
51+
"""
3152
function dfgplot(dfg::LightDFG, p::DFGPlotProps = DFGPlotProps())
3253

3354
nodetypes = [haskey(dfg.g.variables, s) for s in dfg.g.labels]
@@ -46,6 +67,25 @@ function dfgplot(dfg::LightDFG, p::DFGPlotProps = DFGPlotProps())
4667

4768
end
4869

70+
"""
71+
$(SIGNATURES)
72+
Plots the structure of the factor graph. GraphPlot must be imported before DistributedFactoGraphs for these functions to be available.
73+
Returns the plot context.
74+
75+
E.g.
76+
```
77+
using GraphPlot
78+
using DistributedFactorGraphs, DistributedFactorGraphs.DFGPlots
79+
# ... Make graph...
80+
# Using GraphViz plotting
81+
dfgplot(fg)
82+
# Save to PDFG
83+
using Compose
84+
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(fg))
85+
```
86+
87+
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
88+
"""
4989
function dfgplot(dfg::MetaGraphsDFG, p::DFGPlotProps = DFGPlotProps())
5090

5191
nodesize = [has_prop(dfg.g,i,:factor) ? p.nodesize.fac : p.nodesize.var for i=vertices(dfg.g)]
@@ -60,14 +100,32 @@ function dfgplot(dfg::MetaGraphsDFG, p::DFGPlotProps = DFGPlotProps())
60100

61101
end
62102

103+
"""
104+
$(SIGNATURES)
105+
Plots the structure of the factor graph. GraphPlot must be imported before DistributedFactoGraphs for these functions to be available.
106+
Returns the plot context.
107+
108+
E.g.
109+
```
110+
using GraphPlot
111+
using DistributedFactorGraphs, DistributedFactorGraphs.DFGPlots
112+
# ... Make graph...
113+
# Using GraphViz plotting
114+
dfgplot(fg)
115+
# Save to PDFG
116+
using Compose
117+
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(fg))
118+
```
119+
120+
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
121+
"""
63122
function dfgplot(dfg::AbstractDFG, p::DFGPlotProps = DFGPlotProps())
64123
# TODO implement convert functions
65124
@warn "TODO Implement convert"
66125
ldfg = MetaGraphsDFG{AbstractParams}()
67126
DistributedFactorGraphs._copyIntoGraph!(dfg, ldfg, union(getVariableIds(dfg), getFactorIds(dfg)), true)
68127

69128
dfgplot(ldfg, p)
70-
71129
end
72130

73131
function gplot(dfg::MetaGraphsDFG; keyargs...)

src/DistributedFactorGraphs.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,18 @@ using LinearAlgebra
1111
using SparseArrays
1212

1313
# Entities
14-
include("entities/AbstractTypes.jl")
14+
include("entities/AbstractDFG.jl")
1515
include("entities/DFGFactor.jl")
1616
include("entities/DFGVariable.jl")
17+
include("entities/AbstractDFGSummary.jl")
1718

1819
export AbstractDFG
1920
export AbstractParams, NoSolverParams
20-
export DFGNode
21-
22-
export DFGFactor
21+
export DFGNode, DFGVariable, DFGFactor
2322
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable, ConvolutionObject
24-
2523
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
26-
27-
export DFGVariable
28-
export label, timestamp, tags, estimates, estimate, solverData, getData, solverDataDict, internalId, smallData, bigData
29-
export setSolverData
30-
export label, data, id
24+
export label, timestamp, tags, estimates, estimate, data, solverData, getData, solverDataDict, setSolverData, internalId, smallData, bigData
25+
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
3126

3227
# Services/AbstractDFG Exports
3328
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
@@ -42,9 +37,16 @@ export pack, unpack
4237
#Interfaces
4338
export getAdjacencyMatrixSparse
4439

40+
# File import and export
41+
export saveDFG, loadDFG
42+
43+
# Summary functions
44+
export getSummary, getSummaryGraph
45+
4546
# Common includes
4647
include("services/AbstractDFG.jl")
4748
include("services/DFGVariable.jl")
49+
include("services/DFGFactor.jl")
4850

4951
# Include the Graphs.jl API.
5052
include("GraphsDFG/GraphsDFG.jl")
@@ -61,8 +63,6 @@ include("SymbolDFG/SymbolDFG.jl")
6163
include("LightDFG/LightDFG.jl")
6264
@reexport using .LightDFGs
6365

64-
export saveDFG, loadDFG
65-
6666
function __init__()
6767
@require Neo4j="d2adbeaf-5838-5367-8a2f-e46d570981db" begin
6868
# Include the Cloudgraphs API

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -366,68 +366,10 @@ function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, in
366366
return addToDFG
367367
end
368368

369-
"""
370-
$(SIGNATURES)
371-
Get an adjacency matrix for the DFG, returned as a Matrix{Union{Nothing, Symbol}}.
372-
Rows are all factors, columns are all variables, and each cell contains either nothing or the symbol of the relating factor.
373-
The first row and first column are factor and variable headings respectively.
374-
"""
375-
function getAdjacencyMatrix(dfg::GraphsDFG)::Matrix{Union{Nothing, Symbol}}
376-
varLabels = sort(map(v->v.label, getVariables(dfg)))
377-
factLabels = sort(map(f->f.label, getFactors(dfg)))
378-
vDict = Dict(varLabels .=> [1:length(varLabels)...].+1)
379-
380-
adjMat = Matrix{Union{Nothing, Symbol}}(nothing, length(factLabels)+1, length(varLabels)+1)
381-
# Set row/col headings
382-
adjMat[2:end, 1] = factLabels
383-
adjMat[1, 2:end] = varLabels
384-
for (fIndex, factLabel) in enumerate(factLabels)
385-
factVars = getNeighbors(dfg, getFactor(dfg, factLabel))
386-
map(vLabel -> adjMat[fIndex+1,vDict[vLabel]] = factLabel, factVars)
387-
end
388-
return adjMat
389-
end
390-
391-
function getAdjacencyMatrixSparse(dfg::GraphsDFG)::Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
392-
varLabels = map(v->v.label, getVariables(dfg))
393-
factLabels = map(f->f.label, getFactors(dfg))
394-
395-
vDict = Dict(varLabels .=> [1:length(varLabels)...])
396-
397-
adjMat = spzeros(Int, length(factLabels), length(varLabels))
398-
399-
for (fIndex, factLabel) in enumerate(factLabels)
400-
factVars = getNeighbors(dfg, getFactor(dfg, factLabel))
401-
map(vLabel -> adjMat[fIndex,vDict[vLabel]] = 1, factVars)
402-
end
403-
return adjMat, varLabels, factLabels
404-
end
405-
406369
"""
407370
$(SIGNATURES)
408371
Produces a dot-format of the graph for visualization.
409372
"""
410373
function toDot(dfg::GraphsDFG)::String
411-
m = PipeBuffer()
412-
write(m,Graphs.to_dot(dfg.g))
413-
data = take!(m)
414-
close(m)
415-
return String(data)
416-
end
417-
418-
"""
419-
$(SIGNATURES)
420-
Produces a dot file of the graph for visualization.
421-
Download XDot to see the data
422-
423-
Note
424-
- Default location "/tmp/dfg.dot" -- MIGHT BE REMOVED
425-
- Can be viewed with the `xdot` system application.
426-
- Based on graphviz.org
427-
"""
428-
function toDotFile(dfg::GraphsDFG, fileName::String="/tmp/dfg.dot")::Nothing
429-
open(fileName, "w") do fid
430-
write(fid,Graphs.to_dot(dfg.g))
431-
end
432-
return nothing
374+
return Graphs.to_dot(dfg.g)
433375
end

src/LightDFG/FactorGraphs/FactorGraphs.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ export
3131
filter_vertices,
3232
reverse
3333

34-
import DistributedFactorGraphs: DFGNode
35-
const AbstractNodeType = DFGNode
34+
# import DistributedFactorGraphs: DFGNode
35+
# const AbstractNodeType = DFGNode
36+
import DistributedFactorGraphs: AbstractDFGVariable, AbstractDFGFactor
37+
const AbstractVariableType = AbstractDFGVariable
38+
const AbstractFactorType = AbstractDFGFactor
3639

3740
include("BiMaps.jl")
3841

39-
struct FactorGraph{T <: Integer,V <: AbstractNodeType, F <: AbstractNodeType} <: AbstractGraph{T}
42+
struct FactorGraph{T <: Integer,V <: AbstractVariableType, F <: AbstractFactorType} <: AbstractGraph{T}
4043
graph::SimpleGraph{T}
4144
labels::BiDictMap{T}
4245
variables::Dict{Symbol,V}
4346
factors::Dict{Symbol,F}
4447
end
4548

46-
function FactorGraph{T, V, F}(nv::Int=100, nf::Int=100) where {T <: Integer, V <: AbstractNodeType, F <: AbstractNodeType}
49+
function FactorGraph{T, V, F}(nv::Int=100, nf::Int=100) where {T <: Integer, V <: AbstractVariableType, F <: AbstractFactorType}
4750
fadjlist = Vector{Vector{T}}()
4851
sizehint!(fadjlist, nv + nf)
4952
g = SimpleGraph{T}(0, fadjlist)
@@ -55,10 +58,10 @@ function FactorGraph{T, V, F}(nv::Int=100, nf::Int=100) where {T <: Integer, V <
5558
return FactorGraph{T, V, F}(g, labels, variables, factors)
5659
end
5760

58-
# fg = FactorGraph{Int, AbstractNodeType, AbstractNodeType}()
61+
# fg = FactorGraph{Int, AbstractVariableType, AbstractFactorType}()
5962

60-
FactorGraph() = FactorGraph{Int, AbstractNodeType, AbstractNodeType}()
61-
FactorGraph{V,F}() where {V <: AbstractNodeType, F <: AbstractNodeType} = FactorGraph{Int, V, F}()
63+
FactorGraph() = FactorGraph{Int, AbstractVariableType, AbstractFactorType}()
64+
FactorGraph{V,F}() where {V <: AbstractVariableType, F <: AbstractFactorType} = FactorGraph{Int, V, F}()
6265

6366

6467
function show(io::IO, g::FactorGraph)

src/LightDFG/LightDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module LightDFGs
33
using LightGraphs
44
using DocStringExtensions
55

6-
import ...DistributedFactorGraphs: AbstractDFG, DFGNode, AbstractParams, NoSolverParams, DFGVariable, DFGFactor
6+
import ...DistributedFactorGraphs: AbstractDFG, DFGNode, AbstractDFGVariable, AbstractDFGFactor, AbstractDFGSummary, AbstractParams, NoSolverParams, DFGVariable, DFGFactor
77

8-
# import DFG functions to exstend
8+
# import DFG functions to extend
99
import ...DistributedFactorGraphs: setSolverParams,
1010
getInnerGraph,
1111
getFactor,

0 commit comments

Comments
 (0)