Skip to content

Commit 6a613a4

Browse files
committed
wip on new setPartial
1 parent 1a26b5b commit 6a613a4

File tree

6 files changed

+95
-29
lines changed

6 files changed

+95
-29
lines changed

src/Deprecated.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,29 @@ end
133133
## Deprecate code below before v0.26
134134
##==============================================================================
135135

136+
# wow, that was quite far off -- needs testing
137+
# function factorCanInitFromOtherVars(dfg::T,
138+
# fct::Symbol,
139+
# loovar::Symbol)::Tuple{Bool, Vector{Symbol}, Vector{Symbol}} where T <: AbstractDFG
140+
# #
141+
# # all variables attached to this factor
142+
# varsyms = getNeighbors(dfg, fct)
143+
#
144+
# # list of factors to use in init operation
145+
# useinitfct = Symbol[]
146+
# faillist = Symbol[]
147+
# for vsym in varsyms
148+
# xi = DFG.getVariable(dfg, vsym)
149+
# if (isInitialized(xi) && sum(useinitfct .== fct) == 0 ) || length(varsyms) == 1
150+
# push!(useinitfct, fct)
151+
# end
152+
# end
153+
#
154+
# return (length(useinitfct)==length(varsyms)&&length(faillist)==0,
155+
# useinitfct,
156+
# faillist )
157+
# end
158+
136159
@deprecate calcPerturbationFromVariable( fgc::FactorGradientsCached!, fromVar::Int, infoPerCoord::AbstractVector;tol::Real=0.02*fgc._h ) calcPerturbationFromVariable(fgc, [fromVar => infoPerCoord;], tol=tol )
137160

138161
function getVal(vA::Vector{<:DFGVariable}, solveKey::Symbol=:default)

