Skip to content

Commit 4af111d

Browse files
committed
wip changing to AMP.replace
1 parent ffd455b commit 4af111d

File tree

5 files changed

+79
-27
lines changed

5 files changed

+79
-27
lines changed

src/FactorGraph.jl

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,36 @@ setVariableInferDim!(vari::DFGVariable, val::Real) = setVariableInferDim!(getSol
227227
## ==============================================================================================
228228

229229

230-
function setValKDE!(vd::VariableNodeData,
231-
p::ManifoldKernelDensity,
230+
function setValKDE!(vnd::VariableNodeData,
231+
p::ManifoldKernelDensity{M,B,Nothing},
232232
setinit::Bool=true,
233-
inferdim::Union{Float32, Float64, Int32, Int64}=0 )
233+
inferdim::Union{Float32, Float64, Int32, Int64}=0 ) where {M,B}
234234
#
235-
ptsArr = AMP.getPoints(p)
236-
# @show typeof(ptsArr)
237-
# @cast ptsArr[j][i] := pts[i,j]
235+
# L==Nothing means no partials
236+
ptsArr = AMP.getPoints(p) # , false) # for not partial
237+
# also set the bandwidth
238238
bws = getBW(p)[:,1]
239-
setValKDE!(vd,ptsArr,bws,setinit,inferdim )
239+
setValKDE!(vnd,ptsArr,bws,setinit,inferdim )
240+
nothing
241+
end
242+
243+
244+
function setValKDE!(vnd::VariableNodeData,
245+
mkd::ManifoldKernelDensity{M,B,L},
246+
setinit::Bool=true,
247+
inferdim::Union{Float32, Float64, Int32, Int64}=0 ) where {M,B,L<:AbstractVector}
248+
#
249+
oldbel = getBelief(vnd)
250+
# Set partial dims as Manifold points
251+
ptsArr = AMP.getPoints(mkd, false)
252+
oldPts = getVal(vnd)
253+
# get partial coord dims
254+
pvec = mkd._partial
255+
256+
# also set the bandwidth
257+
bws = getBW(mkd)[:,1]
258+
bw_ = getBW
259+
setValKDE!(vnd,ptsArr,bws,setinit,inferdim )
240260
nothing
241261
end
242262

@@ -809,7 +829,7 @@ function doautoinit!( dfg::AbstractDFG,
809829
@info "do init of $vsym"
810830
end
811831
# FIXME ensure a product of only partial densities and returned pts are put to proper dimensions
812-
pts,inferdim = predictbelief(dfg, vsym, useinitfct, solveKey=solveKey, logger=logger)
832+
bel,inferdim = proposalBelief(dfg, vsym, useinitfct, solveKey=solveKey, logger=logger)
813833
setValKDE!(xi, pts, true, inferdim, solveKey=solveKey)
814834
# Update the estimates (longer DFG function used so cloud is also updated)
815835
setVariablePosteriorEstimates!(dfg, xi.label, solveKey)
@@ -1379,7 +1399,7 @@ end
13791399
13801400
Get KernelDensityEstimate kde estimate stored in variable node.
13811401
"""
1382-
getBelief(vnd::VariableNodeData) = manikde!(getVal(vnd), getBW(vnd)[:,1], getVariableType(vnd) )
1402+
getBelief(vnd::VariableNodeData) = manikde!(getManifold(getVariableType(vnd)), getVal(vnd), bw=getBW(vnd)[:,1] )
13831403

13841404
getBelief(v::DFGVariable, solvekey::Symbol=:default) = getBelief(getSolverData(v, solvekey))
13851405
getBelief(dfg::AbstractDFG, lbl::Symbol, solvekey::Symbol=:default) = getBelief(getVariable(dfg, lbl), solvekey)

src/Factors/PartialPriorPassThrough.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ struct PartialPriorPassThrough{B <: HeatmapDensityRegular, T <:Tuple} <: Abstrac
99
end
1010

1111
# this step is skipped during main inference process
12-
getSample(cf::CalcFactor{<:PartialPriorPassThrough}, N::Int=1) = ([rand(cf.factor.Z.densityFnc,1) for _ in 1:N], )
12+
getSample(cf::CalcFactor{<:PartialPriorPassThrough}, N::Int=1) = ([rand(cf.factor.Z.densityFnc,1) for _ in 1:N], )
13+
14+
getManifold(pppt::PartialPriorPassThrough{<:HeatmapDensityRegular{T,H,<:ManifoldKernelDensity}}) where {T,H} = (pppt.Z.densityFnc.manifold)
15+
16+
#

src/GraphProductOperations.jl

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,60 @@ Notes
99
- Returns tuple of product and whether full dimensional (=true) or partial (=false).
1010
- `N` determines the number of samples to draw from the marginal.
1111
- `dens` can contain mixed full and partial dimension `ManifoldKernelDensity` beliefs
12+
13+
Related
14+
15+
[`approxConv`](@ref), [`proposalbeliefs!`](@ref), [`AMP.manifoldProduct`](@ref)
1216
"""
13-
function predictbelief( dfg::AbstractDFG,
14-
destvert::DFGVariable,
15-
factors::Vector{<:DFGFactor};
16-
solveKey::Symbol=:default,
17-
dens = Vector{ManifoldKernelDensity}(),
18-
N::Int=maximum([length(getPoints(getBelief(destvert, solveKey))); getSolverParams(dfg).N]),
19-
needFreshMeasurements::Bool=true,
20-
dbg::Bool=false,
21-
logger=ConsoleLogger() )
22-
#
17+
function propagateBelief( dfg::AbstractDFG,
18+
destvar::DFGVariable,
19+
factors::AbstractVector{<:DFGFactor};
20+
solveKey::Symbol=:default,
21+
dens = Vector{ManifoldKernelDensity}(),
22+
N::Int=maximum([length(getPoints(getBelief(destvar, solveKey))); getSolverParams(dfg).N]),
23+
needFreshMeasurements::Bool=true,
24+
dbg::Bool=false,
25+
logger=ConsoleLogger() )
26+
#
2327

2428
# get proposal beliefs
25-
destlbl = getLabel(destvert)
29+
destlbl = getLabel(destvar)
2630
inferdim = proposalbeliefs!(dfg, destlbl, factors, dens, solveKey=solveKey, N=N, dbg=dbg)
2731

28-
# take the product
29-
# TODO, make sure oldpts has right number of points!
32+
# make sure oldpts has right number of points
3033
oldBel = getBelief(dfg, destlbl, solveKey)
3134
oldpts = if Npts(oldBel) == N
3235
getPoints(oldBel)
3336
else
3437
sample(oldBel, N)[1]
3538
end
3639

37-
varType = getVariableType(dfg, destlbl)
38-
pGM = AMP.productbelief(oldpts, getManifold(varType), dens, N, dbg=dbg, logger=logger, asPartial=false )
40+
# few more data requirements
41+
varType = getVariableType(destvar)
42+
M = getManifold(varType)
3943

40-
return pGM, sum(inferdim)
44+
# take the product
45+
mkd = AMP.manifoldProduct(dens, M, Niter=1, oldPoints=oldpts)
46+
47+
return mkd, sum(inferdim)
48+
end
49+
50+
"""
51+
$SIGNATURES
52+
53+
This is an old function that will be replace by [`propagateBelief`](@ref).
54+
"""
55+
function predictbelief( dfg::AbstractDFG,
56+
destvert::DFGVariable,
57+
factors::Vector{<:DFGFactor};
58+
asPartial::Bool=false,
59+
kw... )
60+
#
61+
# new
62+
mkd, ifd = propagateBelief(dfg,destvert,factors;kw...)
63+
64+
# legacy interface
65+
return getPoints(mkd, asPartial), ifd
4166
end
4267

4368
predictbelief(dfg::AbstractDFG,
@@ -53,6 +78,7 @@ predictbelief(dfg::AbstractDFG,
5378
#
5479

5580

81+
5682
"""
5783
$(SIGNATURES)
5884

src/HeatmapSampler.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ function HeatmapDensityRegular( data::AbstractMatrix{<:Real},
9696
# final samplable density object
9797
bw = getBW(density_)[:,1]
9898
@cast pts[i,j] := vec_preIS[j][i]
99-
density = kde!(collect(pts), bw, weights)
99+
bel = kde!(collect(pts), bw, weights)
100+
density = ManifoldKernelDensity(TranslationGroup(Ndim(bel)), bel)
100101

101102
# return `<:SamplableBelief` object
102103
HeatmapDensityRegular(data, domain, hist_callback, level, sigma, float(sigma_scale), bw_factor, density)

src/IncrementalInference.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ export *,
345345

346346
# user functions
347347
predictbelief,
348+
propagateBelief,
348349
getCliqMat,
349350
getCliqAssocMat,
350351
getCliqMsgMat,

0 commit comments

Comments
 (0)