Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast forward dfg integration testing #1848

Merged
merged 17 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.10'
- '1.11'
os:
- ubuntu-latest
arch:
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
arch:
- x64
version:
- '1.10'
- '1.11'
group:
- 'basic_functional_group'
steps:
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
arch:
- x64
version:
- '1.10'
- '1.11'
group:
- 'test_cases_group'
steps:
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
os:
- ubuntu-latest
version:
- '1.10'
- '1.11'
arch:
- x64
group:
Expand Down
14 changes: 7 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "IncrementalInference"
uuid = "904591bb-b899-562f-9e6f-b8df64c7d480"
keywords = ["MM-iSAMv2", "Bayes tree", "junction tree", "Bayes network", "variable elimination", "graphical models", "SLAM", "inference", "sum-product", "belief-propagation"]
desc = "Implements the Multimodal-iSAMv2 algorithm."
version = "0.35.4"
version = "0.35.5"

[deps]
ApproxManifoldProducts = "9bbbb610-88a1-53cd-9763-118ce10c1f89"
Expand Down Expand Up @@ -65,13 +65,13 @@ IncrInfrInterpolationsExt = "Interpolations"

[compat]
AMD = "0.5"
ApproxManifoldProducts = "0.7, 0.8"
ApproxManifoldProducts = "0.9"
BSON = "0.2, 0.3"
Combinatorics = "1.0"
DataStructures = "0.16, 0.17, 0.18"
DelimitedFiles = "1"
DifferentialEquations = "7"
DistributedFactorGraphs = "0.23, 0.24, 0.25"
DistributedFactorGraphs = "0.25"
Distributions = "0.24, 0.25"
DocStringExtensions = "0.8, 0.9"
FileIO = "1"
Expand All @@ -85,15 +85,15 @@ JSON3 = "1"
KernelDensityEstimate = "0.5.6"
LinearAlgebra = "1.10"
ManifoldDiff = "0.3"
Manifolds = "0.9.12"
Manifolds = "0.10"
ManifoldsBase = "0.15"
Manopt = "0.4.40"
MetaGraphs = "0.7"
Manopt = "0.4.40, 0.5"
MetaGraphs = "0.7, 0.8"
Optim = "1"
OrderedCollections = "1"
PrecompileTools = "1"
ProgressMeter = "1"
RecursiveArrayTools = "2.31.1, 3"
RecursiveArrayTools = "3"
Reexport = "1"
SparseDiffTools = "2"
StaticArrays = "1"
Expand Down
28 changes: 20 additions & 8 deletions ext/HeatmapSampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,16 @@ end

# Helper function to construct HGD
function HeatmapGridDensity(
data::AbstractMatrix{<:Real},
# NAME SUGGESTION: SAMPLEABLE_FIELD, GenericField
field_on_grid::AbstractMatrix{<:Real},
domain::Tuple{<:AbstractVector{<:Real}, <:AbstractVector{<:Real}},
# encapsulate above
hint_callback::Union{<:Function, Nothing} = nothing,
bw_factor::Real = 0.7; # kde spread between domain points
N::Int = 10000,
)
#
pos, weights_ = sampleHeatmap(data, domain..., 0)
pos, weights_ = sampleHeatmap(field_on_grid, domain..., 0)
# recast to the appropriate shape
@cast support_[i, j] := pos[j][i]

