Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function getfnctype(data::GenericFunctionNodeData)
return data.fnc.usrfnc!
end
function getfnctype(fact::DFGFactor; solveKey::Symbol=:default)
data = getData(fact) # TODO , solveKey=solveKey)
data = solverData(fact) # TODO , solveKey=solveKey)
return getfnctype(data)
end
function getfnctype(dfg::T, lbl::Symbol; solveKey::Symbol=:default) where T <: AbstractDFG
Expand All @@ -145,7 +145,7 @@ Notes
- Replaces older `getfnctype`.
"""
getFactorType(data::GenericFunctionNodeData) = data.fnc.usrfnc!
getFactorType(fct::DFGFactor) = getFactorType(getData(fct))
getFactorType(fct::DFGFactor) = getFactorType(solverData(fct))
function getFactorType(dfg::G, lbl::Symbol) where G <: AbstractDFG
getFactorType(getFactor(dfg, lbl))
end
Expand Down Expand Up @@ -190,7 +190,7 @@ function getSofttype(vnd::VariableNodeData)
return vnd.softtype
end
function getSofttype(v::DFGVariable; solveKey::Symbol=:default)
return getSofttype(getData(v, solveKey=solveKey))
return getSofttype(solverData(v, solveKey))
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export AbstractParams, NoSolverParams
export DFGNode, DFGVariable, DFGFactor
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable, ConvolutionObject
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
export label, timestamp, tags, estimates, estimate, data, solverData, getData, solverDataDict, setSolverData, internalId, smallData, bigData
export label, timestamp, tags, estimates, estimate, data, softtype, solverData, getData, solverDataDict, setSolverData, internalId, smallData, bigData
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary

# Services/AbstractDFG Exports
Expand Down
31 changes: 27 additions & 4 deletions src/entities/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,22 @@ mutable struct PackedVariableNodeData
x15::Bool ) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15)
end

struct VariableEstimate

abstract type AbstractVariableEstimate end
"""
$TYPEDEF

Data container to store Parameteric Point Estimate (PPE) from a variety of types.

Notes
- `ppeType` is something like `:max/:mean/:modefit` etc.
- `solveKey` is from super-solve concept, starting with `:default`,
- `estimate` is the actual numerical estimate value,
- Additional information such as how the data is represented (ie softtype) is stored alongside this data container in the `DFGVariableSummary` container.
"""
struct VariableEstimate <: AbstractVariableEstimate
solverKey::Symbol
type::Symbol
ppeType::Symbol
estimate::Vector{Float64}
lastUpdatedTimestamp::DateTime
VariableEstimate(solverKey::Symbol, type::Symbol, estimate::Vector{Float64}, lastUpdatedTimestamp::DateTime=now()) = new(solverKey, type, estimate, lastUpdatedTimestamp)
Expand All @@ -93,7 +106,7 @@ mutable struct DFGVariable <: AbstractDFGVariable
label::Symbol
timestamp::DateTime
tags::Vector{Symbol}
estimateDict::Dict{Symbol, Dict{Symbol, VariableEstimate}}
estimateDict::Dict{Symbol, Dict{Symbol, <: AbstractVariableEstimate}}
Copy link
Member Author

@dehann dehann Oct 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT

know we have been going back and forth on this -- but I'm not convinced about adding an abstract inheritance here unfortunately. Going to create more boiler plate at the top level for DFGVariable{T,P}. There are already 2 dictionaries here.

Will ask again why this is not simpler -- just make it a dictionary and be done?

estimateDict::Dict{Symbol, Dict{Symbol, Float64}}(
:default => Dict{Symbol, Vector{Float64}}(
  :max => [1;2;3],
  :mean => [3;2;1],
  :modefit1 => [2;2;2],
  :modefit1_weight => [4;],
  ...
  :lastupdated => [2019;10;13;22;20;00.000]
))

Better solution

Can use anonymous static types which avoids the boiler plate. See Option 2 here and further:
#148 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easier to link discussions from Issue, so repeated here #147 (comment)

solverDataDict::Dict{Symbol, VariableNodeData}
smallData::Dict{String, String}
bigData::Any
Expand All @@ -110,6 +123,14 @@ timestamp(v::DFGVariable) = v.timestamp
tags(v::DFGVariable) = v.tags
estimates(v::DFGVariable) = v.estimateDict
estimate(v::DFGVariable, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing

"""
$SIGNATURES

