diff --git a/IncrementalInference/ext/FluxModelsSerialization.jl b/IncrementalInference/ext/FluxModelsSerialization.jl index 6590114a..1d1957ac 100644 --- a/IncrementalInference/ext/FluxModelsSerialization.jl +++ b/IncrementalInference/ext/FluxModelsSerialization.jl @@ -99,7 +99,7 @@ function DFG.unpackDistribution(obj::PackedFluxModelsDistribution) end function Base.convert( - ::Union{Type{<:PackedSamplableBelief}, Type{<:PackedFluxModelsDistribution}}, + ::Union{Type{<:PackedBelief}, Type{<:PackedFluxModelsDistribution}}, obj::FluxModelsDistribution, ) # diff --git a/IncrementalInference/ext/IncrInfrDiffEqFactorExt.jl b/IncrementalInference/ext/IncrInfrDiffEqFactorExt.jl index 69d64a84..1e382dd7 100644 --- a/IncrementalInference/ext/IncrInfrDiffEqFactorExt.jl +++ b/IncrementalInference/ext/IncrInfrDiffEqFactorExt.jl @@ -67,7 +67,7 @@ _maketuplebeyond2args = (w1 = nothing, w2 = nothing, w3_...) -> (w3_...,) function DERelative( Xi::AbstractVector{<:DFGVariable}, - domain::Type{<:InferenceVariable}, + domain::Type{<:VariableStateType}, f::Function, data = () -> (); dt::Real = 1, @@ -94,7 +94,7 @@ end function DERelative( dfg::AbstractDFG, labels::AbstractVector{Symbol}, - domain::Type{<:InferenceVariable}, + domain::Type{<:VariableStateType}, f::Function, data = () -> (); Xi::AbstractArray{<:DFGVariable} = getVariable.(dfg, labels), diff --git a/IncrementalInference/ext/IncrInfrInteractiveUtilsExt.jl b/IncrementalInference/ext/IncrInfrInteractiveUtilsExt.jl index 88a4ee16..8e0b0153 100644 --- a/IncrementalInference/ext/IncrInfrInteractiveUtilsExt.jl +++ b/IncrementalInference/ext/IncrInfrInteractiveUtilsExt.jl @@ -4,7 +4,7 @@ module IncrInfrInteractiveUtilsExt using InteractiveUtils using DocStringExtensions -using IncrementalInference: InferenceVariable, AbstractPrior, AbstractRelativeMinimize, AbstractManifoldMinimize +using IncrementalInference: VariableStateType, AbstractPrior, RelativeObservation # using IncrementalInference: getCurrentWorkspaceFactors, getCurrentWorkspaceVariables, listTypeTree import IncrementalInference: getCurrentWorkspaceFactors, getCurrentWorkspaceVariables, listTypeTree @@ -19,8 +19,7 @@ Return all factors currently registered in the workspace. function getCurrentWorkspaceFactors() return [ InteractiveUtils.subtypes(AbstractPrior)..., - # InteractiveUtils.subtypes(AbstractRelativeRoots)..., - InteractiveUtils.subtypes(AbstractRelativeMinimize)..., + InteractiveUtils.subtypes(RelativeObservation)..., ] end @@ -30,7 +29,7 @@ end Return all variables currently registered in the workspace. """ function getCurrentWorkspaceVariables() - return InteractiveUtils.subtypes(InferenceVariable) + return InteractiveUtils.subtypes(VariableStateType) end function _listTypeTree(mytype, printlevel::Int) diff --git a/IncrementalInference/src/Deprecated.jl b/IncrementalInference/src/Deprecated.jl index c534523b..3836e27b 100644 --- a/IncrementalInference/src/Deprecated.jl +++ b/IncrementalInference/src/Deprecated.jl @@ -1,3 +1,41 @@ +## ================================================================================================ +## Deprecated in v0.36 +## ================================================================================================ + +#TODO this looks like dead code, should be removed +# TODO deprecate testshuffle +function _checkErrorCCWNumerics( + ccwl::Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}}, + testshuffle::Bool = false, +) where {N_, F <: AbstractRelativeMinimize, S, T} + return nothing +end +function _checkErrorCCWNumerics( + ccwl::Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}}, + testshuffle::Bool = false, +) where {N_, F <: AbstractManifoldMinimize, S, T} + return nothing +end + +#TODO this looks like dead code, should be removed +function _perturbIfNecessary( + fcttype::Union{F, <:Mixture{N_, F, S, T}}, + len::Int = 1, + perturbation::Real = 1e-10, +) where {N_, F <: AbstractRelativeMinimize, S, T} + return 0 +end + +function _perturbIfNecessary( + fcttype::Union{F, <:Mixture{N_, F, S, T}}, + len::Int = 1, + perturbation::Real = 1e-10, +) where {N_, F <: AbstractManifoldMinimize, S, T} + return 0 +end +# + + ## ================================================================================================ ## ================================================================================================ diff --git a/IncrementalInference/src/ExportAPI.jl b/IncrementalInference/src/ExportAPI.jl index 195ea81f..af66a9e3 100644 --- a/IncrementalInference/src/ExportAPI.jl +++ b/IncrementalInference/src/ExportAPI.jl @@ -72,10 +72,10 @@ export CSMHistory, # general types for softtyping of variable nodes BeliefArray, - InferenceVariable, + VariableStateType, ContinuousScalar, SamplableBelief, - PackedSamplableBelief, + PackedBelief, Prior, PackedPrior, MsgPrior, diff --git a/IncrementalInference/src/Factors/EuclidDistance.jl b/IncrementalInference/src/Factors/EuclidDistance.jl index e712c9e7..84ee1d01 100644 --- a/IncrementalInference/src/Factors/EuclidDistance.jl +++ b/IncrementalInference/src/Factors/EuclidDistance.jl @@ -6,7 +6,7 @@ $(TYPEDEF) Default linear offset between two scalar variables. """ -struct EuclidDistance{T <: SamplableBelief} <: AbstractManifoldMinimize # AbstractRelativeMinimize +struct EuclidDistance{T <: SamplableBelief} <: RelativeObservation Z::T end @@ -29,13 +29,13 @@ Serialization type for `EuclidDistance` binary factor. """ Base.@kwdef mutable struct PackedEuclidDistance <: AbstractPackedFactor _type::String - Z::PackedSamplableBelief + Z::PackedBelief end function convert(::Type{PackedEuclidDistance}, d::EuclidDistance) return PackedEuclidDistance( - "/application/JuliaLang/PackedSamplableBelief", - convert(PackedSamplableBelief, d.Z), + "/application/JuliaLang/PackedBelief", + convert(PackedBelief, d.Z), ) end diff --git a/IncrementalInference/src/Factors/GenericFunctions.jl b/IncrementalInference/src/Factors/GenericFunctions.jl index 30ea1513..43cd324e 100644 --- a/IncrementalInference/src/Factors/GenericFunctions.jl +++ b/IncrementalInference/src/Factors/GenericFunctions.jl @@ -72,7 +72,7 @@ export ManifoldFactor struct ManifoldFactor{ M <: AbstractManifold, T <: SamplableBelief -} <: AbstractManifoldMinimize +} <: RelativeObservation M::M Z::T end @@ -106,7 +106,7 @@ end # Adjoints defined in ApproxManifoldProducts -struct AdFactor{F <: AbstractManifoldMinimize} <: AbstractManifoldMinimize +struct AdFactor{F <: RelativeObservation} <: RelativeObservation factor::F end @@ -229,7 +229,7 @@ end Base.@kwdef mutable struct PackedManifoldPrior <: AbstractPackedFactor varType::String p::Vector{Float64} #NOTE This is a fixed point from where the measurement `Z` likely stored as a coordinate - Z::PackedSamplableBelief + Z::PackedBelief end function convert( @@ -243,7 +243,7 @@ function convert( c = AMP.makeCoordsFromPoint(obj.M, obj.p) # TODO convert all distributions to JSON - Zst = convert(PackedSamplableBelief, obj.Z) # String + Zst = convert(PackedBelief, obj.Z) # String return PackedManifoldPrior(varT, c, Zst) end @@ -254,7 +254,7 @@ function convert( ) # - # piggy back on serialization of InferenceVariable rather than try serialize anything Manifolds.jl + # piggy back on serialization of VariableStateType rather than try serialize anything Manifolds.jl M = DFG.getTypeFromSerializationModule(obj.varType) |> getManifold # TODO this is too excessive diff --git a/IncrementalInference/src/Factors/GenericMarginal.jl b/IncrementalInference/src/Factors/GenericMarginal.jl index 2bdf8300..4655b219 100644 --- a/IncrementalInference/src/Factors/GenericMarginal.jl +++ b/IncrementalInference/src/Factors/GenericMarginal.jl @@ -3,7 +3,7 @@ """ $(TYPEDEF) """ -mutable struct GenericMarginal <: AbstractManifoldMinimize # AbstractRelativeRoots +mutable struct GenericMarginal <: RelativeObservation # AbstractRelativeRoots Zij::Array{Float64, 1} Cov::Array{Float64, 1} W::Array{Float64, 1} diff --git a/IncrementalInference/src/Factors/LinearRelative.jl b/IncrementalInference/src/Factors/LinearRelative.jl index ca1a46f8..9cdff007 100644 --- a/IncrementalInference/src/Factors/LinearRelative.jl +++ b/IncrementalInference/src/Factors/LinearRelative.jl @@ -10,7 +10,7 @@ Default linear offset between two scalar variables. X_2 = X_1 + η_Z ``` """ -struct LinearRelative{N, T <: SamplableBelief} <: AbstractManifoldMinimize # AbstractRelativeMinimize +struct LinearRelative{N, T <: SamplableBelief} <: RelativeObservation Z::T end @@ -60,10 +60,10 @@ $(TYPEDEF) Serialization type for `LinearRelative` binary factor. """ Base.@kwdef mutable struct PackedLinearRelative <: AbstractPackedFactor - Z::PackedSamplableBelief + Z::PackedBelief end function convert(::Type{PackedLinearRelative}, d::LinearRelative) - return PackedLinearRelative(convert(PackedSamplableBelief, d.Z)) + return PackedLinearRelative(convert(PackedBelief, d.Z)) end function convert(::Type{LinearRelative}, d::PackedLinearRelative) return LinearRelative(convert(SamplableBelief, d.Z)) diff --git a/IncrementalInference/src/Factors/Mixture.jl b/IncrementalInference/src/Factors/Mixture.jl index ffc5d853..6081c9e6 100644 --- a/IncrementalInference/src/Factors/Mixture.jl +++ b/IncrementalInference/src/Factors/Mixture.jl @@ -168,14 +168,14 @@ Base.@kwdef mutable struct PackedMixture <: AbstractPackedFactor # store the packed type for later unpacking F_::String S::Vector{String} - components::Vector{PackedSamplableBelief} - diversity::PackedSamplableBelief + components::Vector{PackedBelief} + diversity::PackedBelief end function convert(::Type{<:PackedMixture}, obj::Mixture{N, F, S, T}) where {N, F, S, T} - allcomp = PackedSamplableBelief[] + allcomp = PackedBelief[] for val in obj.components - dtr_ = convert(PackedSamplableBelief, val) + dtr_ = convert(PackedBelief, val) # FIXME ON FIRE, likely to be difficult for non-standard "Samplable" types -- e.g. Flux models in RoME push!(allcomp, dtr_) end @@ -186,7 +186,7 @@ function convert(::Type{<:PackedMixture}, obj::Mixture{N, F, S, T}) where {N, F, pm = convert(DFG.convertPackedType(obj.mechanics), obj.mechanics) end sT = string(typeof(pm)) - dvst = convert(PackedSamplableBelief, obj.diversity) + dvst = convert(PackedBelief, obj.diversity) return PackedMixture(N, sT, string.(collect(S)), allcomp, dvst) end diff --git a/IncrementalInference/src/Factors/MsgPrior.jl b/IncrementalInference/src/Factors/MsgPrior.jl index 178acf73..8c75eae5 100644 --- a/IncrementalInference/src/Factors/MsgPrior.jl +++ b/IncrementalInference/src/Factors/MsgPrior.jl @@ -36,12 +36,12 @@ getManifold(mp::MsgPrior) = mp.M (cfo::CalcFactor{<:MsgPrior})(z, x1) = z .- x1 Base.@kwdef struct PackedMsgPrior <: AbstractPackedFactor - Z::PackedSamplableBelief + Z::PackedBelief infoPerCoord::Vector{Float64} end function convert(::Type{PackedMsgPrior}, d::MsgPrior) - return PackedMsgPrior(convert(PackedSamplableBelief, d.Z), d.infoPerCoord) + return PackedMsgPrior(convert(PackedBelief, d.Z), d.infoPerCoord) end function convert(::Type{<:MsgPrior}, d::PackedMsgPrior) return MsgPrior(convert(SamplableBelief, d.Z), d.infoPerCoord) diff --git a/IncrementalInference/src/Factors/PartialPrior.jl b/IncrementalInference/src/Factors/PartialPrior.jl index 543572ab..3f7105eb 100644 --- a/IncrementalInference/src/Factors/PartialPrior.jl +++ b/IncrementalInference/src/Factors/PartialPrior.jl @@ -9,7 +9,7 @@ Notes - Future TBD, consider using `AMP.getManifoldPartial` for more general abstraction. """ struct PartialPrior{T <: SamplableBelief, P <: Tuple} <: AbstractPrior - varType::Type{<:InferenceVariable} + varType::Type{<:VariableStateType} Z::T partial::P end @@ -29,13 +29,13 @@ Serialization type for `PartialPrior`. """ Base.@kwdef struct PackedPartialPrior <: AbstractPackedFactor varType::String - Z::PackedSamplableBelief + Z::PackedBelief partials::Vector{Int} end function convert(::Type{PackedPartialPrior}, d::PartialPrior) - return PackedPartialPrior(DFG.typeModuleName(d.varType), convert(PackedSamplableBelief, d.Z), [d.partial...;]) - # return PackedPartialPrior(convert(PackedSamplableBelief, d.Z), [d.partial...;]) + return PackedPartialPrior(DFG.typeModuleName(d.varType), convert(PackedBelief, d.Z), [d.partial...;]) + # return PackedPartialPrior(convert(PackedBelief, d.Z), [d.partial...;]) end function convert(::Type{PartialPrior}, d::PackedPartialPrior) return PartialPrior(DFG.getTypeFromSerializationModule(d.varType), convert(SamplableBelief, d.Z),(d.partials...,)) diff --git a/IncrementalInference/src/Factors/PartialPriorPassThrough.jl b/IncrementalInference/src/Factors/PartialPriorPassThrough.jl index 0a35b1fe..28583fdc 100644 --- a/IncrementalInference/src/Factors/PartialPriorPassThrough.jl +++ b/IncrementalInference/src/Factors/PartialPriorPassThrough.jl @@ -28,7 +28,7 @@ end Required internal density to store its type """ Base.@kwdef mutable struct PackedPartialPriorPassThrough <: AbstractPackedFactor - Z::PackedSamplableBelief # PackedHeatmapGridDensity + Z::PackedBelief # PackedHeatmapGridDensity partial::Vector{Int} end @@ -43,7 +43,7 @@ function convert( ) # - po = convert(PackedSamplableBelief, obj.Z) + po = convert(PackedBelief, obj.Z) return PackedPartialPriorPassThrough(po, Int[obj.partial...]) end diff --git a/IncrementalInference/src/NeedsResolution.jl b/IncrementalInference/src/NeedsResolution.jl index 853ab7b0..81ccae71 100644 --- a/IncrementalInference/src/NeedsResolution.jl +++ b/IncrementalInference/src/NeedsResolution.jl @@ -1,6 +1,6 @@ # FIXME move to DFG -getPointDefault(V::InferenceVariable) = getPointIdentity(V) +getPointDefault(V::VariableStateType) = getPointIdentity(V) function compare(c1::Channel, c2::Channel; skip::Vector{Symbol} = []) # diff --git a/IncrementalInference/src/Serialization/entities/AdditionalDensities.jl b/IncrementalInference/src/Serialization/entities/AdditionalDensities.jl index e85dd652..696c6249 100644 --- a/IncrementalInference/src/Serialization/entities/AdditionalDensities.jl +++ b/IncrementalInference/src/Serialization/entities/AdditionalDensities.jl @@ -1,5 +1,5 @@ -Base.@kwdef struct PackedManifoldKernelDensity <: PackedSamplableBelief +Base.@kwdef struct PackedManifoldKernelDensity <: PackedBelief _type::String = "IncrementalInference.PackedManifoldKernelDensity" varType::String pts::Vector{Vector{Float64}} @@ -8,7 +8,7 @@ Base.@kwdef struct PackedManifoldKernelDensity <: PackedSamplableBelief infoPerCoord::Vector{Float64} = zeros(length(pts[1])) end -Base.@kwdef struct PackedAliasingScalarSampler <: PackedSamplableBelief +Base.@kwdef struct PackedAliasingScalarSampler <: PackedBelief _type::String = "IncrementalInference.PackedAliasingScalarSampler" domain::Vector{Float64} = [0; 1.0] weights::Vector{Float64} = [0.5; 0.5] diff --git a/IncrementalInference/src/Serialization/entities/SerializingDistributions.jl b/IncrementalInference/src/Serialization/entities/SerializingDistributions.jl index 8fb163c3..c969e1b8 100644 --- a/IncrementalInference/src/Serialization/entities/SerializingDistributions.jl +++ b/IncrementalInference/src/Serialization/entities/SerializingDistributions.jl @@ -16,6 +16,6 @@ StringThemSamplableBeliefs = Union{ } ## TODO, TBD -# Base.@kwdef struct PackedDiscreteNonParametric <: PackedSamplableBelief +# Base.@kwdef struct PackedDiscreteNonParametric <: PackedBelief # _type::String = "IncrementalInference.PackedDiscreteNonParametric" # end diff --git a/IncrementalInference/src/Serialization/entities/SerializingOptionalDensities.jl b/IncrementalInference/src/Serialization/entities/SerializingOptionalDensities.jl index 71895045..8f309cd3 100644 --- a/IncrementalInference/src/Serialization/entities/SerializingOptionalDensities.jl +++ b/IncrementalInference/src/Serialization/entities/SerializingOptionalDensities.jl @@ -1,7 +1,7 @@ -Base.@kwdef mutable struct PackedHeatmapGridDensity <: PackedSamplableBelief +Base.@kwdef mutable struct PackedHeatmapGridDensity <: PackedBelief _type::String = "IncrementalInference.PackedHeatmapGridDensity" data::Vector{Vector{Float64}} domain::Tuple{Vector{Float64}, Vector{Float64}} @@ -12,7 +12,7 @@ Base.@kwdef mutable struct PackedHeatmapGridDensity <: PackedSamplableBelief end -Base.@kwdef mutable struct PackedLevelSetGridNormal <: PackedSamplableBelief +Base.@kwdef mutable struct PackedLevelSetGridNormal <: PackedBelief _type::String = "IncrementalInference.PackedLevelSetGridNormal" level::Float64 sigma::Float64 @@ -22,7 +22,7 @@ Base.@kwdef mutable struct PackedLevelSetGridNormal <: PackedSamplableBelief end -Base.@kwdef mutable struct PackedFluxModelsDistribution <: PackedSamplableBelief +Base.@kwdef mutable struct PackedFluxModelsDistribution <: PackedBelief # standardized _type field _type::String # shape of the input data diff --git a/IncrementalInference/src/Serialization/services/SerializationMKD.jl b/IncrementalInference/src/Serialization/services/SerializationMKD.jl index 2a492b39..5cc39074 100644 --- a/IncrementalInference/src/Serialization/services/SerializationMKD.jl +++ b/IncrementalInference/src/Serialization/services/SerializationMKD.jl @@ -14,7 +14,7 @@ getVariableType(M::TranslationGroup{TypeParameter{Tuple{N}}}) where {N} = Contin function Base.convert(::Type{<:SamplableBelief}, ::Type{<:PackedManifoldKernelDensity}) return ManifoldKernelDensity end -function Base.convert(::Type{<:PackedSamplableBelief}, ::Type{<:ManifoldKernelDensity}) +function Base.convert(::Type{<:PackedBelief}, ::Type{<:ManifoldKernelDensity}) return PackedManifoldKernelDensity end @@ -49,7 +49,7 @@ function DFG.packDistribution(mkd::ManifoldKernelDensity) return PackedManifoldKernelDensity( "IncrementalInference.PackedManifoldKernelDensity", - # piggy back on InferenceVariable serialization rather than try serialize anything Manifolds.jl + # piggy back on VariableStateType serialization rather than try serialize anything Manifolds.jl DFG.typeModuleName(getVariableType(mkd.manifold)), [AMP.makeCoordsFromPoint(mkd.manifold, pt) for pt in pts], getBW(mkd.belief)[:, 1], @@ -59,7 +59,7 @@ function DFG.packDistribution(mkd::ManifoldKernelDensity) end function DFG.unpackDistribution(dtr::PackedManifoldKernelDensity) - # find InferenceVariable type from string (anything Manifolds.jl?) + # find VariableStateType type from string (anything Manifolds.jl?) M = DFG.getTypeFromSerializationModule(dtr.varType) |> getManifold vecP = [AMP.makePointFromCoords(M, pt) for pt in dtr.pts] bw = length(dtr.bw) === 0 ? nothing : dtr.bw @@ -79,7 +79,7 @@ function Base.convert(::Type{String}, mkd::ManifoldKernelDensity) end # Use general dispatch -# Base.convert(::Type{<:PackedSamplableBelief}, mkd::ManifoldKernelDensity) = convert(String, mkd) +# Base.convert(::Type{<:PackedBelief}, mkd::ManifoldKernelDensity) = convert(String, mkd) # make module specific # good references: diff --git a/IncrementalInference/src/Serialization/services/SerializingDistributions.jl b/IncrementalInference/src/Serialization/services/SerializingDistributions.jl index d846f27f..51f65afb 100644 --- a/IncrementalInference/src/Serialization/services/SerializingDistributions.jl +++ b/IncrementalInference/src/Serialization/services/SerializingDistributions.jl @@ -33,10 +33,10 @@ end ## =========================================================================================== # NOTE part of new effort to overhaul the SamplableBelief serialization approach -function convert(::Type{<:PackedSamplableBelief}, obj::StringThemSamplableBeliefs) +function convert(::Type{<:PackedBelief}, obj::StringThemSamplableBeliefs) return packDistribution(obj) end -convert(::Type{<:SamplableBelief}, obj::PackedSamplableBelief) = unpackDistribution(obj) +convert(::Type{<:SamplableBelief}, obj::PackedBelief) = unpackDistribution(obj) ##=================================================================================== diff --git a/IncrementalInference/src/entities/BeliefTypes.jl b/IncrementalInference/src/entities/BeliefTypes.jl index 472f5f44..974d65ba 100644 --- a/IncrementalInference/src/entities/BeliefTypes.jl +++ b/IncrementalInference/src/entities/BeliefTypes.jl @@ -16,7 +16,7 @@ abstract type MessageType end struct NonparametricMessage <: MessageType end struct ParametricMessage <: MessageType end -using DistributedFactorGraphs: PackedSamplableBelief +using DistributedFactorGraphs: PackedBelief const SamplableBelief = Union{ <:Distributions.Distribution, @@ -42,7 +42,7 @@ Notes: - we want to send the joint, this is just to resolve consolidation #459 first. - Long term objective is single joint definition, likely called `LikelihoodMessage`. """ -struct TreeBelief{T <: InferenceVariable, P, M <: MB.AbstractManifold} +struct TreeBelief{T <: VariableStateType, P, M <: MB.AbstractManifold} val::Vector{P} bw::Array{Float64, 2} infoPerCoord::Vector{Float64} @@ -60,7 +60,7 @@ function TreeBelief( variableType::T = ContinuousScalar(), manifold = getManifold(variableType), solvableDim::Real = 0, -) where {T <: InferenceVariable} +) where {T <: VariableStateType} return TreeBelief(getPoints(p), getBW(p), ipc, variableType, manifold, solvableDim) end @@ -71,17 +71,17 @@ function TreeBelief( variableType::T = ContinuousScalar(), manifold::M = getManifold(variableType), solvableDim::Real = 0, -) where {P, T <: InferenceVariable, M <: MB.AbstractManifold} +) where {P, T <: VariableStateType, M <: MB.AbstractManifold} return TreeBelief{T, P, M}(val, bw, ipc, variableType, manifold, solvableDim) end -function TreeBelief(vnd::VariableNodeData{T}, solvDim::Real = 0) where {T} +function TreeBelief(vnd::VariableNodeData, solvDim::Real = 0) return TreeBelief( vnd.val, vnd.bw, vnd.infoPerCoord, getVariableType(vnd), - getManifold(T), + getManifold(vnd), solvDim, ) end diff --git a/IncrementalInference/src/entities/ExtFactors.jl b/IncrementalInference/src/entities/ExtFactors.jl index f6d916e4..046a12bb 100644 --- a/IncrementalInference/src/entities/ExtFactors.jl +++ b/IncrementalInference/src/entities/ExtFactors.jl @@ -19,7 +19,7 @@ DevNotes - FIXME Lots of consolidation and standardization to do, see RoME.jl #244 regarding Manifolds.jl. - TODO does not yet handle case where a factor spans across two timezones. """ -struct DERelative{T <: InferenceVariable, P, D} <: AbstractManifoldMinimize # AbstractRelativeMinimize +struct DERelative{T <: VariableStateType, P, D} <: RelativeObservation domain::Type{T} forwardProblem::P backwardProblem::P diff --git a/IncrementalInference/src/manifolds/services/ManifoldSampling.jl b/IncrementalInference/src/manifolds/services/ManifoldSampling.jl index c18de24e..29a6f9da 100644 --- a/IncrementalInference/src/manifolds/services/ManifoldSampling.jl +++ b/IncrementalInference/src/manifolds/services/ManifoldSampling.jl @@ -104,7 +104,7 @@ if more advanced sampling is required, the `getSample` function should be extend The default behavior for `getSample` is as follows: - The `SamplableBelief`` shall be in the field `Z` and that shall be enough to fully define the factor, i.e. `Z<:SamplableBelief` should be the only field. -- Sampling on `<:AbstractManifoldMinimize` factors defined on Group Manifolds: +- Sampling on `<:RelativeObservation` factors defined on Group Manifolds: - `getSample` normally returns a tangent vector at the identity element, however it should just match the custom factor definition. - Sampling on prior (`<:AbstractPrior`) factors : - `getSample` must return a point on the manifold that matches the point representation of the variable. diff --git a/IncrementalInference/src/services/ApproxConv.jl b/IncrementalInference/src/services/ApproxConv.jl index 3335c2a8..43e373f1 100644 --- a/IncrementalInference/src/services/ApproxConv.jl +++ b/IncrementalInference/src/services/ApproxConv.jl @@ -310,7 +310,7 @@ end # varTypes::Union{<:Tuple,<:AbstractVector{<:InstanceType{T}}}, # mkds::Union{<:Tuple,<:AbstractVector{<:InstanceType{T}}}; # tfg::AbstractDFG=_buildGraphByFactorAndTypes!(fct,) -# ) where {T <: InferenceVariable} +# ) where {T <: VariableStateType} # # # end diff --git a/IncrementalInference/src/services/CalcFactor.jl b/IncrementalInference/src/services/CalcFactor.jl index ea4e72d2..9a83d712 100644 --- a/IncrementalInference/src/services/CalcFactor.jl +++ b/IncrementalInference/src/services/CalcFactor.jl @@ -240,7 +240,7 @@ Notes - `maxlen` is length of all (possibly resampled) `ARR` contained particles. - `Xi` is order sensitive. - for initialization, solveFor = Nothing. -- `P = getPointType(<:InferenceVariable)` +- `P = getPointType(<:VariableStateType)` """ function _createVarValsAll( variables::AbstractVector{<:DFGVariable}; @@ -298,11 +298,7 @@ function _setCCWDecisionDimsConv!( xDim::Int ) where { N_, - F <: Union{ - AbstractManifoldMinimize, - AbstractRelativeMinimize, - AbstractPrior, - }, + F <: AbstractFactorObservation, S, T, } diff --git a/IncrementalInference/src/services/DeconvUtils.jl b/IncrementalInference/src/services/DeconvUtils.jl index 7ba97d52..07872d4a 100644 --- a/IncrementalInference/src/services/DeconvUtils.jl +++ b/IncrementalInference/src/services/DeconvUtils.jl @@ -30,7 +30,7 @@ Related [`approxDeconv`](@ref), [`_solveCCWNumeric!`](@ref) """ function approxDeconv( - fcto::DFGFactor, + fcto::DFGFactor{<:Union{<:AbstractRelativeMinimize, <:PriorObservation}}, ccw::CommonConvWrapper = _getCCW(fcto); N::Int = 100, measurement::AbstractVector = sampleFactor(ccw, N), @@ -94,7 +94,14 @@ function approxDeconv( if fcttype isa AbstractManifoldMinimize error("Fix dispatch on AbstractManifoldMinimize") else - ts = _solveLambdaNumeric(fcttype, hypoObj, res_, measurement[idx], islen1) + ts = _solveLambdaNumeric( + fcttype, + hypoObj, + res_, + measurement[idx], + nothing, # not used here + islen1 + ) measurement[idx] = ts end end @@ -106,8 +113,10 @@ function approxDeconv( end # TBD deprecate use of xDim +#FIXME add trait to get AbstractManifoldMinimize functionality. +# Or better consolidate wiht previous approxDeconv function. function approxDeconv( - fcto::DFGFactor{<:AbstractManifoldMinimize}, + fcto::DFGFactor{<:RelativeObservation}, ccw::CommonConvWrapper = _getCCW(fcto); N::Int = 100, measurement::AbstractVector = sampleFactor(ccw, N), diff --git a/IncrementalInference/src/services/DefaultNodeTypes.jl b/IncrementalInference/src/services/DefaultNodeTypes.jl index 3a428b87..0782c61b 100644 --- a/IncrementalInference/src/services/DefaultNodeTypes.jl +++ b/IncrementalInference/src/services/DefaultNodeTypes.jl @@ -11,19 +11,19 @@ Notes """ function selectFactorType( Modl::Module, - T1::Type{<:InferenceVariable}, - T2::Type{<:InferenceVariable}, + T1::Type{<:VariableStateType}, + T2::Type{<:VariableStateType}, ) return getfield(Modl, Symbol(T1, T2)) end -function selectFactorType(T1::Type{<:InferenceVariable}, T2::Type{<:InferenceVariable}) +function selectFactorType(T1::Type{<:VariableStateType}, T2::Type{<:VariableStateType}) return selectFactorType(typeof(T1()).name.module, T1, T2) end selectFactorType(T1::Type{<:Position1}, T2::Type{<:Position1}) = LinearRelative{1} function selectFactorType(T1::Type{<:Position{N}}, T2::Type{<:Position{N}}) where {N} return LinearRelative{N} end -function selectFactorType(T1::InferenceVariable, T2::InferenceVariable) +function selectFactorType(T1::VariableStateType, T2::VariableStateType) return selectFactorType(typeof(T1), typeof(T2)) end function selectFactorType(dfg::AbstractDFG, s1::Symbol, s2::Symbol) diff --git a/IncrementalInference/src/services/EvalFactor.jl b/IncrementalInference/src/services/EvalFactor.jl index 021d2c99..bf73e3a9 100644 --- a/IncrementalInference/src/services/EvalFactor.jl +++ b/IncrementalInference/src/services/EvalFactor.jl @@ -198,7 +198,7 @@ function computeAcrossHypothesis!( ccwl.partialDims, ) # no calculate new proposal belief on kernels `allelements[count]` - _checkErrorCCWNumerics(ccwl, testshuffle) + # _checkErrorCCWNumerics(ccwl, testshuffle) if skipSolve @warn("skipping numerical solve operation") else @@ -316,7 +316,7 @@ end Multiple dispatch wrapper for `<:AbstractRelative` types, to prepare and execute the general approximate convolution with user defined factor residual functions. This method also supports multihypothesis operations as one mechanism to introduce new modality into the proposal beliefs. -Planned changes will fold null hypothesis in as a standard feature and no longer appear as a separate `InferenceVariable`. +Planned changes will fold null hypothesis in as a standard feature and no longer appear as a separate `VariableStateType`. """ function evalPotentialSpecific( variables::AbstractVector{<:DFGVariable}, @@ -610,7 +610,7 @@ This temporary function can be run without passing a factor graph object, but wi Alternatively, the factor graph used for calculations can be passed in via the keyword `tfg`, hence the function name bang. Notes -- `TypeParams_args::Vector{Tuple{InferenceVariable, P}} +- `TypeParams_args::Vector{Tuple{VariableStateType, P}} - idea is please find best e.g. `b`, given `f(z,a,b,c)` either by roots or minimize (depends on definition of `f`) - `sfidx::Int` is the solve for index, assuming `getVariableOrder(fct)`. diff --git a/IncrementalInference/src/services/FGOSUtils.jl b/IncrementalInference/src/services/FGOSUtils.jl index 117c88ae..2a571433 100644 --- a/IncrementalInference/src/services/FGOSUtils.jl +++ b/IncrementalInference/src/services/FGOSUtils.jl @@ -118,7 +118,7 @@ getFactorDim(fg::AbstractDFG, fctid::Symbol) = getFactorDim(getFactor(fg, fctid) # extend convenience function (Matrix or Vector{P}) function manikde!( - variableType::Union{InstanceType{<:InferenceVariable}, InstanceType{<:AbstractFactor}}, + variableType::Union{InstanceType{<:VariableStateType}, InstanceType{<:AbstractFactor}}, pts::AbstractVector{P}; kw..., ) where {P <: Union{<:AbstractArray, <:Number, <: ArrayPartition}} @@ -130,7 +130,7 @@ function manikde!( end function manikde!( - varT::InstanceType{<:InferenceVariable}, + varT::InstanceType{<:VariableStateType}, pts::AbstractVector{<:Tuple}; kw..., ) @@ -212,8 +212,8 @@ function fifoFreeze!(dfg::AbstractDFG) return nothing end -DFG.getPoint(typ::InferenceVariable, w...; kw...) = getPoint(typeof(typ), w...; kw...) -function DFG.getCoordinates(typ::InferenceVariable, w...; kw...) +DFG.getPoint(typ::VariableStateType, w...; kw...) = getPoint(typeof(typ), w...; kw...) +function DFG.getCoordinates(typ::VariableStateType, w...; kw...) return getCoordinates(typeof(typ), w...; kw...) end @@ -238,7 +238,7 @@ Related """ function calcPPE( var::DFGVariable, - varType::InferenceVariable = getVariableType(var); + varType::VariableStateType = getVariableType(var); ppeType::Type{<:MeanMaxPPE} = MeanMaxPPE, solveKey::Symbol = :default, ppeKey::Symbol = solveKey diff --git a/IncrementalInference/src/services/FactorGradients.jl b/IncrementalInference/src/services/FactorGradients.jl index f8e67f54..e9b28bb3 100644 --- a/IncrementalInference/src/services/FactorGradients.jl +++ b/IncrementalInference/src/services/FactorGradients.jl @@ -39,14 +39,10 @@ end export getCoordSizes export checkGradientsToleranceMask, calcPerturbationFromVariable -# T_pt_args[:] = [(T1::Type{<:InferenceVariable}, point1); ...] +# T_pt_args[:] = [(T1::Type{<:VariableStateType}, point1); ...] # FORCED TO START AT EITHER :x1 function _prepFactorGradientLambdas( - fct::Union{ - <:AbstractRelativeMinimize, - # <:AbstractRelativeRoots, - <:AbstractManifoldMinimize, - }, + fct::RelativeObservation, measurement, varTypes::Tuple, pts::Tuple; @@ -135,10 +131,7 @@ function _prepFactorGradientLambdas( end function FactorGradientsCached!( - fct::Union{ - <:AbstractRelativeMinimize, - <:AbstractManifoldMinimize, - }, + fct::RelativeObservation, varTypes::Tuple, meas_single, pts::Tuple; diff --git a/IncrementalInference/src/services/FactorGraph.jl b/IncrementalInference/src/services/FactorGraph.jl index 069b107d..ad3fa7fe 100644 --- a/IncrementalInference/src/services/FactorGraph.jl +++ b/IncrementalInference/src/services/FactorGraph.jl @@ -380,7 +380,7 @@ end function DefaultNodeDataParametric( dodims::Int, dims::Int, - variableType::InferenceVariable; + variableType::VariableStateType; initialized::Bool = true, dontmargin::Bool = false, solveKey::Symbol = :parametric @@ -433,7 +433,7 @@ DevNotes """ function setDefaultNodeDataParametric!( v::DFGVariable, - variableType::InferenceVariable; + variableType::VariableStateType; solveKey::Symbol = :parametric, kwargs..., ) @@ -560,8 +560,8 @@ function setVariableRefence!( end # get instance from variableType -_variableType(varType::InferenceVariable) = varType -_variableType(varType::Type{<:InferenceVariable}) = varType() +_variableType(varType::VariableStateType) = varType +_variableType(varType::Type{<:VariableStateType}) = varType() ## ================================================================================================== ## DFG Overloads on addVariable! and addFactor! @@ -570,7 +570,7 @@ _variableType(varType::Type{<:InferenceVariable}) = varType() """ $(SIGNATURES) -Add a variable node `label::Symbol` to `dfg::AbstractDFG`, as `varType<:InferenceVariable`. +Add a variable node `label::Symbol` to `dfg::AbstractDFG`, as `varType<:VariableStateType`. Notes ----- @@ -597,7 +597,7 @@ function addVariable!( smalldata = Dict{Symbol, DFG.SmallDataTypes}(), checkduplicates::Bool = true, initsolvekeys::Vector{Symbol} = getSolverParams(dfg).algorithms, -) where {T <: InferenceVariable} +) where {T <: VariableStateType} # varType = _variableType(varTypeU) diff --git a/IncrementalInference/src/services/NumericalCalculations.jl b/IncrementalInference/src/services/NumericalCalculations.jl index d77c9d86..89c336c1 100644 --- a/IncrementalInference/src/services/NumericalCalculations.jl +++ b/IncrementalInference/src/services/NumericalCalculations.jl @@ -1,43 +1,10 @@ - -# TODO deprecate testshuffle -function _checkErrorCCWNumerics( - ccwl::Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}}, - testshuffle::Bool = false, -) where {N_, F <: AbstractRelativeMinimize, S, T} - return nothing -end -function _checkErrorCCWNumerics( - ccwl::Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}}, - testshuffle::Bool = false, -) where {N_, F <: AbstractManifoldMinimize, S, T} - return nothing -end - - -function _perturbIfNecessary( - fcttype::Union{F, <:Mixture{N_, F, S, T}}, - len::Int = 1, - perturbation::Real = 1e-10, -) where {N_, F <: AbstractRelativeMinimize, S, T} - return 0 -end - -function _perturbIfNecessary( - fcttype::Union{F, <:Mixture{N_, F, S, T}}, - len::Int = 1, - perturbation::Real = 1e-10, -) where {N_, F <: AbstractManifoldMinimize, S, T} - return 0 -end -# - - # internal use only, and selected out from approxDeconv functions function _solveLambdaNumeric( fcttype::AbstractPrior, objResX::Function, residual::AbstractVector{<:Real}, u0::AbstractVector{<:Real}, + variableType::Union{Nothing, VariableStateType}, islen1::Bool = false; perturb::Real = 1e-10, ) @@ -45,14 +12,74 @@ function _solveLambdaNumeric( end # +## ================================================================================================ +# TODO Maybe move to IIFTypes +#TODO we can propably expand this to better traits in the future, such as: +# Including the method (BFGS, NelderMead, etc) +# but for now we just lump it together as the 2 current options: +# OptimConvSolver and LieGroupOptimConvSolver +# implemented by overloading ConvSolver +""" + OptimConvSolver +A approxConv solver for relative observation not on Manifold using Optim.jl. +#TODO should be deprecated, but partials still use it. +""" +struct OptimConvSolver end +""" + LieGroupOptimConvSolver +An approxConv solver for relative observation on LieGroups using Optim.jl. +The current default for all relative observations. +""" +struct LieGroupOptimConvSolver end + +""" + ConvSolver(fcttype::RelativeObservation) + +Trait function to select the solver type used for approximate convolution (approxConv) of relative observation factors in non-parametric tree inference. + +By default, this returns `LieGroupOptimConvSolver`, which is suitable for relative observations on Lie groups. +You can overload this method for your custom factor type to specify a different solver. + +# Notes +- Overload this trait for your custom factor if you require a different solver for approxConv. +- The solver determines which optimization backend and method will be used during inference. +""" +ConvSolver(::Union{<:RelativeObservation, <:Mixture{N, <:RelativeObservation}}) where {N} = LieGroupOptimConvSolver() + +function ConvSolver(::Union{F, <:Mixture{N_, F, S, T}}) where {N_, F <: AbstractRelativeMinimize, S, T} + OptimConvSolver() +end + +## ================================================================================================ function _solveLambdaNumeric( - fcttype::Union{F, <:Mixture{N_, F, S, T}}, + fcttype::Union{<:RelativeObservation, <:Mixture{N, <:RelativeObservation}}, + objResX_hypoCalcFactor, + residual::AbstractVector{<:Real}, + u0, + variableType::Union{Nothing, VariableStateType}, + islen1::Bool = false, +) where {N} + _solveLambdaNumeric( + ConvSolver(fcttype), + fcttype, + objResX_hypoCalcFactor, + residual, + u0, + variableType, + islen1 + ) +end + +function _solveLambdaNumeric( + ::OptimConvSolver, + fcttype,#::RelativeObservation, objResX::Function, residual::AbstractVector{<:Real}, u0::AbstractVector{<:Real}, + variableType, #unused islen1::Bool = false, -) where {N_, F <: AbstractRelativeMinimize, S, T} +) # retries::Int=3 ) # # wrt #467 allow residual to be standardize for Roots and Minimize and Parametric cases. @@ -88,13 +115,14 @@ function (hypoCalcFactor::CalcFactorNormSq)(::Type{ManoptCalcConv}, M::AbstractM end function _solveLambdaNumeric( - fcttype::Union{F, <:Mixture{N_, F, S, T}}, + ::LieGroupOptimConvSolver, + fcttype,#::RelativeObservation, hypoCalcFactor, residual::AbstractVector{<:Real}, - u0,#::AbstractVector{<:Real}, - variableType::InferenceVariable, + u0, + variableType::VariableStateType, islen1::Bool = false, -) where {N_, F <: AbstractManifoldMinimize, S, T} +) # M = getManifold(variableType) # the variable is a manifold point, we are working on the tangent plane in optim for now. @@ -151,11 +179,11 @@ end # TODO test / dev for n-ary factor deconv # TODO Consolidate with _solveLambdaNumeric, see #1374 function _solveLambdaNumericMeas( - fcttype::Union{F, <:Mixture{N_, F, S, T}}, + fcttype::RelativeObservation, hypoCalcFactor, X0,#::AbstractVector{<:Real}, islen1::Bool = false, -) where {N_, F <: AbstractManifoldMinimize, S, T} +) # M = getManifold(fcttype) ϵ = getPointIdentity(M) @@ -283,7 +311,7 @@ function _solveCCWNumeric!( ccwl::Union{<:CommonConvWrapper{F}, <:CommonConvWrapper{<:Mixture{N_, F, S, T}}}, _slack = nothing; perturb::Real = 1e-10, -) where {N_, F <: AbstractRelative, S, T} +) where {N_, F <: AbstractRelativeMinimize, S, T} # # @@ -340,7 +368,8 @@ function _solveCCWNumeric!( getFactorType(ccwl), _hypoObj, ccwl.res, - X, + X, + nothing, #not used here islen1 ) @@ -414,7 +443,7 @@ function _solveCCWNumeric!( ccwl::Union{<:CommonConvWrapper{F}, <:CommonConvWrapper{<:Mixture{N_, F, S, T}}}, _slack = nothing; perturb::Real = 1e-10, -) where {N_, F <: AbstractManifoldMinimize, S, T} +) where {N_, F <: RelativeObservation, S, T} # # # FIXME, move this check higher and out of smpid loop # _checkErrorCCWNumerics(ccwl, testshuffle) diff --git a/IncrementalInference/src/services/SolverUtilities.jl b/IncrementalInference/src/services/SolverUtilities.jl index 6e1fbcd5..1e1522b0 100644 --- a/IncrementalInference/src/services/SolverUtilities.jl +++ b/IncrementalInference/src/services/SolverUtilities.jl @@ -25,7 +25,7 @@ end function mmd( p1::AbstractVector{P1}, p2::AbstractVector{P2}, - varType::Union{InstanceType{<:InferenceVariable}, InstanceType{<:AbstractFactor}}, + varType::Union{InstanceType{<:VariableStateType}, InstanceType{<:AbstractFactor}}, threads::Bool = true; bw::AbstractVector{<:Real} = SA[0.001;], ) where {P1 <: AbstractVector, P2 <: AbstractVector} @@ -37,7 +37,7 @@ end function mmd( p1::ManifoldKernelDensity, p2::ManifoldKernelDensity, - nodeType::Union{InstanceType{<:InferenceVariable}, InstanceType{<:AbstractFactor}}, + nodeType::Union{InstanceType{<:VariableStateType}, InstanceType{<:AbstractFactor}}, threads::Bool = true; bw::AbstractVector{<:Real} = SA[0.001;], asPartial::Bool = true @@ -238,9 +238,9 @@ function _checkVariableByReference( fg::AbstractDFG, srcLabel::Symbol, destRegex::Regex, - destType::Type{<:InferenceVariable}, + destType::Type{<:VariableStateType}, factor::AbstractRelative; - srcType::Type{<:InferenceVariable} = getVariableType(fg, srcLabel) |> typeof, + srcType::Type{<:VariableStateType} = getVariableType(fg, srcLabel) |> typeof, doRef::Bool = true, refKey::Symbol = :simulated, prior = if !doRef @@ -299,9 +299,9 @@ function _checkVariableByReference( fg::AbstractDFG, srcLabel::Symbol, destRegex::Regex, - destType::Type{<:InferenceVariable}, + destType::Type{<:VariableStateType}, factor::AbstractPrior; - srcType::Type{<:InferenceVariable} = getVariableType(fg, srcLabel) |> typeof, + srcType::Type{<:VariableStateType} = getVariableType(fg, srcLabel) |> typeof, doRef::Bool = true, refKey::Symbol = :simulated, prior = typeof(factor)(MvNormal(getMeasurementParametric(factor)...)), diff --git a/IncrementalInference/src/services/VariableStatistics.jl b/IncrementalInference/src/services/VariableStatistics.jl index 2990df62..0bbd117c 100644 --- a/IncrementalInference/src/services/VariableStatistics.jl +++ b/IncrementalInference/src/services/VariableStatistics.jl @@ -1,16 +1,16 @@ -function Statistics.mean(vartype::InferenceVariable, args...; kwargs...) +function Statistics.mean(vartype::VariableStateType, args...; kwargs...) return mean(getManifold(vartype), args...; kwargs...) end -function Statistics.std(vartype::InferenceVariable, args...; kwargs...) +function Statistics.std(vartype::VariableStateType, args...; kwargs...) return std(getManifold(vartype), args...; kwargs...) end -function Statistics.var(vartype::InferenceVariable, args...; kwargs...) +function Statistics.var(vartype::VariableStateType, args...; kwargs...) return var(getManifold(vartype), args...; kwargs...) end function Statistics.cov( - vartype::InferenceVariable, + vartype::VariableStateType, ptsArr::AbstractVector; basis::Manifolds.AbstractBasis = Manifolds.DefaultOrthogonalBasis(), kwargs..., @@ -19,7 +19,7 @@ function Statistics.cov( end #TODO check performance and FIXME on makemutalbe might not be needed any more -function calcStdBasicSpread(vartype::InferenceVariable, ptsArr::AbstractVector) # {P}) where {P} +function calcStdBasicSpread(vartype::VariableStateType, ptsArr::AbstractVector) # {P}) where {P} # _makemutable(s) = s # _makemutable(s::StaticArray{Tuple{S},T,N}) where {S,T,N} = MArray{Tuple{S},T,N,S}(s) # _makemutable(s::SMatrix{N,N,T,D}) where {N,T,D} = MMatrix{N,N,T,D}(s) diff --git a/IncrementalInference/test/basicGraphsOperations.jl b/IncrementalInference/test/basicGraphsOperations.jl index de8fef49..4d24feb7 100644 --- a/IncrementalInference/test/basicGraphsOperations.jl +++ b/IncrementalInference/test/basicGraphsOperations.jl @@ -50,7 +50,7 @@ end @testset "test InteractiveUtilsExt" begin ## -IIF.listTypeTree(AbstractManifoldMinimize) +IIF.listTypeTree(RelativeObservation) IIF.getCurrentWorkspaceFactors() IIF.getCurrentWorkspaceVariables() diff --git a/IncrementalInference/test/testCSMMonitor.jl b/IncrementalInference/test/testCSMMonitor.jl index f768b140..bcd25c19 100644 --- a/IncrementalInference/test/testCSMMonitor.jl +++ b/IncrementalInference/test/testCSMMonitor.jl @@ -2,7 +2,7 @@ using IncrementalInference using Test ## a new factor that is broken -struct BrokenFactor{T<: SamplableBelief} <: AbstractManifoldMinimize +struct BrokenFactor{T<: SamplableBelief} <: RelativeObservation Z::T end diff --git a/IncrementalInference/test/testCalcFactorHypos.jl b/IncrementalInference/test/testCalcFactorHypos.jl index 94590664..88717a55 100644 --- a/IncrementalInference/test/testCalcFactorHypos.jl +++ b/IncrementalInference/test/testCalcFactorHypos.jl @@ -8,7 +8,7 @@ import IncrementalInference: getSample, getManifold ## -struct MyFactor{T <: SamplableBelief} <: IIF.AbstractManifoldMinimize +struct MyFactor{T <: SamplableBelief} <: IIF.RelativeObservation Z::T # specialSampler approach will be deprecated # specialSampler::Function diff --git a/IncrementalInference/test/testCommonConvWrapper.jl b/IncrementalInference/test/testCommonConvWrapper.jl index bc7bc486..d3f91301 100644 --- a/IncrementalInference/test/testCommonConvWrapper.jl +++ b/IncrementalInference/test/testCommonConvWrapper.jl @@ -72,7 +72,7 @@ end # abstract Nonparametric <: Function # This is what the internmediate user would be contributing -mutable struct Pose1Pose1Test{T} <: AbstractManifoldMinimize +mutable struct Pose1Pose1Test{T} <: RelativeObservation Dx::T end diff --git a/IncrementalInference/test/testDeadReckoningTether.jl b/IncrementalInference/test/testDeadReckoningTether.jl index 2be30a46..c6c3bf2f 100644 --- a/IncrementalInference/test/testDeadReckoningTether.jl +++ b/IncrementalInference/test/testDeadReckoningTether.jl @@ -6,7 +6,7 @@ using Test ## -mutable struct MutableLinearRelative{N, T <: SamplableBelief} <: AbstractManifoldMinimize +mutable struct MutableLinearRelative{N, T <: SamplableBelief} <: RelativeObservation Z::T # timestamp::DateTime end diff --git a/IncrementalInference/test/testFluxModelsDistribution.jl b/IncrementalInference/test/testFluxModelsDistribution.jl index 8b10eef9..d0902fe5 100644 --- a/IncrementalInference/test/testFluxModelsDistribution.jl +++ b/IncrementalInference/test/testFluxModelsDistribution.jl @@ -18,7 +18,7 @@ measd = rand(fxd, 2) @test length( measd ) == 2 # convert to packed type -fxp = convert(PackedSamplableBelief, fxd) # TODO, PackedSamplableBelief +fxp = convert(PackedBelief, fxd) # TODO, PackedBelief @test fxp isa IIF.PackedFluxModelsDistribution # convert back to hydrated object diff --git a/IncrementalInference/test/testHeatmapGridDensity.jl b/IncrementalInference/test/testHeatmapGridDensity.jl index a16202e1..067abd03 100644 --- a/IncrementalInference/test/testHeatmapGridDensity.jl +++ b/IncrementalInference/test/testHeatmapGridDensity.jl @@ -33,7 +33,7 @@ hgd = IIF.HeatmapGridDensity(img, (x,y), nothing, 0.07; N=1000) println("test packing converters") # check conversions to packed types -phgd = convert(PackedSamplableBelief, hgd) +phgd = convert(PackedBelief, hgd) hgd_ = convert(SamplableBelief, phgd) @test isapprox( hgd, hgd_ ) diff --git a/IncrementalInference/test/testPackedDistributions.jl b/IncrementalInference/test/testPackedDistributions.jl index 6ed4f79d..e0b2e1a5 100644 --- a/IncrementalInference/test/testPackedDistributions.jl +++ b/IncrementalInference/test/testPackedDistributions.jl @@ -13,7 +13,7 @@ ctg = Categorical(5) packed = packDistribution(ctg) -@test packed isa PackedSamplableBelief +@test packed isa PackedBelief @test packed isa IncrementalInference.PackedCategorical upck = unpackDistribution(packed) @@ -32,7 +32,7 @@ nor = Normal() packed = packDistribution(nor) -@test packed isa PackedSamplableBelief +@test packed isa PackedBelief @test packed isa PackedNormal upck = unpackDistribution(packed) @@ -50,7 +50,7 @@ end mv = MvNormal([0.0;1.0], [1 0.1; 0.1 1]) packed = packDistribution(mv) -@test packed isa PackedSamplableBelief +@test packed isa PackedBelief @test packed isa PackedFullNormal upck = unpackDistribution(packed) @@ -68,7 +68,7 @@ end mv = MvNormal([0.0; 1.0], [4.0; 4.0]) packed = packDistribution(mv) -@test packed isa PackedSamplableBelief +@test packed isa PackedBelief @test packed isa PackedDiagNormal upck = unpackDistribution(packed) @@ -85,7 +85,7 @@ end mv = MvNormal([1 0.1; 0.1 1]) packed = packDistribution(mv) -@test packed isa PackedSamplableBelief +@test packed isa PackedBelief @test packed isa PackedZeroMeanFullNormal upck = unpackDistribution(packed) @@ -103,7 +103,7 @@ end mv = MvNormal([4.0;4.0]) packed = packDistribution(mv) -@test packed isa PackedSamplableBelief +@test packed isa PackedBelief @test packed isa PackedZeroMeanDiagNormal upck = unpackDistribution(packed) @@ -123,7 +123,7 @@ end bss = AliasingScalarSampler([1.0;2.0], [0.6;0.4]) packed = packDistribution(bss) -@test packed isa PackedSamplableBelief +@test packed isa PackedBelief @test packed isa IncrementalInference.PackedAliasingScalarSampler upck = unpackDistribution(packed) @@ -148,7 +148,7 @@ pts = [randn(2) for _ in 1:50] mkd = manikde!(T, pts) packed = packDistribution(mkd) -@test packed isa PackedSamplableBelief +@test packed isa PackedBelief @test packed isa IncrementalInference.PackedManifoldKernelDensity upck = unpackDistribution(packed) @@ -167,7 +167,7 @@ end r = Rayleigh(1.1) r_ = packDistribution(r) -@test r_ isa PackedSamplableBelief +@test r_ isa PackedBelief @test r_ isa PackedRayleigh r__ = unpackDistribution(r_) diff --git a/IncrementalInference/test/testSpecialEuclidean2Mani.jl b/IncrementalInference/test/testSpecialEuclidean2Mani.jl index 5116eb18..bf1be868 100644 --- a/IncrementalInference/test/testSpecialEuclidean2Mani.jl +++ b/IncrementalInference/test/testSpecialEuclidean2Mani.jl @@ -135,7 +135,7 @@ end ## -struct ManifoldFactorSE2{T <: SamplableBelief} <: IIF.AbstractManifoldMinimize +struct ManifoldFactorSE2{T <: SamplableBelief} <: IIF.RelativeObservation Z::T end @@ -216,7 +216,7 @@ end -@testset "test deconv on <:AbstractManifoldMinimize" begin +@testset "test deconv on <:RelativeObservation" begin ## fg = initfg() @@ -264,7 +264,7 @@ end ## ## ====================================================================================== -struct ManiPose2Point2{T <: SamplableBelief} <: IIF.AbstractManifoldMinimize +struct ManiPose2Point2{T <: SamplableBelief} <: IIF.RelativeObservation Z::T partial::Vector{Int} end diff --git a/IncrementalInference/test/testSpecialSampler.jl b/IncrementalInference/test/testSpecialSampler.jl index 407088af..c631078f 100644 --- a/IncrementalInference/test/testSpecialSampler.jl +++ b/IncrementalInference/test/testSpecialSampler.jl @@ -16,7 +16,7 @@ end getManifold(::SpecialPrior) = TranslationGroup(1) getSample(s::CalcFactor{<:SpecialPrior}) = rand(s.factor.z,1) -struct SpecialLinearOffset{T <: SamplableBelief} <: AbstractManifoldMinimize +struct SpecialLinearOffset{T <: SamplableBelief} <: RelativeObservation z::T end getManifold(::SpecialLinearOffset) = TranslationGroup(1) diff --git a/IncrementalInference/test/testgraphpackingconverters.jl b/IncrementalInference/test/testgraphpackingconverters.jl index 018ed71a..07fa2237 100644 --- a/IncrementalInference/test/testgraphpackingconverters.jl +++ b/IncrementalInference/test/testgraphpackingconverters.jl @@ -13,7 +13,7 @@ using Test td = Uniform() -ptd = convert(String, td) # TODO, PackedSamplableBelief +ptd = convert(String, td) # TODO, PackedBelief utd = convert(SamplableBelief, td) @test td.a - utd.a |> abs < 1e-10 @@ -87,7 +87,7 @@ end mkd = manikde!(TranslationGroup(2), [randn(2) for _ in 1:100]) # convert up and down -st = convert(String, mkd) # TODO, PackedSamplableBelief +st = convert(String, mkd) # TODO, PackedBelief upk = convert(SamplableBelief, st) # and check the basics diff --git a/IncrementalInference/test/testmultihypothesisapi.jl b/IncrementalInference/test/testmultihypothesisapi.jl index 3ac403b7..75afc484 100644 --- a/IncrementalInference/test/testmultihypothesisapi.jl +++ b/IncrementalInference/test/testmultihypothesisapi.jl @@ -19,7 +19,7 @@ end getManifold(dp::DevelopPrior) = TranslationGroup(getDimension(dp.x)) getSample(cf::CalcFactor{<:DevelopPrior}) = rand(cf.factor.x, 1) -mutable struct DevelopLikelihood{T <: SamplableBelief} <: AbstractManifoldMinimize +mutable struct DevelopLikelihood{T <: SamplableBelief} <: RelativeObservation x::T end @@ -110,20 +110,20 @@ println("Packing converters") Base.@kwdef mutable struct PackedDevelopPrior <: AbstractPackedFactor - x::PackedSamplableBelief + x::PackedBelief end function convert(::Type{PackedDevelopPrior}, d::DevelopPrior) - PackedDevelopPrior(convert(PackedSamplableBelief, d.x)) + PackedDevelopPrior(convert(PackedBelief, d.x)) end function convert(::Type{DevelopPrior}, d::PackedDevelopPrior) DevelopPrior(convert(SamplableBelief, d.x)) end @kwdef mutable struct PackedDevelopLikelihood <: AbstractPackedFactor - x::PackedSamplableBelief + x::PackedBelief end function convert(::Type{PackedDevelopLikelihood}, d::DevelopLikelihood) - PackedDevelopLikelihood(convert(PackedSamplableBelief, d.x)) + PackedDevelopLikelihood(convert(PackedBelief, d.x)) end function convert(::Type{<:DevelopLikelihood}, d::PackedDevelopLikelihood) DevelopLikelihood(convert(SamplableBelief, d.x)) diff --git a/IncrementalInferenceTypes/src/factors/Circular.jl b/IncrementalInferenceTypes/src/factors/Circular.jl index 2d06f7d9..1a293c90 100644 --- a/IncrementalInferenceTypes/src/factors/Circular.jl +++ b/IncrementalInferenceTypes/src/factors/Circular.jl @@ -8,7 +8,7 @@ Related [`Sphere1`](@ref), [`PriorSphere1`](@ref), [`Polar`](@ref), [`ContinuousEuclid`](@ref) """ -DFG.@defFactorType CircularCircular AbstractManifoldMinimize Manifolds.RealCircleGroup() +DFG.@defObservationType CircularCircular RelativeObservation Manifolds.RealCircleGroup() """ @@ -26,5 +26,5 @@ Related [`Circular`](@ref), [`Prior`](@ref), [`PartialPrior`](@ref) """ -DFG.@defFactorType PriorCircular AbstractPrior Manifolds.RealCircleGroup() +DFG.@defObservationType PriorCircular AbstractPrior Manifolds.RealCircleGroup() diff --git a/IncrementalInferenceTypes/src/factors/DefaultPrior.jl b/IncrementalInferenceTypes/src/factors/DefaultPrior.jl index 623ce03e..b1c9ecab 100644 --- a/IncrementalInferenceTypes/src/factors/DefaultPrior.jl +++ b/IncrementalInferenceTypes/src/factors/DefaultPrior.jl @@ -15,7 +15,7 @@ $(TYPEDEF) Serialization type for Prior. """ Base.@kwdef mutable struct PackedPrior <: AbstractPackedFactor - Z::PackedSamplableBelief + Z::PackedBelief end function DFG.pack(d::Prior) diff --git a/IncrementalInferenceTypes/src/factors/LinearRelative.jl b/IncrementalInferenceTypes/src/factors/LinearRelative.jl index db37b13e..1d44bc94 100644 --- a/IncrementalInferenceTypes/src/factors/LinearRelative.jl +++ b/IncrementalInferenceTypes/src/factors/LinearRelative.jl @@ -8,7 +8,7 @@ Default linear offset between two scalar variables. X_2 = X_1 + η_Z ``` """ -struct LinearRelative{T} <: AbstractManifoldMinimize +struct LinearRelative{T} <: RelativeObservation Z::T end @@ -19,7 +19,7 @@ $(TYPEDEF) Serialization type for `LinearRelative` binary factor. """ Base.@kwdef mutable struct PackedLinearRelative <: AbstractPackedFactor - Z::PackedSamplableBelief + Z::PackedBelief end function DFG.pack(d::LinearRelative) diff --git a/IncrementalInferenceTypes/src/serialization/entities/SerializingDistributions.jl b/IncrementalInferenceTypes/src/serialization/entities/SerializingDistributions.jl index cc3316f9..9b237b74 100644 --- a/IncrementalInferenceTypes/src/serialization/entities/SerializingDistributions.jl +++ b/IncrementalInferenceTypes/src/serialization/entities/SerializingDistributions.jl @@ -1,45 +1,45 @@ -Base.@kwdef struct PackedCategorical <: PackedSamplableBelief +Base.@kwdef struct PackedCategorical <: PackedBelief _type::String = "IncrementalInferenceTypes.PackedCategorical" p::Vector{Float64} = [1.0;] end -Base.@kwdef mutable struct PackedUniform <: PackedSamplableBelief +Base.@kwdef mutable struct PackedUniform <: PackedBelief _type::String = "IncrementalInferenceTypes.PackedUniform" a::Float64 = 0.0 b::Float64 = 1.0 PackedSamplableTypeJSON::String = "IncrementalInferenceTypes.PackedUniform" end -Base.@kwdef struct PackedNormal <: PackedSamplableBelief +Base.@kwdef struct PackedNormal <: PackedBelief _type::String = "IncrementalInferenceTypes.PackedNormal" mu::Float64 = 0.0 sigma::Float64 = 1.0 end -Base.@kwdef struct PackedZeroMeanDiagNormal <: PackedSamplableBelief +Base.@kwdef struct PackedZeroMeanDiagNormal <: PackedBelief _type::String = "IncrementalInferenceTypes.PackedZeroMeanDiagNormal" diag::Vector{Float64} = ones(1) end -Base.@kwdef struct PackedZeroMeanFullNormal <: PackedSamplableBelief +Base.@kwdef struct PackedZeroMeanFullNormal <: PackedBelief _type::String = "IncrementalInferenceTypes.PackedZeroMeanFullNormal" cov::Vector{Float64} = ones(1) end -Base.@kwdef mutable struct PackedDiagNormal <: PackedSamplableBelief +Base.@kwdef mutable struct PackedDiagNormal <: PackedBelief _type::String = "IncrementalInferenceTypes.PackedDiagNormal" mu::Vector{Float64} = zeros(1) diag::Vector{Float64} = ones(1) end -Base.@kwdef struct PackedFullNormal <: PackedSamplableBelief +Base.@kwdef struct PackedFullNormal <: PackedBelief _type::String = "IncrementalInferenceTypes.PackedFullNormal" mu::Vector{Float64} = zeros(1) cov::Vector{Float64} = ones(1) end -Base.@kwdef struct PackedRayleigh <: PackedSamplableBelief +Base.@kwdef struct PackedRayleigh <: PackedBelief _type::String = "IncrementalInferenceTypes.PackedRayleigh" sigma::Float64 = 1.0 end diff --git a/IncrementalInferenceTypes/src/variables/DefaultVariableTypes.jl b/IncrementalInferenceTypes/src/variables/DefaultVariableTypes.jl index 7d9dad09..173ee7d4 100644 --- a/IncrementalInferenceTypes/src/variables/DefaultVariableTypes.jl +++ b/IncrementalInferenceTypes/src/variables/DefaultVariableTypes.jl @@ -8,7 +8,7 @@ const InstanceType{T} = Union{Type{<:T}, <:T} Continuous Euclidean variable of dimension `N` representing a Position in cartesian space. """ -struct Position{N} <: InferenceVariable end +struct Position{N} <: VariableStateType{N} end Position(N::Int) = Position{N}()