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
3 changes: 2 additions & 1 deletion src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariab
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
export label, timestamp, tags, estimates, estimate, data, softtype, solverData, getData, solverDataDict, setSolverData, internalId, smallData, bigData
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
export PointParametricEstimates

# Services/AbstractDFG Exports
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
export updateGraphSolverData!

# Solver (IIF) Exports
export VariableNodeData, PackedVariableNodeData, VariableEstimate
export VariableNodeData, PackedVariableNodeData
export GenericFunctionNodeData#, FunctionNodeData
export getSerializationModule, setSerializationModule!
export pack, unpack
Expand Down
26 changes: 9 additions & 17 deletions src/entities/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,16 @@ mutable struct PackedVariableNodeData
end


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
ppeType::Symbol
estimate::Vector{Float64}
"""
struct PointParametricEstimates
Copy link
Member

Choose a reason for hiding this comment

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

struct PointParametricEstimates <: AbstractPointParametric as originally suggested by @Affie.

or whatever the chosen name for AbstractPointParametric is in the end

Copy link
Member

Choose a reason for hiding this comment

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

from #148

<: AbstractVariableEstimate

# Put other fields here.
estimates::Dict{Symbol, Vector{Float64}}
lastUpdatedTimestamp::DateTime
VariableEstimate(solverKey::Symbol, type::Symbol, estimate::Vector{Float64}, lastUpdatedTimestamp::DateTime=now()) = new(solverKey, type, estimate, lastUpdatedTimestamp)
PointParametricEstimates(lastUpdatedTimestamp::DateTime=now()) = new(Dict{Symbol, Vector{Float64}}(), lastUpdatedTimestamp)
end

"""
Expand All @@ -106,15 +98,15 @@ mutable struct DFGVariable <: AbstractDFGVariable
label::Symbol
timestamp::DateTime
tags::Vector{Symbol}
estimateDict::Dict{Symbol, Dict{Symbol, <: AbstractVariableEstimate}}
estimateDict::Dict{Symbol, PointParametricEstimates}
Copy link
Member

Choose a reason for hiding this comment

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

estimateDict::Dict{Symbol, <: AbstractPointParametric}

or whatever the chosen name for AbstractPointParametric is in the end

Copy link
Member

Choose a reason for hiding this comment

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

from #148

<: AbstractVariableEstimate

solverDataDict::Dict{Symbol, VariableNodeData}
smallData::Dict{String, String}
bigData::Any
ready::Int
backendset::Int
_internalId::Int64
DFGVariable(label::Symbol, _internalId::Int64) = new(label, now(), Symbol[], Dict{Symbol, Dict{Symbol, VariableEstimate}}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, _internalId)
DFGVariable(label::Symbol) = new(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, 0)
DFGVariable(label::Symbol, _internalId::Int64) = new(label, now(), Symbol[], Dict{Symbol, PointParametricEstimates}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, _internalId)
DFGVariable(label::Symbol) = new(label, now(), Symbol[], Dict{Symbol, PointParametricEstimates}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), nothing, 0, 0, 0)
end

# Accessors
Expand Down Expand Up @@ -166,7 +158,7 @@ mutable struct DFGVariableSummary <: AbstractDFGVariable
label::Symbol
timestamp::DateTime
tags::Vector{Symbol}
estimateDict::Dict{Symbol, Dict{Symbol, <:AbstractVariableEstimate}}
estimateDict::Dict{Symbol, PointParametricEstimates}
softtypename::Symbol
_internalId::Int64
end
Expand Down
6 changes: 6 additions & 0 deletions src/services/DFGVariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ function ==(a::VariableNodeData,b::VariableNodeData, nt::Symbol=:var)
return DistributedFactorGraphs.compare(a,b)
end

function ==(a::PointParametricEstimates, b::PointParametricEstimates)::Bool
a.estimates != b.estimates && return false
a.lastUpdatedTimestamp != b.lastUpdatedTimestamp && return false
return true
end

