Skip to content

Commit 3200541

Browse files
authored
Merge pull request #779 from JuliaRobotics/21Q2/enh/printvar2
is/set Marginalized, printVar, bump v0.14.5
2 parents 572b94f + b530213 commit 3200541

File tree

5 files changed

+83
-35
lines changed

5 files changed

+83
-35
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
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.14.4"
3+
version = "0.14.5"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/DataBlobs/services/AbstractDataEntries.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ buildSourceString(dfg::AbstractDFG, label::Symbol) =
2929
Get data entry
3030
"""
3131
function getDataEntry(var::AbstractDFGVariable, key::Symbol)
32-
!hasDataEntry(var, key) && error("Data entry $(key) does not exist in variable")
32+
!hasDataEntry(var, key) && error("Data entry $(key) does not exist in variable $(getLabel(var))")
3333
return var.dataDict[key]
3434
end
3535

@@ -42,7 +42,7 @@ end
4242
Add Data Entry to a DFG variable
4343
"""
4444
function addDataEntry!(var::AbstractDFGVariable, bde::AbstractDataEntry)
45-
haskey(var.dataDict, bde.label) && error("Data entry $(bde.label) already exists in variable")
45+
haskey(var.dataDict, bde.label) && error("Data entry $(bde.label) already exists in variable $(getLabel(var))")
4646
var.dataDict[bde.label] = bde
4747
return bde
4848
end
@@ -66,7 +66,7 @@ DevNote
6666
- DF, unclear if `update` verb is applicable in this case, see #404
6767
"""
6868
function updateDataEntry!(var::AbstractDFGVariable, bde::AbstractDataEntry)
69-
!haskey(var.dataDict, bde.label) && (@warn "$(bde.label) does not exist in variable, adding")
69+
!haskey(var.dataDict, bde.label) && (@warn "$(bde.label) does not exist in variable $(getLabel(var)), adding")
7070
var.dataDict[bde.label] = bde
7171
return bde
7272
end

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export VariableNodeData, PackedVariableNodeData
180180

181181
export packVariableNodeData, unpackVariableNodeData
182182

183-
export getSolvedCount, isSolved, setSolvedCount!, isInitialized
183+
export getSolvedCount, isSolved, setSolvedCount!, isInitialized, isMarginalized, setMarginalized!
184184

185185
export getNeighborhood, getNeighbors, _getDuplicatedEmptyDFG
186186
export findFactorsBetweenNaive

src/services/CustomPrinting.jl

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,68 @@ function printVariable( io::IO, vert::DFGVariable;
1616
if short
1717
# opmemt = (getVariableType(vert) |> typeof ).name
1818
vari = getVariableType(vert) |> typeof
19-
printstyled(ioc, typeof(vert).name, "{",vari.name,"...}","\n", bold=true)
19+
printstyled(ioc, typeof(vert).name.name, "{",bold=true)
20+
printstyled(ioc, vari.name.name, bold=true, color=:blue)
21+
printstyled(ioc,"...}", bold=true)
22+
println(ioc, "")
2023
# printstyled(ioc, summary(vert),"\n", bold=true)
2124

22-
vnd = getSolverData(vert)
23-
println(ioc, " timestamp: ", vert.timestamp)
24-
println(ioc, " label: ", vert.label)
25-
println(ioc, " solvable: ", getSolvable(vert))
26-
println(ioc, " initilized: ", isInitialized(vert))
27-
println(ioc, " tags: ", getTags(vert))
2825
try
29-
print(ioc, " manifold: ")
26+
print(ioc, " manifold: ")
3027
show(ioc, getManifold(vert))
3128
println(ioc, "")
3229
catch e
3330
end
31+
vnd = getSolverData(vert, :default)
32+
println(ioc, " timestamp: ", vert.timestamp)
33+
println(ioc, " nstime: ", vert.nstime)
34+
print(ioc, " label: ")
35+
printstyled(ioc, vert.label, bold=true)
36+
println(ioc)
37+
println(ioc, " solvable: ", getSolvable(vert))
38+
println(ioc, " tags: ", getTags(vert))
3439
solk = listSolveKeys(vert) |> collect
3540
lsolk = length(solk)
3641
smsk = (rand(1:lsolk,100) |> unique)[1:minimum([4,lsolk])]
37-
println(ioc, " Nr solveKeys=$(lsolk): ", solk[smsk], 4<lsolk ? "..." : "")
38-
printstyled(ioc, " :default <-- VariableNodeData", "\n", bold=true)
39-
println(ioc, " size marginal samples: ", size(vnd.val))
40-
println(ioc, " kde bandwidths: ", round.((vnd.bw)[:,1], digits=4))
42+
# list the marginalization status
43+
ismarg = solk .|> x->isMarginalized(vert, x)
44+
isinit = solk .|> x->isInitialized(vert, x)
45+
printstyled(ioc, " # VND solveKeys= ($(lsolk))", bold=true)
46+
println(ioc, "")
47+
printstyled(ioc, " # initialized: ", bold=true)
48+
println(ioc, "(true=", sum(isinit), ",false=", length(isinit) - sum(isinit), ")" )
49+
printstyled(ioc, " # marginalized: ", bold=true)
50+
println(ioc, "(true=", sum(ismarg), ",false=", length(ismarg) - sum(ismarg), ")" )
51+
52+
println(ioc, " :default <-- VariableNodeData")
53+
println(ioc, " initilized: ", isInitialized(vert, :default))
54+
println(ioc, " marginalized: ", isMarginalized(vert, :default))
55+
println(ioc, " size bel. samples: ", size(vnd.val))
56+
println(ioc, " kde bandwidths: ", round.((vnd.bw)[:,1], digits=4))
57+
printstyled(ioc, " VNDs: ",bold=true)
58+
println(ioc, solk[smsk], 4<lsolk ? "..." : "")
59+
printstyled(ioc, " # PPE solveKeys= ($(length(getPPEDict(vert))))", bold=true)
60+
println(ioc, "")
4161
if haskey(getPPEDict(vert), :default)
42-
printstyled(ioc, " :default ", bold=true)
43-
println(ioc, "<-- PPE.suggested: ", round.(ppe.suggested,digits=4) )
62+
print(ioc, " :default ")
63+
println(ioc, "<-- .suggested: ", round.(getPPE(vert, :default).suggested,digits=4) )
4464
end
45-
maxkeys = 3
65+
maxkeys = 4
4666
for (key, ppe) in getPPEDict(vert)
67+
key == :default && continue # skip as default is done separately
4768
maxkeys -= 1
4869
maxkeys == 0 && break
49-
printstyled(ioc, " :$key ", bold=true)
50-
println(ioc, "<-- PPE.suggested: ", round.(ppe.suggested,digits=4) )
70+
print(ioc, " :$key ")
71+
println(ioc, "<-- .suggested: ", round.(ppe.suggested,digits=4) )
5172
end
52-
printstyled(ioc, " TYPE: ", bold=true, color=:blue)
73+
printstyled(ioc, " VariableType: ", color=:blue, bold=true)
5374
println(ioc, vari)
5475
# println(ioc, "kde max: $(round.(getKDEMax(getKDE(vnd)),digits=4))")
5576
# println(ioc, "kde max: $(round.(getKDEMax(getKDE(vnd)),digits=4))")
5677
else
5778

58-
printstyled(ioc, summary(vert),"\n", bold=true, color=:blue)
79+
printstyled(ioc, summary(vert), bold=true, color=:blue)
80+
println(ioc, "")
5981

6082
:solver in skipfields && push!(skipfields, :solverDataDict)
6183
:ppe in skipfields && push!(skipfields, :ppeDict)
@@ -65,7 +87,8 @@ function printVariable( io::IO, vert::DFGVariable;
6587
nf = nfields(vert)
6688

6789
for f in fields
68-
printstyled(ioc, f,":\n", color=:blue)
90+
printstyled(ioc, f,":", color=:blue)
91+
println(ioc, "")
6992
show(ioc, getproperty(vert, f))
7093
println(ioc)
7194
end
@@ -85,20 +108,22 @@ function printFactor( io::IO, vert::DFGFactor;
85108
opmemt = (getSolverData(vert).fnc |> typeof).name
86109
fct = getFactorType(vert)
87110
fctt = fct |> typeof
88-
printstyled(ioc, typeof(vert).name, "{",opmemt,"{",fctt.name,"...}}","\n", bold=true)
89-
println(ioc, " timestamp: ", vert.timestamp)
90-
println(ioc, " nstime: ",vert.nstime)
91-
println(ioc, " label: ", vert.label)
92-
println(ioc, " solvable: ", vert.solvable)
111+
printstyled(ioc, typeof(vert).name.name, "{",opmemt,"{",fctt.name.name,"...}}","\n", bold=true)
112+
println(ioc, " timestamp: ", vert.timestamp)
113+
println(ioc, " nstime: ", vert.nstime)
114+
print(ioc, " label: ")
115+
printstyled(ioc, vert.label, bold=true)
116+
println(ioc)
117+
println(ioc, " solvable: ", vert.solvable)
93118
println(ioc, " VariableOrder: ", vert._variableOrderSymbols)
94-
println(ioc, " multihypo: ", getSolverData(vert).multihypo) # FIXME #477
95-
println(ioc, " nullhypo: ", getSolverData(vert).nullhypo)
96-
println(ioc, " tags: ", vert.tags)
97-
printstyled(ioc, " TYPE: ", bold=true, color=:blue)
119+
println(ioc, " multihypo: ", getSolverData(vert).multihypo) # FIXME #477
120+
println(ioc, " nullhypo: ", getSolverData(vert).nullhypo)
121+
println(ioc, " tags: ", vert.tags)
122+
printstyled(ioc, " FactorType: ", bold=true, color=:blue)
98123
println(ioc, fctt)
99124
# show(ioc, fctt)
100125
for f in setdiff(fieldnames(fctt), skipfields)
101-
printstyled(ioc, f,":\n", color=:blue)
126+
printstyled(ioc, f,":\n", color=:magenta)
102127
show(ioc, getproperty(fct, f))
103128
println(ioc)
104129
end

src/services/DFGVariable.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,29 @@ function isInitialized(dfg::AbstractDFG, label::Symbol, key::Symbol=:default)
190190
end
191191

192192

193+
"""
194+
$SIGNATURES
195+
196+
Return `::Bool` on whether this variable has been marginalized.
197+
198+
Notes:
199+
- VariableNodeData default `solveKey=:default`
200+
"""
201+
isMarginalized(vert::DFGVariable, solveKey::Symbol=:default) = getSolverData(vert, solveKey).ismargin
202+
isMarginalized(dfg::AbstractDFG, sym::Symbol, solveKey::Symbol=:default) = isMarginalized(DFG.getVariable(dfg, sym), solveKey)
203+
204+
"""
205+
$SIGNATURES
206+
207+
Mark a variable as marginalized `true` or `false`.
208+
"""
209+
function setMarginalized!(vnd::VariableNodeData, val::Bool)
210+
vnd.ismargin = val
211+
end
212+
setMarginalized!(vari::DFGVariable, val::Bool, solveKey::Symbol=:default) = setMarginalized!(getSolverData(vari, solveKey), val)
213+
setMarginalized!(dfg::AbstractDFG, sym::Symbol, val::Bool, solveKey::Symbol=:default) = setMarginalized!(getVariable(dfg, sym), val, solveKey)
214+
215+
193216
##==============================================================================
194217
## Variables
195218
##==============================================================================

0 commit comments

Comments
 (0)