Skip to content

Commit 83274f2

Browse files
authored
Merge pull request #183 from JuliaRobotics/feature/147_PointParametricEst
Closes #147 PointParametricEst implementation
2 parents 3b03369 + f0b8a10 commit 83274f2

File tree

7 files changed

+42
-77
lines changed

7 files changed

+42
-77
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ function getVariable(dfg::CloudGraphsDFG, variableId::Int64)::DFGVariable
182182
# props["label"] = Symbol(variable.label)
183183
timestamp = DateTime(props["timestamp"])
184184
tags = JSON2.read(props["tags"], Vector{Symbol})
185-
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
185+
#TODO this will work for some time, but unpacking in an <: AbstractPointParametricEst would be lekker.
186+
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, MeanMaxPPE})
186187
smallData = nothing
187188
smallData = JSON2.read(props["smallData"], Dict{String, String})
188189

src/DistributedFactorGraphs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isF
3333
export mergeUpdateVariableSolverData!, mergeUpdateGraphSolverData!
3434

3535
# Solver (IIF) Exports
36-
export VariableNodeData, PackedVariableNodeData, VariableEstimate
36+
export VariableNodeData, PackedVariableNodeData
3737
export GenericFunctionNodeData#, FunctionNodeData
3838
export getSerializationModule, setSerializationModule!
3939
export pack, unpack
4040
# Resolve with above
4141
export packVariable, unpackVariable, packFactor, unpackFactor
4242

43+
#PPE exports
44+
export MeanMaxPPE
45+
4346
#Interfaces
4447
export getAdjacencyMatrixSparse
4548

src/entities/DFGVariable.jl

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,28 @@ mutable struct PackedVariableNodeData
6363
x15::Bool ) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15)
6464
end
6565

66-
67-
abstract type AbstractVariableEstimate end
66+
# AbstractPointParametricEst interface
67+
abstract type AbstractPointParametricEst end
6868
"""
6969
$TYPEDEF
7070
71-
Data container to store Parameteric Point Estimate (PPE) from a variety of types.
72-
73-
Notes
74-
- `ppeType` is something like `:max/:mean/:modefit` etc.
75-
- `solveKey` is from super-solve concept, starting with `:default`,
76-
- `estimate` is the actual numerical estimate value,
77-
- Additional information such as how the data is represented (ie softtype) is stored alongside this data container in the `DFGVariableSummary` container.
71+
Data container to store Parameteric Point Estimate (PPE) for mean and max.
7872
"""
79-
struct VariableEstimate <: AbstractVariableEstimate
80-
solverKey::Symbol
81-
ppeType::Symbol
82-
estimate::Vector{Float64}
83-
lastUpdatedTimestamp::DateTime
73+
struct MeanMaxPPE <: AbstractPointParametricEst
74+
solverKey::Symbol #repeated because of Sam's request
75+
max::Vector{Float64}
76+
mean::Vector{Float64}
77+
lastUpdatedTimestamp::DateTime
8478
end
85-
VariableEstimate(solverKey::Symbol, type::Symbol, estimate::Vector{Float64}) = VariableEstimate(solverKey, type, estimate, now())
79+
MeanMaxPPE(solverKey::Symbol,max::Vector{Float64},mean::Vector{Float64}) = MeanMaxPPE(solverKey, max, mean, now())
80+
81+
getMaxPPE(est::AbstractPointParametricEst) = est.max
82+
getMeanPPE(est::AbstractPointParametricEst) = est.mean
83+
getLastUpdatedTimestamp(est::AbstractPointParametricEst) = est.lastUpdatedTimestamp
84+
85+
86+
VariableEstimate(params...) = errror("VariableEstimate is depreciated, please use MeanMaxPPE")
87+
8688