Expand All @@ -178,9 +180,9 @@ function HeatmapGridDensity(

@cast vec_preIS[j][i] := pts_preIS[i, j]

# weight the intermediate samples according to interpolation of raw data
# weight the intermediate samples according to interpolation of raw field_on_grid
# interpolated heatmap
hm = Interpolations.linear_interpolation(domain, data) # depr .LinearInterpolation(..)
hm = Interpolations.linear_interpolation(domain, field_on_grid) # depr .LinearInterpolation(..)
d_scalar = Vector{Float64}(undef, length(vec_preIS))

# interpolate d_scalar for intermediate test points
Expand All @@ -204,7 +206,7 @@ function HeatmapGridDensity(
density = ManifoldKernelDensity(TranslationGroup(Ndim(bel)), bel)

# return `<:SamplableBelief` object
return HeatmapGridDensity(data, domain, hint_callback, bw_factor, density)
return HeatmapGridDensity(field_on_grid, domain, hint_callback, bw_factor, density)
end

function Base.isapprox(
Expand All @@ -225,7 +227,7 @@ end

# legacy construct helper
function LevelSetGridNormal(
data::AbstractMatrix{<:Real},
field_on_grid::AbstractMatrix{<:Real},
domain::Tuple{<:AbstractVector{<:Real}, <:AbstractVector{<:Real}},
level::Real,
sigma::Real;
Expand All @@ -235,8 +237,18 @@ function LevelSetGridNormal(
N::Int = 10000,
)
#
hgd = HeatmapGridDensity(data, domain, hint_callback, bw_factor; N = N)
return LevelSetGridNormal(level, sigma, float(sigma_scale), hgd)
field = HeatmapGridDensity(field_on_grid, domain, hint_callback, bw_factor; N = N)
return LevelSetGridNormal(level, sigma, float(sigma_scale), field)
end

# Field: domain (R^2/3), image (R^1/n scalar or tensor) e.g.: x,y -> elevation ;; x, y, z, t -> EM-field (R^(4x4))
# Field( grid_x, grid_y,.... field_grid )
# Field^ = interpolator(field_at_grid, grid)
#
# FieldGrid(data_on_grid, grid_domain) # internally does interpolation vodoo (same as Field^)
# BeliefGrid <: FieldGrid
# BeliefGrid(field_data: FieldGrid, measurement: Normal(mean: image_domain, cov: image_domain^2) ) -> domain, R_0+
#
# calcApproxLoss(ref::BeliefGrid, appr::ManifoldKernelDensity)::Field{Real}
# ref = Normal(ScalarField - measurement, cov)
#
53 changes: 53 additions & 0 deletions src/Factors/GenericFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,59 @@ function (cf::CalcFactor{<:ManifoldFactor})(X, p, q)
return distanceTangent2Point(cf.factor.M, X, p, q)
end


## ======================================================================================
## adjoint factor - adjoint action applied to the measurement
## ======================================================================================


# Adjoints defined in ApproxManifoldProducts
struct AdFactor{F <: AbstractManifoldMinimize} <: AbstractManifoldMinimize
factor::F
end

function (cf::CalcFactor{<:AdFactor})(Xϵ, p, q)
# M = getManifold(cf.factor)
# p,q ∈ M
# Xϵ ∈ TϵM
# ϵ = identity_element(M)
# transform measurement from TϵM to TpM (global to local coordinates)
# Adₚ⁻¹ = AdjointMatrix(M, p)⁻¹ = AdjointMatrix(M, p⁻¹)
# Xp = Adₚ⁻¹ * Xϵᵛ
# ad = Ad(M, inv(M, p))
# Xp = Ad(M, inv(M, p), Xϵ)
# Xp = adjoint_action(M, inv(M, p), Xϵ)
#TODO is vector transport supposed to be the same?
# Xp = vector_transport_to(M, ϵ, Xϵ, p)

# Transform measurement covariance
# ᵉΣₚ = Adₚ ᵖΣₚ Adₚᵀ
#TODO test if transforming sqrt_iΣ is the same as Σ
# Σ = ad * inv(cf.sqrt_iΣ^2) * ad'
# sqrt_iΣ = convert(typeof(cf.sqrt_iΣ), sqrt(inv(Σ)))
# sqrt_iΣ = convert(typeof(cf.sqrt_iΣ), ad * cf.sqrt_iΣ * ad')
Xp = Xϵ

child_cf = CalcFactorResidual(
cf.faclbl,
cf.factor.factor,
cf.varOrder,
cf.varOrderIdxs,
cf.meas,
cf.sqrt_iΣ,
cf.cache,
)
return child_cf(Xp, p, q)
end

getMeasurementParametric(f::AdFactor) = getMeasurementParametric(f.factor)

getManifold(f::AdFactor) = getManifold(f.factor)
function getSample(cf::CalcFactor{<:AdFactor})
M = getManifold(cf)
return sampleTangent(M, cf.factor.factor.Z)
end

## ======================================================================================
## ManifoldPrior
## ======================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/services/FGOSUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function manikde!(
variableType::Union{InstanceType{<:InferenceVariable}, InstanceType{<:AbstractFactor}},
pts::AbstractVector{P};
kw...,
) where {P <: Union{<:AbstractArray, <:Number, <:Manifolds.ArrayPartition}}
) where {P <: Union{<:AbstractArray, <:Number, <: ArrayPartition}}
#
M = getManifold(variableType)
# @info "pts" P typeof(pts[1]) pts[1]
Expand Down
2 changes: 1 addition & 1 deletion src/services/GraphInit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function initVariable!(
# TODO ArrayPartition inputs
_prodrepr(pt) = pt
# _prodrepr(pt::Tuple) = Manifolds.ProductRepr(pt...)
_prodrepr(pt::Tuple) = Manifolds.ArrayPartition(pt...)
_prodrepr(pt::Tuple) = ArrayPartition(pt...)

M = getManifold(vari)
pp = manikde!(M, _prodrepr.(pts); bw)
Expand Down
2 changes: 1 addition & 1 deletion src/services/SolverAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function solveTree!(
runtaskmonitor::Bool = true,
algorithm::Symbol = :default,
solveKey::Symbol = algorithm,
multithread::Bool = true,
multithread::Bool = false,
)
#
# workaround in case isolated variables occur
Expand Down
2 changes: 1 addition & 1 deletion test/basicGraphsOperations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ varT = LinearRelative{1}
manikde!(varT, pts)


DFG.@defVariable _TestManiKde IIF.Manifolds.SpecialEuclidean(2) ArrayPartition([0;0.], [1 0; 0 1.])
DFG.@defVariable _TestManiKde IIF.Manifolds.SpecialEuclidean(2; vectors=HybridTangentRepresentation()) ArrayPartition([0;0.], [1 0; 0 1.])

# construct directly with ArrayPartition
pts = [ArrayPartition(randn(2), [1 0; 0 1.]) for _ in 1:100]
Expand Down
2 changes: 1 addition & 1 deletion test/manifolds/factordiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ end
##


M = SpecialEuclidean(2)
M = SpecialEuclidean(2; vectors=HybridTangentRepresentation())
z = ArrayPartition(SA[10.0; 0.0], SMatrix{2,2}(0.0, -1.0, 1.0, 0.0))

p1 = ArrayPartition(SA[0.0; 0.0], SMatrix{2,2}(1, 0, 0, 1.))
Expand Down
8 changes: 4 additions & 4 deletions test/manifolds/manifolddiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ sol = Optim.optimize(f, g_FD!, x0, Optim.ConjugateGradient(; manifold=ManifoldWr
end


@testset "Modified Manifolds.jl ManifoldWrapper <: Optim.Manifold for SpecialEuclidean(2)" begin
@testset "Modified Manifolds.jl ManifoldWrapper <: Optim.Manifold for SpecialEuclidean(2; vectors=HybridTangentRepresentation())" begin
##

M = Manifolds.SpecialEuclidean(2)
M = Manifolds.SpecialEuclidean(2; vectors=HybridTangentRepresentation())
e0 = ArrayPartition([0,0.], [1 0; 0 1.])

x0 = deepcopy(e0)
Expand Down Expand Up @@ -171,7 +171,7 @@ end
##


M = Manifolds.SpecialEuclidean(3)
M = Manifolds.SpecialEuclidean(3; vectors=HybridTangentRepresentation())
e0 = ArrayPartition([0,0,0.], Matrix(_Rot.RotXYZ(0,0,0.)))

x0 = deepcopy(e0)
Expand Down Expand Up @@ -217,7 +217,7 @@ end
@testset "Optim.Manifolds, SpecialEuclidean(3), using IIF.optimizeManifold_FD" begin
##

M = Manifolds.SpecialEuclidean(3)
M = Manifolds.SpecialEuclidean(3; vectors=HybridTangentRepresentation())
e0 = ArrayPartition([0,0,0.], Matrix(_Rot.RotXYZ(0,0,0.)))

x0 = deepcopy(e0)
Expand Down
2 changes: 1 addition & 1 deletion test/testBasicManifolds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using Test

w = [-0.0;-0.78;-0.18]

M = SpecialEuclidean(3)
M = SpecialEuclidean(3; vectors=HybridTangentRepresentation())
Mr = M.manifold[2]
pPq = ArrayPartition(zeros(3), exp(Mr, Identity(Mr), hat(Mr, Identity(Mr), w)))
rPc_ = exp(M, Identity(M), hat(M, Identity(M), [zeros(3);w]))
Expand Down
3 changes: 1 addition & 2 deletions test/testCompareVariablesFactors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ sfg = buildSubgraph(fg, [:x0;:x1], 1) # distance=1 to include factors

#FIXME JT - this doesn't make sense to pass, it is a subgraph so should it not rather be ⊂ [subset]?
# compareDFG(fg1, fg2, by=⊂, skip=...)
@test fg.sessionLabel == sfg.sessionLabel[1:length(fg.sessionLabel)]
@test compareFactorGraphs(fg, sfg, skip=[:labelDict;:addHistory;:logpath;:sessionLabel; :particleidx; :varidx])
@test_broken compareFactorGraphs(fg, sfg, skip=[:labelDict;:addHistory;:logpath;:sessionLabel; :particleidx; :varidx])

# drawGraph(sfg)

Expand Down
Loading
Loading