Skip to content

Commit 77b83a9

Browse files
committed
fix mv GenericMarginal.jl
1 parent 070fcb2 commit 77b83a9

File tree

3 files changed

+140
-108
lines changed

3 files changed

+140
-108
lines changed

src/Factors/GenericMarginal.jl

Lines changed: 21 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,32 @@
1+
# agnostic factors for internal use
12

23

34
"""
4-
$SIGNATURES
5-
6-
Calculate the proposals and products on `destvert` using `factors` in factor graph `dfg`.
7-
8-
Notes
9-
- Returns tuple of product and whether full dimensional (=true) or partial (=false).
10-
- `N` determines the number of samples to draw from the marginal.
11-
- `dens` can contain mixed full and partial dimension `ManifoldKernelDensity` beliefs
5+
$(TYPEDEF)
126
"""
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-
#
23-
24-
# get proposal beliefs
25-
destlbl = getLabel(destvert)
26-
inferdim = proposalbeliefs!(dfg, destlbl, factors, dens, solveKey=solveKey, N=N, dbg=dbg)
27-
28-
# take the product
29-
# TODO, make sure oldpts has right number of points!
30-
oldBel = getBelief(dfg, destlbl, solveKey)
31-
oldpts = if Npts(oldBel) == N
32-
getPoints(oldBel)
33-
else
34-
sample(oldBel, N)[1]
35-
end
36-
37-
varType = getVariableType(dfg, destlbl)
38-
pGM = AMP.productbelief(oldpts, getManifold(varType), dens, N, dbg=dbg, logger=logger, asPartial=false )
39-
40-
return pGM, sum(inferdim)
7+
mutable struct GenericMarginal <: AbstractRelativeRoots
8+
Zij::Array{Float64,1}
9+
Cov::Array{Float64,1}
10+
W::Array{Float64,1}
11+
GenericMarginal() = new()
12+
GenericMarginal(a,b,c) = new(a,b,c)
4113
end
4214

43-
predictbelief(dfg::AbstractDFG,
44-
destlbl::Symbol,
45-
fctlbls::AbstractVector{Symbol};
46-
kw... ) = predictbelief(dfg, getVariable(dfg, destlbl), getFactor.(dfg, fctlbls); kw... )
47-
#
48-
49-
predictbelief(dfg::AbstractDFG,
50-
destlbl::Symbol,
51-
::Colon;
52-
kw... ) = predictbelief(dfg, destlbl, getNeighbors(dfg, destlbl); kw... )
53-
#
54-
55-
56-
"""
57-
$(SIGNATURES)
58-
59-
Using factor graph object `dfg`, project belief through connected factors
60-
(convolution with likelihood) to variable `sym` followed by a approximate functional product.
61-
62-
Return: product belief, full proposals, partial dimension proposals, labels
63-
"""
64-
function localProduct(dfg::AbstractDFG,
65-
sym::Symbol;
66-
solveKey::Symbol=:default,
67-
N::Int=maximum([length(getPoints(getBelief(dfg, sym, solveKey))); getSolverParams(dfg).N]),
68-
dbg::Bool=false,
69-
logger=ConsoleLogger() )
70-
#
71-
# vector of all neighbors as Symbols
72-
lb = getNeighbors(dfg, sym)
73-
74-
# # get proposal beliefs
75-
dens = Array{ManifoldKernelDensity,1}()
76-
# partials = Dict{Any, Vector{ManifoldKernelDensity}}()
77-
pGM, sinfd = predictbelief(dfg, sym, lb, solveKey=solveKey, logger=logger, dens=dens, N=N )
7815

79-
# make manifold belief from product
80-
vari = getVariable(dfg, sym)
81-
pp = AMP.manikde!(getManifold(getVariableType(vari)), pGM )
16+
sampleFactor(::CalcFactor{<:GenericMarginal},N::Int) = (0,)
8217

83-
return pp, dens, lb, sinfd
18+
mutable struct PackedGenericMarginal <: PackedInferenceType
19+
Zij::Array{Float64,1}
20+
Cov::Array{Float64,1}
21+
W::Array{Float64,1}
22+
PackedGenericMarginal() = new()
23+
PackedGenericMarginal(a,b,c) = new(a,b,c)
8424
end
85-
localProduct(dfg::AbstractDFG, lbl::AbstractString; kw...) = localProduct(dfg, Symbol(lbl); kw...)
86-
87-
88-
89-
90-
"""
91-
$SIGNATURES
92-
93-
Basic wrapper to take local product and then set the value of `sym` in `dfg`.
94-
95-
Notes
96-
- returns `::Tuple{ManifoldKernelDensity, Float64, Vector{Symbol}}`
97-
98-
DevNotes:
99-
- Unknown issue first occurred here near IIF v0.8.4 tag, recorded case at 2020-01-17T15:26:17.673
100-
"""
101-
function localProductAndUpdate!(dfg::AbstractDFG,
102-
sym::Symbol,
103-
setkde::Bool=true,
104-
logger=ConsoleLogger();
105-
solveKey::Symbol=:default )
106-
#
107-
# calculate new points for sym using existing structure around sym in dfg
108-
newPts, dens, lbl, infdim = localProduct(dfg, sym, solveKey=solveKey, N=getSolverParams(dfg).N, logger=logger)
109-
# maybe update dfg sym with newly calculated points
110-
setkde && 0 < length(getPoints(newPts)) ? setValKDE!(dfg, sym, newPts, false, infdim, solveKey=solveKey) : nothing
111-
112-
return newPts, infdim, lbl
25+
function convert(::Type{PackedGenericMarginal}, d::GenericMarginal)
26+
return PackedGenericMarginal(d.Zij, d.Cov, d.W)
27+
end
28+
function convert(::Type{GenericMarginal}, d::PackedGenericMarginal)
29+
return GenericMarginal(d.Zij, d.Cov, d.W)
11330
end
11431