function convert(::Type{DFGVariableSummary}, v::DFGVariable)
return DFGVariableSummary(v.label, v.timestamp, deepcopy(v.tags), deepcopy(v.estimateDict), Symbol(typeof(getSofttype(v))), v._internalId)
end
28 changes: 11 additions & 17 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}(), :NA, 0)
DistributedFactorGraphs.DFGVariableSummary(label::Symbol) = DFGVariableSummary(label, DistributedFactorGraphs.now(), Symbol[], Dict{Symbol, PointParametricEstimates}(), :NA, 0)

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

Expand Down Expand Up @@ -124,30 +124,24 @@ end
var = getVariable(dfg, :a)
#make a copy and simulate external changes
newvar = deepcopy(var)
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
:max => VariableEstimate(:default, :max, [100.0]),
:mean => VariableEstimate(:default, :mean, [50.0]),
:modefit => VariableEstimate(:default, :modefit, [75.0]))
ppe = PointParametricEstimates()
ppe.estimates[:max] = [100.0]
ppe.estimates[:mean] = [50.0]
ppe.estimates[:modefit] = [75.0]
estimates(newvar)[:default] = ppe
#update
updateVariableSolverData!(dfg, newvar)
#TODO maybe implement ==; @test newvar==var
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
varest1.ppeType == varest2.ppeType || return false
varest1.solverKey == varest2.solverKey || return false
varest1.estimate == varest2.estimate || return false
return true
end
#For now spot check
# @test solverDataDict(newvar) == solverDataDict(var)
@test estimates(newvar) == estimates(var)

# Delete :default and replace to see if new ones can be added
delete!(estimates(newvar), :default)
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
:max => VariableEstimate(:default, :max, [10.0]),
:mean => VariableEstimate(:default, :mean, [5.0]),
:ppe => VariableEstimate(:default, :ppe, [7.0]))
ppe = PointParametricEstimates()
ppe.estimates[:max] = [10.0]
ppe.estimates[:mean] = [5.0]
ppe.estimates[:modefit] = [7.0]
estimates(newvar)[:second] = ppe

# Persist to the original variable.
updateVariableSolverData!(dfg, newvar)
Expand Down
26 changes: 10 additions & 16 deletions test/interfaceTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,30 +146,24 @@ end
var = getVariable(dfg, :a)
#make a copy and simulate external changes
newvar = deepcopy(var)
estimates(newvar)[:default] = Dict{Symbol, VariableEstimate}(
:max => VariableEstimate(:default, :max, [100.0]),
:mean => VariableEstimate(:default, :mean, [50.0]),
:modefit => VariableEstimate(:default, :modefit, [75.0]))
ppe = PointParametricEstimates()
ppe.estimates[:max] = [100.0]
ppe.estimates[:mean] = [50.0]
ppe.estimates[:modefit] = [75.0]
estimates(newvar)[:default] = ppe
#update
updateVariableSolverData!(dfg, newvar)
#TODO maybe implement ==; @test newvar==var
Base.:(==)(varest1::VariableEstimate, varest2::VariableEstimate) = begin
varest1.lastUpdatedTimestamp == varest2.lastUpdatedTimestamp || return false
varest1.ppeType == varest2.ppeType || return false
varest1.solverKey == varest2.solverKey || return false
varest1.estimate == varest2.estimate || return false
return true
end
#For now spot check
@test solverDataDict(newvar) == solverDataDict(var)
@test estimates(newvar) == estimates(var)

# Delete :default and replace to see if new ones can be added
delete!(estimates(newvar), :default)
estimates(newvar)[:second] = Dict{Symbol, VariableEstimate}(
:max => VariableEstimate(:default, :max, [10.0]),
:mean => VariableEstimate(:default, :mean, [5.0]),
:modefit => VariableEstimate(:default, :modefit, [7.0]))
ppe = PointParametricEstimates()
ppe.estimates[:max] = [10.0]
ppe.estimates[:mean] = [5.0]
ppe.estimates[:modefit] = [7.0]
estimates(newvar)[:second] = ppe

# Persist to the original variable.
updateVariableSolverData!(dfg, newvar)
Expand Down