Skip to content

Commit 04c9983

Browse files
committed
Merge branch '4Q19/poc/v0_6' into develop
2 parents 6f9006e + 2cd8c21 commit 04c9983

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2211
-1303
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.5.4"
3+
version = "0.6.0"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
@@ -21,7 +21,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2121
[compat]
2222
Colors = "0.8, 0.9, 0.10, 0.11"
2323
Distributions = "0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 0.24, 0.25, 1"
24-
DocStringExtensions = "0.7, 0.8, 0.9, 0.10, 1"
24+
DocStringExtensions = "0.8, 0.9, 0.10, 1"
2525
GraphPlot = "0.3.1, 0.4"
2626
Graphs = "0.10.2, 0.11, 1"
2727
JSON2 = "0.3.1"

docs/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[deps]
22
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
34

45
[compat]
56
Documenter = "0.23"

docs/make.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ makedocs(
77
sitename = "DistributedFactorGraphs.jl",
88
pages = Any[
99
"Home" => "index.md",
10+
"Data Structure" => "DataStructure.md",
1011
"Getting Started" => [
1112
"Introduction" => "getting_started.md",
12-
"Variables and Factors" => "variables_and_factors.md",
13-
"Common API Interface" => "ref_api.md",
14-
"Example" => "example.md"
13+
"Building Graphs" => "BuildingGraphs.md",
14+
"Using Graph Data" => "GraphData.md",
15+
"Drawing Graphs" => "DrawingGraphs.md",
16+
"Traversing and Querying" => "TraversingAndQuerying.md",
17+
"Common API Interface" => "ref_api.md"
1518
],
1619
"DistributedFactorGraph API's" => [
1720
"Graphs.jl" => "apis/graphs.md",
18-
"MetaGraph.jl" => "apis/graphs.md",
19-
"GraffSDK.jl" => "apis/graphs.md",
21+
"LightGraphs.jl" => "apis/graphs.md",
2022
"CloudGraphs.jl" => "apis/graphs.md",
2123
],
2224
"Reference" => "func_ref.md"

docs/src/BuildingGraphs.md

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Creating Graphs
2+
3+
In this section constructing DFG graphs will be discussed. To start, bring DistributedFactorGraphs into your workspace:
4+
5+
```julia
6+
using DistributedFactorGraphs
7+
```
8+
9+
We recommend using IncrementalInference (IIF) to populate DFG graphs. DFG provides the structure, but IIF overloads the provided `addVariable!` and `addFactor!` functions and creates solver-specific data that allows the graph to be solved. So although you can use DFG's `addVariable!` and `addFactor!`, it is better to start with IIF's functions so that the graph is solvable.
10+
11+
So for the following examples, IncrementalInference will be used to create the variables and factors. It should be added and imported to run the examples:
12+
13+
```julia
14+
using Pkg
15+
Pkg.add("IncrementalInference")
16+
using IncrementalInference
17+
```
18+
19+
## Initializing a Graph
20+
21+
DFG graphs can be built using various drivers (different representations of the underlying graph). At the moment DFG supports 3 drivers:
22+
- GraphsDFG: An in-memory graph that uses Graphs.jl for representing the graph.
23+
- LightDFG: An in-memory graph that uses LightGraphs.jl for representing the graph.
24+
- CloudGraphs: A database-driven graph that uses Neo4j.jl for interacting with the graph.
25+
26+
In general the first two are used for building and solving graphs, and CloudGraphs is used for persisting in-memory graphs into a database. In the long term we recommend using the LightDFG driver for in-memory operation because Graphs.jl is not actively supported and over time that driver may be deprecated.
27+
28+
To continue the example, run one of the following to create a DFG driver:
29+
30+
### Creating a GraphsDFG Graph
31+
32+
```julia
33+
# Create a DFG with default solver parameters using the Graphs.jl driver.
34+
dfg = GraphsDFG{SolverParams}(params=SolverParams())
35+
```
36+
37+
### Creating a LightDFG Graph
38+
39+
```julia
40+
# Create a DFG with default solver parameters using the LightGraphs.jl driver.
41+
dfg = LightDFG{SolverParams}(params=SolverParams())
42+
```
43+
44+
### Creating a CloudGraphsDFG Graph
45+
46+
```julia
47+
# Create a DFG with no solver parameters (just to demonstrate the difference) using the CloudGraphs driver, and connect it to a local Neo4j instance.
48+
dfg = CloudGraphsDFG{NoSolverParams}("localhost", 7474, "neo4j", "test",
49+
"testUser", "testRobot", "testSession",
50+
nothing,
51+
nothing,
52+
IncrementalInference.decodePackedType,
53+
IncrementalInference.rebuildFactorMetadata!)
54+
```
55+
56+
## Creating Variables and Factors
57+
58+
DFG and IIF rely on a CRUD (Create, Read, Update, and Delete) interface to allow users to create and edit graphs.
59+
60+
### Creating Variables with IIF
61+
62+
Variables are added using IncrementalInference's `addVariable!` function. To create the variable, you provide the following parameters:
63+
- The graph the variable is being added to
64+
- The variable's label (e.g. :x1 or :a)
65+
- The variable inference type (aka soft type), which is a subtype of InferenceVariable
66+
67+
**NOTE**: Once variables are initialized to a specific soft type, variable node data (solver data) is templated to that type.
68+
69+
In addition, the following optional parameters are provided:
70+
- Additional labels for the variable (in DFG these are referred to as tags)
71+
- A `solvable` flag to indicate whether the variable is ready to be added to a solution
72+
73+
Three variables are added:
74+
75+
```julia
76+
v1 = addVariable!(dfg, :x0, ContinuousScalar, labels = [:POSE], solvable=1)
77+
v2 = addVariable!(dfg, :x1, ContinuousScalar, labels = [:POSE], solvable=1)
78+
v3 = addVariable!(dfg, :l0, ContinuousScalar, labels = [:LANDMARK], solvable=1)
79+
```
80+
81+
### Creating Factors with IIF
82+
83+
Similarly to variables, it is recommended that users start with the IIF implementation of the `addFactor!` functions to create factors. To create the factors, you provide the following parameters:
84+
- The graph the variable is being added to
85+
- The labels for the variables that the factor is linking
86+
- The factor function (which is a subtype of )
87+
88+
Additionally, the solvable flag is also set to indicate that the factor can be used in solving graphs.
89+
90+
**NOTE:** Every graph requires a prior for it to be solvable, so it is a good practice to make sure one is added (generally by adding to the first variable in the graph).
91+
92+
Four factors are added: a prior, a linear conditional relationship with a normal distribution between x0 and x1, and a pair of linear conditional relationships between each pose and the landmark.
93+
94+
```julia
95+
prior = addFactor!(dfg, [:x0], Prior(Normal(0,1)))
96+
f1 = addFactor!(dfg, [:x0; :x1], LinearConditional(Normal(50.0,2.0)), solvable=1)
97+
f1 = addFactor!(dfg, [:l0; :x0], LinearConditional(Normal(40.0,5.0)), solvable=1)
98+
f1 = addFactor!(dfg, [:l0; :x1], LinearConditional(Normal(-10.0,5.0)), solvable=1)
99+
```
100+
101+
The produced factor graph is:
102+
103+
![imgs/initialgraph.jpg](imgs/initialgraph.jpg)
104+
105+
(For more information on producing plots of the graph, please refer to the
106+
[Drawing Graphs](DrawingGraphs.md) section).
107+
108+
## Listing Variables and Factors
109+
110+
Reading, updating, and deleting all use DFG functions (as opposed to adding,
111+
where using the IncrementalInference functions are recommended).
112+
113+
Each variable and factor is uniquely identified by its label. The list of
114+
variable and factor labels can be retrieved with the `ls`/`getVariableIds` and
115+
`lsf`/`getFactorIds` functions:
116+
117+
```@docs
118+
getVariableIds
119+
ls
120+
```
121+
122+
```@docs
123+
getFactorIds
124+
lsf
125+
```
126+
127+
To list all variables or factors (instead of just their labels), use the
128+
`getVariables` and `getFactors` functions:
129+
130+
```@docs
131+
getVariables
132+
getFactors
133+
```
134+
135+
**NOTE**: `getNeighbors` is also worth mentioning at this point as it is a simple way to
136+
find the bigraph relationships. More information on this and other ways to
137+
retrieve filtered lists of variables/factors (an area that's currently WIP in
138+
DFG) can be found in [Traversing and Querying](TraversingAndQuerying.md).
139+
140+
## Getting (Reading) Variables and Factors
141+
142+
Individual variables and factors can be retrieved from their labels using the following functions:
143+
144+
```@docs
145+
getVariable
146+
```
147+
148+
```@docs
149+
getFactor
150+
```
151+
152+
It is worth noting that `getVariable` allows a user to retrieve only a single
153+
solver entry, so that subsets of the solver data can be retrieved individually
154+
(say, in the case that there are many solutions). These can then be updated
155+
independently using the functions as discussed in the update section below.
156+
157+
## Updating Variables and Factors
158+
159+
Full variables and factors can be updated using the following functions:
160+
161+
```@docs
162+
updateVariable!
163+
```
164+
165+
```@docs
166+
updateFactor!
167+
```
168+
169+
**NOTE**: Skeleton and summary variables are read-only. To perform updates you
170+
should use the full factors and variables.
171+
172+
**NOTE**: `updateVariable`/`updateFactor` performs a complete update of the
173+
respective node. It's not a very efficient way to edit fine-grain detail. There
174+
are other methods to perform smaller in-place changes. This is discussed in
175+
more detail in [Data Structure](DataStructure.md).
176+
177+
## Deleting Variables and Factors
178+
179+
Variables and factors can be deleted using the following functions:
180+
181+
```@docs
182+
deleteVariable!
183+
```
184+
185+
```@docs
186+
deleteFactor!
187+
```

docs/src/DataStructure.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Data Structure
2+
3+
Variables and factors can potentially contain a lot of data, so DFG has
4+
different structures that are specialized for each use-case and level of detail.
5+
For example, if you want to retrieve just a simple summary of the structure,
6+
you can use the summary or skeleton structures to identify variables and factors
7+
of interest and then retrieve more detail on the subset.
8+
9+
Note that drivers support all of the structures.
10+
11+
The following section discusses the datastructures for each level. A quick
12+
summary of the types and the available properties (some of which are derived) is provided below.
13+
14+
Accessible properties for each of the variable structures:
15+
16+
| | Label | Timestamp | Tags | Estimates | Soft Type | Solvable | Solver Data | Small Data | Big Data Entries |
17+
|---------------------|-------|-----------|------|-----------|-----------|----------|-------------|------------|------------------|
18+
| SkeletonDFGVariable | X | | X | | | | | | |
19+
| DFGVariableSummary | X | X | X | X | Symbol | | | | X |
20+
| DFGVariable | X | X | X | X | X | X | X | X | X |
21+
22+
Accessible properties for each of the factor structures:
23+
24+
| | Label | Timestamp | Tags | Factor Type | Solvable | Solver Data |
25+
|-------------------|-------|-----------|------|-------------|----------|-------------|
26+
| SkeletonDFGFactor | X | | X | | | |
27+
| DFGFactorSummary | X | X | X | | | |
28+
| DFGFactor | X | X | X | X | X | X |
29+
30+
## DFG Skeleton
31+
32+
```@docs
33+
SkeletonDFGVariable
34+
SkeletonDFGFactor
35+
```
36+
37+
## DFG Summary
38+
39+
```@docs
40+
DFGVariableSummary
41+
DFGFactorSummary
42+
```
43+
44+
## Full DFG Node
45+
46+
```@docs
47+
DFGVariable
48+
DFGFactor
49+
```
50+
51+
## Additional Offloaded Data
52+
53+
Additional, larger data can be associated with variables using keyed big data entries.

docs/src/DrawingGraphs.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Drawing Graphs
2+
3+
Graphs can be visualized by using either `GraphPlot` or rendering to .dot files (which can be viewed using xdot).
4+
5+
## GraphPlot
6+
7+
`GraphPlot` plotting is available if `GraphPlot` is imported before DFG is imported. Install `GraphPlot` using the following command:
8+
9+
```julia
10+
using Pkg
11+
Pkg.install("GraphPlot")
12+
```
13+
14+
Then bring `GraphPlot` in before DFG:
15+
16+
```julia
17+
using GraphPlot
18+
using DistributedFactorGraphs
19+
```
20+
21+
Any factor graph can then be drawn by calling `dfgPlot`:
22+
23+
```julia
24+
# Construct graph using IIF
25+
using IncrementalInference
26+
# Create graph
27+
dfg = GraphsDFG{SolverParams}(params=SolverParams())
28+
v1 = addVariable!(dfg, :x0, ContinuousScalar, labels = [:POSE], solvable=1)
29+
v2 = addVariable!(dfg, :x1, ContinuousScalar, labels = [:POSE], solvable=1)
30+
v3 = addVariable!(dfg, :l0, ContinuousScalar, labels = [:LANDMARK], solvable=1)
31+
prior = addFactor!(dfg, [:x0], Prior(Normal(0,1)))
32+
f1 = addFactor!(dfg, [:x0; :x1], LinearConditional(Normal(50.0,2.0)), solvable=1)
33+
f1 = addFactor!(dfg, [:l0; :x0], LinearConditional(Normal(40.0,5.0)), solvable=1)
34+
f1 = addFactor!(dfg, [:l0; :x1], LinearConditional(Normal(-10.0,5.0)), solvable=1)
35+
36+
# Plot graph
37+
dfgplot(dfg)
38+
```
39+
40+
![imgs/initialgraph.jpg](imgs/initialgraph.jpg)
41+
42+
```@docs
43+
dfgplot
44+
```
45+
46+
### Rendering GraphPlot to PDF
47+
48+
The graph can be rendered to PDF or JPG in the following way:
49+
50+
```julia
51+
# Save to PDF
52+
using Compose
53+
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(dfg))
54+
```
55+
56+
### More Information
57+
58+
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
59+
60+
## Dot Files
61+
62+
Dot files are a standard format for visualizing graphs and applications such as
63+
xdot are available to view the files. Dot plotting does not require `GraphPlot`
64+
and can be drawn by either:
65+
- Calling `toDot` on any graph to produce a string of the graph
66+
- Calling `toDotFile` on any graph to save it directly to a dotfile
67+
68+
```julia
69+
using DistributedFactorGraphs
70+
# Construct graph using IIF
71+
using IncrementalInference
72+
# Create graph
73+
dfg = GraphsDFG{SolverParams}(params=SolverParams())
74+
v1 = addVariable!(dfg, :x0, ContinuousScalar, labels = [:POSE], solvable=1)
75+
v2 = addVariable!(dfg, :x1, ContinuousScalar, labels = [:POSE], solvable=1)
76+
v3 = addVariable!(dfg, :l0, ContinuousScalar, labels = [:LANDMARK], solvable=1)
77+
prior = addFactor!(dfg, [:x0], Prior(Normal(0,1)))
78+
f1 = addFactor!(dfg, [:x0; :x1], LinearConditional(Normal(50.0,2.0)), solvable=1)
79+
f1 = addFactor!(dfg, [:l0; :x0], LinearConditional(Normal(40.0,5.0)), solvable=1)
80+
f1 = addFactor!(dfg, [:l0; :x1], LinearConditional(Normal(-10.0,5.0)), solvable=1)
81+
# Save to dot file
82+
toDotFile(dfg, "/tmp/test.dot")
83+
# Open with xdot
84+
run(`xdot /tmp/test.dot`)
85+
```
86+
87+
```@docs
88+
toDot
89+
toDotFile
90+
```

0 commit comments

Comments
 (0)