8789
"""
8890
$(TYPEDEF)
@@ -93,7 +95,7 @@ mutable struct DFGVariable <: AbstractDFGVariable
9395
label::Symbol
9496
timestamp::DateTime
9597
tags::Vector{Symbol}
96-
estimateDict::Dict{Symbol, Dict{Symbol, <: AbstractVariableEstimate}}
98+
estimateDict::Dict{Symbol, <: AbstractPointParametricEst}
9799
solverDataDict::Dict{Symbol, VariableNodeData}
98100
smallData::Dict{String, String}
99101
bigData::Dict{Symbol, AbstractBigDataEntry}
@@ -107,10 +109,10 @@ end
107109
DFGVariable constructors.
108110
"""
109111
DFGVariable(label::Symbol, _internalId::Int64) =
110-
DFGVariable(label, now(), Symbol[], Dict{Symbol, Dict{Symbol, VariableEstimate}}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
112+
DFGVariable(label, now(), Symbol[], Dict{Symbol, MeanMaxPPE}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
111113

112114
DFGVariable(label::Symbol) =
113-
DFGVariable(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, 0)
115+
DFGVariable(label, now(), Symbol[], Dict{Symbol, MeanMaxPPE}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, 0)
114116

115117
# Accessors
116118
label(v::DFGVariable) = v.label
@@ -138,12 +140,7 @@ solverData(v::DFGVariable, key::Symbol=:default) = haskey(v.solverDataDict, key)
138140
Retrieve data structure stored in a variable.
139141
"""
140142
function getData(v::DFGVariable; solveKey::Symbol=:default)::VariableNodeData
141-
#FIXME but back in later, it just slows everything down
142-
if !(@isdefined getDataWarnOnce)
143-
@warn "getData is deprecated, please use solverData(), future warnings in getData is suppressed"
144-
global getDataWarnOnce = true
145-
end
146-
# @warn "getData is deprecated, please use solverData()"
143+
@warn "getData is deprecated, please use solverData()"
147144
return v.solverDataDict[solveKey]
148145
end
149146
"""
@@ -166,7 +163,7 @@ mutable struct DFGVariableSummary <: AbstractDFGVariable
166163
label::Symbol
167164
timestamp::DateTime
168165
tags::Vector{Symbol}
169-
estimateDict::Dict{Symbol, Dict{Symbol, <:AbstractVariableEstimate}}
166+
estimateDict::Dict{Symbol, <:AbstractPointParametricEst}
170167
softtypename::Symbol
171168
_internalId::Int64
172169
end

src/services/DFGVariable.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ function unpackVariable(dfg::G, packedProps::Dict{String, Any})::DFGVariable whe
1717
label = Symbol(packedProps["label"])
1818
timestamp = DateTime(packedProps["timestamp"])
1919
tags = JSON2.read(packedProps["tags"], Vector{Symbol})
20-
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, Dict{Symbol, VariableEstimate}})
20+
#TODO this will work for some time, but unpacking in an <: AbstractPointParametricEst would be lekker.
21+
estimateDict = JSON2.read(packedProps["estimateDict"], Dict{Symbol, MeanMaxPPE})
2122
smallData = nothing
2223
smallData = JSON2.read(packedProps["smallData"], Dict{String, String})
2324

@@ -112,15 +113,11 @@ function ==(a::VariableNodeData,b::VariableNodeData, nt::Symbol=:var)
112113
end
113114

114115
"""
115-
$(SIGNATURES)
116-
Equality check for VariableEstimate.
116+
==(x::T, y::T) where T <: AbstractPointParametricEst
117+
Equality check for AbstractPointParametricEst.
117118
"""
118-
function ==(a::VariableEstimate, b::VariableEstimate)::Bool
119-
a.solverKey != b.solverKey && @debug("solverKey are not equal")==nothing && return false
120-
a.ppeType != b.ppeType && @debug("ppeType is not equal")==nothing && return false
121-
a.estimate != b.estimate && @debug("estimate are not equal")==nothing && return false
122-
a.lastUpdatedTimestamp != b.lastUpdatedTimestamp && @debug("lastUpdatedTimestamp is not equal")==nothing && return false
123-
return true
119+
@generated function ==(x::T, y::T) where T <: AbstractPointParametricEst
120+
mapreduce(n -> :(x.$n == y.$n), (a,b)->:($a && $b), fieldnames(x))
124121
end
125122