Retrieve the soft type name symbol for a DFGVariable or DFGVariableSummary. ie :Point2, Pose2, etc.
"""
softtype(v::DFGVariable)::Symbol = Symbol(typeof(getSofttype(v)))

"""
$SIGNATURES

Expand Down Expand Up @@ -145,12 +166,14 @@ mutable struct DFGVariableSummary <: AbstractDFGVariable
label::Symbol
timestamp::DateTime
tags::Vector{Symbol}
estimateDict::Dict{Symbol, Dict{Symbol, VariableEstimate}}
estimateDict::Dict{Symbol, Dict{Symbol, <:AbstractVariableEstimate}}
softtypename::Symbol
_internalId::Int64
end
label(v::DFGVariableSummary) = v.label
timestamp(v::DFGVariableSummary) = v.timestamp
tags(v::DFGVariableSummary) = v.tags
estimates(v::DFGVariableSummary) = v.estimateDict
estimate(v::DFGVariableSummary, key::Symbol=:default) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing
softtype(v::DFGVariableSummary)::Symbol = v.softtypename
internalId(v::DFGVariableSummary) = v._internalId
2 changes: 1 addition & 1 deletion src/services/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,5 @@ function ==(a::VariableNodeData,b::VariableNodeData, nt::Symbol=:var)
end

function convert(::Type{DFGVariableSummary}, v::DFGVariable)
return DFGVariableSummary(v.label, v.timestamp, deepcopy(v.tags), deepcopy(v.estimateDict), v._internalId)
return DFGVariableSummary(v.label, v.timestamp, deepcopy(v.tags), deepcopy(v.estimateDict), Symbol(typeof(getSofttype(v))), v._internalId)
end
10 changes: 7 additions & 3 deletions test/LightDFGSummaryTypes.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dfg = LightDFG{NoSolverParams, DFGVariableSummary, DFGFactorSummary}()

DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(label, DistributedFactorGraphs.now(), Symbol[], Dict{Symbol, VariableEstimate}(), 0)
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(label, DistributedFactorGraphs.now(), Symbol[], Dict{Symbol, VariableEstimate}(), :NA, 0)

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

Expand All @@ -13,6 +13,9 @@ append!(v1.tags, [:VARIABLE, :POSE])
append!(v2.tags, [:VARIABLE, :LANDMARK])
append!(f1.tags, [:FACTOR])

#Force softtypename
v1.softtypename = :Pose2

# @testset "Creating Graphs" begin
global dfg,v1,v2,f1
addVariable!(dfg, v1)
Expand Down Expand Up @@ -95,6 +98,7 @@ end
@test timestamp(v1) == v1.timestamp
@test estimates(v1) == v1.estimateDict
@test estimate(v1, :notfound) == nothing
@test softtype(v1) == :Pose2
# @test solverData(v1) === v1.solverDataDict[:default]
# @test getData(v1) === v1.solverDataDict[:default]
# @test solverData(v1, :default) === v1.solverDataDict[:default]
Expand Down Expand Up @@ -123,13 +127,13 @@ end
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
:max => VariableEstimate(:default, :max, [100.0]),
:mean => VariableEstimate(:default, :mean, [50.0]),
:ppe => VariableEstimate(:default, :ppe, [75.0]))
:modefit => VariableEstimate(:default, :modefit, [75.0]))
#update
updateVariableSolverData!(dfg, newvar)
#TODO maybe implement ==; @test newvar==var
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
varest1.type == varest2.type || return false
varest1.ppeType == varest2.ppeType || return false
varest1.solverKey == varest2.solverKey || return false
varest1.estimate == varest2.estimate || return false
return true
Expand Down
41 changes: 36 additions & 5 deletions test/interfaceTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ append!(v1.tags, [:VARIABLE, :POSE])
append!(v2.tags, [:VARIABLE, :LANDMARK])
append!(f1.tags, [:FACTOR])