src/FactorGraph.jl

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,9 @@ function factorCanInitFromOtherVars(dfg::AbstractDFG,
738738
mhp = getMultihypoDistribution(fctnode).p
739739
allmhp,certainidx,uncertnidx = getHypothesesVectors(mhp)
740740
if isLeastOneHypoAvailable(sfidx, certainidx, uncertnidx, isinit)
741-
# special case works
742-
@info "allowing init from incomplete set of previously initialized hypotheses, fct=$fct"
743-
canuse = true
741+
# special case works
742+
@info "allowing init from incomplete set of previously initialized hypotheses, fct=$fct"
743+
canuse = true
744744
end
745745
end
746746

@@ -754,29 +754,6 @@ function factorCanInitFromOtherVars(dfg::AbstractDFG,
754754
end
755755

756756

757-
# wow, that was quite far off -- needs testing
758-
# function factorCanInitFromOtherVars(dfg::T,
759-
# fct::Symbol,
760-
# loovar::Symbol)::Tuple{Bool, Vector{Symbol}, Vector{Symbol}} where T <: AbstractDFG
761-
# #
762-
# # all variables attached to this factor
763-
# varsyms = getNeighbors(dfg, fct)
764-
#
765-
# # list of factors to use in init operation
766-
# useinitfct = Symbol[]
767-
# faillist = Symbol[]
768-
# for vsym in varsyms
769-
# xi = DFG.getVariable(dfg, vsym)
770-
# if (isInitialized(xi) && sum(useinitfct .== fct) == 0 ) || length(varsyms) == 1
771-
# push!(useinitfct, fct)
772-
# end
773-
# end
774-
#
775-
# return (length(useinitfct)==length(varsyms)&&length(faillist)==0,
776-
# useinitfct,
777-
# faillist )
778-
# end
779-
780757
"""
781758
$(SIGNATURES)
782759
@@ -830,6 +807,7 @@ function doautoinit!( dfg::AbstractDFG,
830807
end
831808
# FIXME ensure a product of only partial densities and returned pts are put to proper dimensions
832809
bel,inferdim = propagateBelief(dfg, getVariable(dfg,vsym), getFactor.(dfg,useinitfct), solveKey=solveKey, logger=logger)
810+
@info "MANIFOLD IS" bel.manifold string(getPoints(bel, false)[1])
833811
setValKDE!(xi, getPoints(bel, false), true, inferdim, solveKey=solveKey)
834812
# Update the estimates (longer DFG function used so cloud is also updated)
835813
setVariablePosteriorEstimates!(dfg, xi.label, solveKey)

src/SolverUtilities.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Related
2121
randToPoints(distr::SamplableBelief, N::Int=1) = [rand(distr,1)[:] for i in 1:N]
2222
randToPoints(distr::ManifoldKernelDensity, N::Int=1) = rand(distr,N)
2323

24+
2425
_setPointsMani!(dest::AbstractVector, src::AbstractVector) = (dest .= src)
2526
_setPointsMani!(dest::AbstractMatrix, src::AbstractMatrix) = (dest .= src)
2627
function _setPointsMani!(dest::AbstractVector, src::AbstractMatrix)
@@ -43,6 +44,33 @@ function _setPointsMani!(dest::ProductRepr, src::ProductRepr)
4344
end
4445
end
4546

47+
# asPartial=true indicates that src coords are smaller than dest coords, and false implying src has dummy values in placeholder dimensions
48+
function _setPointsManiPartial!(Mdest::AbstractManifold,
49+
dest,
50+
Msrc::AbstractManifold,
51+
src,
52+
partial::AbstractVector{<:Integer},
53+
asPartial::Bool=true )
54+
#
55+
56+
e0 = identity(Mdest, dest)
57+
dest_ = vee(Mdest, e0, log(Mdest, e0, dest))
58+
59+
e0s = identity(Msrc, src)
60+
src_ = vee(Msrc, e0s, log(Msrc, e0s, src))
61+
62+
# do the copy in coords
63+
dest_[partial] .= asPartial ? src_ : view(src_, partial)
64+
65+
# update points base in original
66+
dest__ = exp(Mdest, e0, hat(Mdest, e0, dest_))
67+
_setPointsMani!(dest, dest__)
68+
69+
#
70+
return dest
71+
end
72+
73+
4674

4775
"""
4876
$TYPEDSIGNATURES

src/entities/OptionalDensities.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ function Base.show(io::IO, mime::MIME"text/plain", x::HeatmapDensityRegular{T,H,
8282
nothing
8383
end
8484

85-
# Base.show(io::IO, ::MIME"application/prs.juno.inline", x::HeatmapDensityRegular) = x
85+
Base.show(io::IO, ::MIME"application/prs.juno.inline", x::HeatmapDensityRegular) = show(io,x)
8686

8787
#

test/testApproxConv.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,23 @@ pts_ = approxConv(fg, :x1f1, :l2)
7878
@test 1.6 < Statistics.std(pts) < 4.0
7979

8080
##
81-
8281
end
8382

8483

84+
@testset "test approxConvBelief with partial prior" begin
85+
##
86+
87+
fg = initfg()
88+
89+
addVariable!(fg, :x0, ContinuousEuclid{2})
90+
pp = PartialPrior(Normal(),(2,))
91+
addFactor!(fg, [:x0], pp, graphinit=false)
92+
93+
approxConvBelief(fg, :x0f1, :x0)
94+
95+
@info "second test with more complicated manifolds in testSpecialEuclidean2Mani.jl"
96+
97+
##
98+
end
8599

86100
#

test/testSpecialEuclidean2Mani.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ v0 = addVariable!(fg, :x0, SpecialEuclidean2)
3636
mp = ManifoldPrior(SpecialEuclidean(2), ProductRepr(@MVector([0.0,0.0]), @MMatrix([1.0 0.0; 0.0 1.0])), MvNormal([0.01, 0.01, 0.01]))
3737
p = addFactor!(fg, [:x0], mp)
3838

39+
40+
##
41+
3942
doautoinit!(fg, :x0)
4043

4144
##
@@ -78,6 +81,23 @@ f = addFactor!(fg, [:x1, :x2], mf)
7881
@test solveTree!(fg; verbose=true) isa Tuple
7982

8083

84+
## test partial prior issue
85+
86+
fg = initfg()
87+
88+
v0 = addVariable!(fg, :x0, SpecialEuclidean2)
89+
mp = PartialPrior(MvNormal([0.01, 0.01]), (1,2))
90+
91+
p = addFactor!(fg, [:x0], mp, graphinit=false)
92+
93+
##
94+
95+
# try
96+
pbel_ = approxConvBelief(fg, :x0f1, :x0)
97+
# catch
98+
# @test_broken false
99+
# end
100+
81101
##
82102
end
83103

@@ -190,4 +210,7 @@ vnd = getVariableSolverData(fg, :x0)
190210
vnd = getVariableSolverData(fg, :x1)
191211
@test all(isapprox.(mean(vnd.val), [1.0,2.0], atol=0.1))
192212

193-
end
213+
end
214+
215+
216+
#

0 commit comments

Comments
 (0)