126123
"""

test/LightDFGSummaryTypes.jl

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dfg = LightDFG{NoSolverParams, DFGVariableSummary, DFGFactorSummary}()
22

3-
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(label, DistributedFactorGraphs.now(), Symbol[], Dict{Symbol, VariableEstimate}(), :NA, 0)
3+
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(label, DistributedFactorGraphs.now(), Symbol[], Dict{Symbol, MeanMaxPPE}(), :NA, 0)
44

55
DistributedFactorGraphs.DFGFactorSummary(label::Symbol) = DFGFactorSummary(label, Symbol[], 0, Symbol[])
66

@@ -124,30 +124,16 @@ end
124124
var = getVariable(dfg, :a)
125125
#make a copy and simulate external changes
126126
newvar = deepcopy(var)
127-
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
128-
:max => VariableEstimate(:default, :max, [100.0]),
129-
:mean => VariableEstimate(:default, :mean, [50.0]),
130-
:modefit => VariableEstimate(:default, :modefit, [75.0]))
127+
estimates(newvar)[:default] = MeanMaxPPE(:default, [100.0], [50.0])
131128
#update
132129
mergeUpdateVariableSolverData!(dfg, newvar)
133-
#TODO maybe implement ==; @test newvar==var
134-
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
135-
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
136-
varest1.ppeType == varest2.ppeType || return false
137-
varest1.solverKey == varest2.solverKey || return false
138-
varest1.estimate == varest2.estimate || return false
139-
return true
140-
end
141130
#For now spot check
142131
# @test solverDataDict(newvar) == solverDataDict(var)
143132
@test estimates(newvar) == estimates(var)
144133

145134
# Delete :default and replace to see if new ones can be added
146135
delete!(estimates(newvar), :default)
147-
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
148-
:max => VariableEstimate(:default, :max, [10.0]),
149-
:mean => VariableEstimate(:default, :mean, [5.0]),
150-
:ppe => VariableEstimate(:default, :ppe, [7.0]))
136+
estimates(newvar)[:second] = MeanMaxPPE(:second, [10.0], [5.0])
151137

152138
# Persist to the original variable.
153139
mergeUpdateVariableSolverData!(dfg, newvar)

test/iifInterfaceTests.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,7 @@ end
234234
var = getVariable(dfg, :a)
235235
#make a copy and simulate external changes
236236
newvar = deepcopy(var)
237-
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
238-
:max => VariableEstimate(:default, :max, [100.0]),
239-
:mean => VariableEstimate(:default, :mean, [50.0]),
240-
:modefit => VariableEstimate(:default, :modefit, [75.0]))
237+
estimates(newvar)[:default] = MeanMaxPPE(:default, [100.0], [50.0])
241238
#update
242239
mergeUpdateVariableSolverData!(dfg, newvar)
243240

@@ -246,10 +243,7 @@ end
246243
@test estimates(newvar) == estimates(var)
247244

248245
# Add a new estimate.
249-
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
250-
:max => VariableEstimate(:default, :max, [10.0]),
251-
:mean => VariableEstimate(:default, :mean, [5.0]),
252-
:modefit => VariableEstimate(:default, :modefit, [7.0]))
246+
estimates(newvar)[:second] = MeanMaxPPE(:second, [10.0], [5.0])
253247

254248
# Confirm they're different
255249
@test estimates(newvar) != estimates(var)

test/interfaceTests.jl

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,30 +208,17 @@ end
208208
var = getVariable(dfg, :a)
209209
#make a copy and simulate external changes
210210
newvar = deepcopy(var)
211-
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
212-
:max => VariableEstimate(:default, :max, [100.0]),
213-
:mean => VariableEstimate(:default, :mean, [50.0]),
214-
:modefit => VariableEstimate(:default, :modefit, [75.0]))
211+
estimates(newvar)[:default] = MeanMaxPPE(:default, [100.0], [50.0])
215212
#update
216213
mergeUpdateVariableSolverData!(dfg, newvar)
217-
#TODO maybe implement ==; @test newvar==var
218-
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
219-
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
220-
varest1.ppeType == varest2.ppeType || return false
221-
varest1.solverKey == varest2.solverKey || return false
222-
varest1.estimate == varest2.estimate || return false
223-
return true
224-
end
214+
225215
#For now spot check
226216
@test solverDataDict(newvar) == solverDataDict(var)
227217
@test estimates(newvar) == estimates(var)
228218

229219
# Delete :default and replace to see if new ones can be added
230220
delete!(estimates(newvar), :default)
231-
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
232-
:max => VariableEstimate(:default, :max, [10.0]),
233-
:mean => VariableEstimate(:default, :mean, [5.0]),
234-
:modefit => VariableEstimate(:default, :modefit, [7.0]))
221+
estimates(newvar)[:second] = MeanMaxPPE(:second, [10.0], [5.0])
235222

236223
# Persist to the original variable.
237224
mergeUpdateVariableSolverData!(dfg, newvar)

0 commit comments

Comments
 (0)