#add types for softtypes
# Simple test for the soft type.
mutable struct TestSoftType <: InferenceVariable
a
b
TestSoftType(a, b) = new(a, b)
end
import Base.==
function ==(a::TestSoftType, b::TestSoftType)::Bool
a.a != b.a && return false
a.b != b.b && return false
return true
end
st1 = TestSoftType(1,2)
st2 = TestSoftType(1.0,2.0)
v1.solverDataDict[:default].softtype = deepcopy(st1)
v2.solverDataDict[:default].softtype = deepcopy(st2)

# @testset "Creating Graphs" begin
global dfg,v1,v2,f1
addVariable!(dfg, v1)
Expand Down Expand Up @@ -96,6 +114,10 @@ end
@test solverDataDict(v1) == v1.solverDataDict
@test internalId(v1) == v1._internalId

@test softtype(v1) == Symbol(typeof(st1))
@test softtype(v2) == Symbol(typeof(st2))
@test getSofttype(v1) == st1

@test label(f1) == f1.label
@test tags(f1) == f1.tags
@test solverData(f1) == f1.data
Expand All @@ -115,7 +137,7 @@ end
#TODO Should the next test work?
@test_broken !isInitialized(dfg, :f1)
@test_broken !isInitialized(f1)

end

@testset "Updating Nodes" begin
Expand All @@ -127,13 +149,13 @@ end
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
:max => VariableEstimate(:default, :max, [100.0]),
:mean => VariableEstimate(:default, :mean, [50.0]),
:ppe => VariableEstimate(:default, :ppe, [75.0]))
:modefit => VariableEstimate(:default, :modefit, [75.0]))
#update
updateVariableSolverData!(dfg, newvar)
#TODO maybe implement ==; @test newvar==var
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
varest1.type == varest2.type || return false
varest1.ppeType == varest2.ppeType || return false
varest1.solverKey == varest2.solverKey || return false
varest1.estimate == varest2.estimate || return false
return true
Expand All @@ -147,7 +169,7 @@ end
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
:max => VariableEstimate(:default, :max, [10.0]),
:mean => VariableEstimate(:default, :mean, [5.0]),
:ppe => VariableEstimate(:default, :ppe, [7.0]))
:modefit => VariableEstimate(:default, :modefit, [7.0]))

# Persist to the original variable.
updateVariableSolverData!(dfg, newvar)
Expand Down Expand Up @@ -210,6 +232,11 @@ verts = map(n -> DFGVariable(Symbol("x$n")), 1:numNodes)
#change ready and backendset for x7,x8 for improved tests on x7x8f1
verts[7].ready = 1
verts[8].backendset = 1

#force softytypes to first 2 vertices.
verts[1].solverDataDict[:default].softtype = deepcopy(st1)
verts[2].solverDataDict[:default].softtype = deepcopy(st2)

map(v -> addVariable!(dfg, v), verts)
map(n -> addFactor!(dfg, [verts[n], verts[n+1]], DFGFactor{Int, :Symbol}(Symbol("x$(n)x$(n+1)f1"))), 1:(numNodes-1))

Expand Down Expand Up @@ -283,7 +310,11 @@ end
# Check all fields are equal for all variables
for v in ls(summaryGraph)
for field in variableFields
@test getfield(getVariable(dfg, v), field) == getfield(getVariable(summaryGraph, v), field)
if field != :softtypename
@test getfield(getVariable(dfg, v), field) == getfield(getVariable(summaryGraph, v), field)
else
@test softtype(getVariable(dfg, v)) == softtype(getVariable(summaryGraph, v))
end
end
end
for f in lsf(summaryGraph)
Expand Down