From 0f7edd48090c93351435303865cfbc58ea8aefca Mon Sep 17 00:00:00 2001 From: dehann Date: Thu, 8 Jul 2021 15:26:19 -0400 Subject: [PATCH] replace #1291 , some code cleanup --- src/ApproxConv.jl | 22 ++++++--------------- src/FGOSUtils.jl | 12 ----------- src/FactorGraph.jl | 23 +++++++++++----------- src/IncrementalInference.jl | 2 +- src/{ => entities}/GraphConstraintTypes.jl | 0 5 files changed, 19 insertions(+), 40 deletions(-) rename src/{ => entities}/GraphConstraintTypes.jl (100%) diff --git a/src/ApproxConv.jl b/src/ApproxConv.jl index 40b5bc5f2..c5245e2ab 100644 --- a/src/ApproxConv.jl +++ b/src/ApproxConv.jl @@ -252,7 +252,7 @@ function calcVariableDistanceExpectedFractional(ccwl::CommonConvWrapper, end # Add entrypy on a point in `points` on manifold M, only on dimIdx if in p -function addEntropyOnManifoldHack!( M::ManifoldsBase.AbstractManifold, +function addEntropyOnManifold!( M::ManifoldsBase.AbstractManifold, points::Union{<:AbstractVector{<:Real},SubArray}, dimIdx::AbstractVector, spreadDist::Real, @@ -281,16 +281,6 @@ function addEntropyOnManifoldHack!( M::ManifoldsBase.AbstractManifold, end # - # manis = convert(Tuple, M) # LEGACY, TODO REMOVE - # # TODO deprecate - # maniAddOps, _, _, _ = buildHybridManifoldCallbacks(manis) - # # add 1σ "noise" level to max distance as control - # # 1:size(addEntr, 1) - # for dim in dimIdx, idx in 1:length(addEntr) - # if (p === :) || dim in p - # addEntr[idx][dim] = maniAddOps[dim](addEntr[idx][dim], spreadDist*(rand()-0.5)) - # end - # end nothing end @@ -333,7 +323,7 @@ function computeAcrossHypothesis!(ccwl::Union{<:CommonConvWrapper{F}, # consider duplicate convolution approximations for inflation off-zero # ultimately set by dfg.params.inflateCycles for iflc in 1:inflateCycles - addEntropyOnManifoldHack!(mani, addEntr, 1:getDimension(mani), spreadDist, cpt_.p) + addEntropyOnManifold!(mani, addEntr, 1:getDimension(mani), spreadDist, cpt_.p) # no calculate new proposal belief on kernels `allelements[count]` skipSolve ? @warn("skipping numerical solve operation") : approxConvOnElements!(ccwl, allelements[count]) end @@ -348,7 +338,7 @@ function computeAcrossHypothesis!(ccwl::Union{<:CommonConvWrapper{F}, addEntr = view(ccwl.params[sfidx], allelements[count]) # dynamic estimate with user requested speadNH of how much noise to inject (inflation or nullhypo) spreadDist = calcVariableDistanceExpectedFractional(ccwl, sfidx, certainidx, kappa=spreadNH) - addEntropyOnManifoldHack!(mani, addEntr, 1:getDimension(mani), spreadDist) + addEntropyOnManifold!(mani, addEntr, 1:getDimension(mani), spreadDist) elseif hypoidx == 0 # basically do nothing since the factor is not active for these allelements[count] @@ -358,7 +348,7 @@ function computeAcrossHypothesis!(ccwl::Union{<:CommonConvWrapper{F}, # dynamic estimate with user requested speadNH of how much noise to inject (inflation or nullhypo) spreadDist = calcVariableDistanceExpectedFractional(ccwl, sfidx, certainidx, kappa=spreadNH) # # make spread (1σ) equal to mean distance of other fractionals - addEntropyOnManifoldHack!(mani, addEntr, 1:getDimension(mani), spreadDist) + addEntropyOnManifold!(mani, addEntr, 1:getDimension(mani), spreadDist) else error("computeAcrossHypothesis -- not dealing with multi-hypothesis case correctly") end @@ -518,7 +508,7 @@ function evalPotentialSpecific( Xi::AbstractVector{<:DFGVariable}, addEntr[m] .= ccwl.measurement[1][m] end # ongoing part of RoME.jl #244 - addEntropyOnManifoldHack!(mani, addEntrNH, 1:getDimension(mani), spreadDist) + addEntropyOnManifold!(mani, addEntrNH, 1:getDimension(mani), spreadDist) else i = 0 for dimnum in fnc.partial @@ -529,7 +519,7 @@ function evalPotentialSpecific( Xi::AbstractVector{<:DFGVariable}, # @show size(addEntr), dimnum, nhmask addEntrNHp = view(view(addEntr, (1:length(ahmask))[ahmask]), dimnum) # ongoing part of RoME.jl #244 - addEntropyOnManifoldHack!(mani, addEntrNHp, dimnum:dimnum, spreadDist) + addEntropyOnManifold!(mani, addEntrNHp, dimnum:dimnum, spreadDist) end end return addEntr diff --git a/src/FGOSUtils.jl b/src/FGOSUtils.jl index 3fe965ebf..205509623 100644 --- a/src/FGOSUtils.jl +++ b/src/FGOSUtils.jl @@ -140,19 +140,7 @@ function manikde!(pts::AbstractVector{P}, return AMP.manikde!(M, pts) end -# manikde!( pts::AbstractVector{<:Real}, -# vartype::Type{<:ContinuousScalar}) = manikde!(reshape(pts,1,:), vartype) -# -# TEMPORARY legacy wrapper -# function manikde!(ptsArr::Vector{Vector{Float64}}, -# bw::Vector{Float64}, -# varType::Union{InstanceType{<:InferenceVariable}, InstanceType{<:AbstractFactor}} ) -# # -# arr = Matrix{Float64}(undef, length(ptsArr[1]), length(ptsArr)) -# @cast arr[i,j] = ptsArr[j][i] -# manikde!( arr, bw, varType ) -# end """ $SIGNATURES diff --git a/src/FactorGraph.jl b/src/FactorGraph.jl index c23e38946..dfd325008 100644 --- a/src/FactorGraph.jl +++ b/src/FactorGraph.jl @@ -594,20 +594,21 @@ Notes - Will not work in all situations, but good enough so far. - # TODO standardize via domain or manifold definition...?? """ -function calcZDim(cf::CalcFactor{T}) where {T <: FunctorInferenceType} +function calcZDim(cf::CalcFactor{T}) where {T <: AbstractFactor} # - # zdim = T != GenericMarginal ? size(getSample(usrfnc, 2)[1],1) : 0 - zdim = if T != GenericMarginal - # vnds = Xi # (x->getSolverData(x)).(Xi) - # NOTE try to make sure we get matrix back (not a vector) - smpls = sampleFactor(cf, 2)[1] - length(smpls[1]) - else - 0 - end - return zdim + + # NOTE try to make sure we get matrix back (not a vector) + smpls = sampleFactor(cf, 2)[1] + return length(smpls[1]) end +# FIXME THIS IS NEW REPLACEMENT FUNCTION +# function calcZDim(cf::CalcFactor{T}) where T <: AbstractFactor +# return manifold_dimension(getManifold(cf.factor)) +# end + +calcZDim(cf::CalcFactor{<:GenericMarginal}) = 0 + calcZDim(cf::CalcFactor{<:ManifoldPrior}) = manifold_dimension(cf.factor.M) diff --git a/src/IncrementalInference.jl b/src/IncrementalInference.jl index 8fa1abe10..d4a8cbeab 100644 --- a/src/IncrementalInference.jl +++ b/src/IncrementalInference.jl @@ -422,6 +422,7 @@ include("Factors/GenericFunctions.jl") # Refactoring in progress include("Factors/MsgLikelihoods.jl") +include("entities/GraphConstraintTypes.jl") include("CliqueTypes.jl") include("JunctionTreeTypes.jl") @@ -444,7 +445,6 @@ include("TreeBasedInitialization.jl") include("HeatmapSampler.jl") # special variables and factors, see RoME.jl for more examples -include("GraphConstraintTypes.jl") include("Factors/Mixture.jl") include("Factors/DefaultPrior.jl") include("Factors/LinearRelative.jl") diff --git a/src/GraphConstraintTypes.jl b/src/entities/GraphConstraintTypes.jl similarity index 100% rename from src/GraphConstraintTypes.jl rename to src/entities/GraphConstraintTypes.jl