115-
116-
117-
#
32+
# ------------------------------------------------------------

src/GraphProductOperations.jl

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
2+
3+
"""
4+
$SIGNATURES
5+
6+
Calculate the proposals and products on `destvert` using `factors` in factor graph `dfg`.
7+
8+
Notes
9+
- Returns tuple of product and whether full dimensional (=true) or partial (=false).
10+
- `N` determines the number of samples to draw from the marginal.
11+
- `dens` can contain mixed full and partial dimension `ManifoldKernelDensity` beliefs
12+
"""
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+
#
23+
24+
# get proposal beliefs
25+
destlbl = getLabel(destvert)
26+
inferdim = proposalbeliefs!(dfg, destlbl, factors, dens, solveKey=solveKey, N=N, dbg=dbg)
27+
28+
# take the product
29+
# TODO, make sure oldpts has right number of points!
30+
oldBel = getBelief(dfg, destlbl, solveKey)
31+
oldpts = if Npts(oldBel) == N
32+
getPoints(oldBel)
33+
else
34+
sample(oldBel, N)[1]
35+
end
36+
37+
varType = getVariableType(dfg, destlbl)
38+
pGM = AMP.productbelief(oldpts, getManifold(varType), dens, N, dbg=dbg, logger=logger, asPartial=false )
39+
40+
return pGM, sum(inferdim)
41+
end
42+
43+
predictbelief(dfg::AbstractDFG,
44+
destlbl::Symbol,
45+
fctlbls::AbstractVector{Symbol};
46+
kw... ) = predictbelief(dfg, getVariable(dfg, destlbl), getFactor.(dfg, fctlbls); kw... )
47+
#
48+
49+
predictbelief(dfg::AbstractDFG,
50+
destlbl::Symbol,
51+
::Colon;
52+
kw... ) = predictbelief(dfg, destlbl, getNeighbors(dfg, destlbl); kw... )
53+
#
54+
55+
56+
"""
57+
$(SIGNATURES)
58+
59+
Using factor graph object `dfg`, project belief through connected factors
60+
(convolution with likelihood) to variable `sym` followed by a approximate functional product.
61+
62+
Return: product belief, full proposals, partial dimension proposals, labels
63+
"""
64+
function localProduct(dfg::AbstractDFG,
65+
sym::Symbol;
66+
solveKey::Symbol=:default,
67+
N::Int=maximum([length(getPoints(getBelief(dfg, sym, solveKey))); getSolverParams(dfg).N]),
68+
dbg::Bool=false,
69+
logger=ConsoleLogger() )
70+
#
71+
# vector of all neighbors as Symbols
72+
lb = getNeighbors(dfg, sym)
73+
74+
# # get proposal beliefs
75+
dens = Array{ManifoldKernelDensity,1}()
76+
# partials = Dict{Any, Vector{ManifoldKernelDensity}}()
77+
pGM, sinfd = predictbelief(dfg, sym, lb, solveKey=solveKey, logger=logger, dens=dens, N=N )
78+
79+
# make manifold belief from product
80+
vari = getVariable(dfg, sym)
81+
pp = AMP.manikde!(getManifold(getVariableType(vari)), pGM )
82+
83+
return pp, dens, lb, sinfd
84+
end
85+
localProduct(dfg::AbstractDFG, lbl::AbstractString; kw...) = localProduct(dfg, Symbol(lbl); kw...)
86+
87+
88+
89+
90+
"""
91+
$SIGNATURES
92+
93+
Basic wrapper to take local product and then set the value of `sym` in `dfg`.
94+
95+
Notes
96+
- returns `::Tuple{ManifoldKernelDensity, Float64, Vector{Symbol}}`
97+
98+
DevNotes:
99+
- Unknown issue first occurred here near IIF v0.8.4 tag, recorded case at 2020-01-17T15:26:17.673
100+
"""
101+
function localProductAndUpdate!(dfg::AbstractDFG,
102+
sym::Symbol,
103+
setkde::Bool=true,
104+
logger=ConsoleLogger();
105+
solveKey::Symbol=:default )
106+
#
107+
# calculate new points for sym using existing structure around sym in dfg
108+
newPts, dens, lbl, infdim = localProduct(dfg, sym, solveKey=solveKey, N=getSolverParams(dfg).N, logger=logger)
109+
# maybe update dfg sym with newly calculated points
110+
setkde && 0 < length(getPoints(newPts)) ? setValKDE!(dfg, sym, newPts, false, infdim, solveKey=solveKey) : nothing
111+
112+
return newPts, infdim, lbl
113+
end
114+
115+
116+
117+
#

src/IncrementalInference.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ const InMemDFGType = DFG.LightDFG{SolverParams}
413413
include("entities/FactorOperationalMemory.jl")
414414

415415

416-
include("entities/GraphConstraintTypes.jl")
416+
include("Factors/GenericMarginal.jl")
417417
include("entities/OptionalDensities.jl")
418418
include("entities/FactorGradients.jl")
419419

@@ -479,7 +479,7 @@ include("ExplicitDiscreteMarginalizations.jl")
479479
include("InferDimensionUtils.jl")
480480
include("services/EvalFactor.jl")
481481
include("services/ApproxConv.jl")
482-
include("Factors/GenericMarginal.jl")
482+
include("GraphProductOperations.jl")
483483
include("SolveTree.jl")
484484
include("TetherUtils.jl")
485485
include("TreeDebugTools.jl")

0 commit comments

Comments
 (0)