Skip to content

Commit

Permalink
replace #1291 , some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dehann committed Jul 8, 2021
1 parent 7349828 commit 0f7edd4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 40 deletions.
22 changes: 6 additions & 16 deletions src/ApproxConv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 0 additions & 12 deletions src/FGOSUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions src/FactorGraph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion src/IncrementalInference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
File renamed without changes.

0 comments on commit 0f7edd4

Please sign in to comment.