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

WIP on manifold optimization and factors #1292

Merged
merged 12 commits into from
Jul 8, 2021
Merged

Conversation

Affie
Copy link
Member

@Affie Affie commented Jul 5, 2021

  • Factors returns tangent vector at p
  • _solveLambdaNumeric does distance2
  • parametric does Mahalanobis distance2

Tests added:

Needs:

Breaks (TODO):

@Affie Affie added this to the v0.25.0 milestone Jul 5, 2021
@codecov
Copy link

codecov bot commented Jul 5, 2021

Codecov Report

Merging #1292 (cf7837e) into master (9b0c5fc) will decrease coverage by 29.99%.
The diff coverage is 42.46%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1292       +/-   ##
===========================================
- Coverage   40.63%   10.63%   -30.00%     
===========================================
  Files          57       57               
  Lines        4794     4860       +66     
===========================================
- Hits         1948      517     -1431     
- Misses       2846     4343     +1497     
Impacted Files Coverage Δ
src/CompareUtils.jl 0.00% <0.00%> (-18.75%) ⬇️
src/FactorGraph.jl 46.51% <0.00%> (-18.13%) ⬇️
src/FactorGraphTypes.jl 100.00% <ø> (ø)
src/ParametricUtils.jl 0.00% <0.00%> (ø)
src/Factors/GenericFunctions.jl 40.42% <28.57%> (+40.42%) ⬆️
src/ApproxConv.jl 51.79% <43.75%> (-14.75%) ⬇️
src/NumericalCalculations.jl 47.94% <89.47%> (-5.63%) ⬇️
src/FGOSUtils.jl 17.72% <100.00%> (-18.99%) ⬇️
src/TreeMessageAccessors.jl 0.00% <0.00%> (-76.00%) ⬇️
src/AliasScalarSampling.jl 0.00% <0.00%> (-69.24%) ⬇️
... and 32 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b0c5fc...cf7837e. Read the comment docs.


for cfp in cfvec

varOrder = getindex.(Ref(labeldict), cfp.varOrder)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, julia is already pass by reference, so adding a second tier Ref over a dict ref seems weird to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again for broadcasting.

Comment on lines 177 to 190
function calcVariableCovarianceBasic(M::AbstractManifold, ptsArr::Vector{P}) where P
#TODO double check the maths,. it looks like its working at least for groups
μ = mean(M, ptsArr)
Xcs = vee.(Ref(M), Ref(μ), log.(Ref(M), Ref(μ), ptsArr))
Σ = mean(Xcs .* adjoint.(Xcs))
@debug "calcVariableCovarianceBasic" μ
@debug "calcVariableCovarianceBasic" Σ
# TODO don't know what to do here so keeping as before, #FIXME it will break
# a change between this and previous is that a full covariance matrix is returned
msst = Σ
msst_ = 0 < sum(1e-10 .< msst) ? maximum(msst) : 1.0
return msst_
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dehann, have a look please

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msst_ is probably part of initialization when trivial case errors occur in this calculation. I was expecting the first mean for mu, the coordinates on Xc look right (around mu). The adjoint is somewhat unfamiliar to me in this context, must just make sure that the communativity is right, e.g. hypothetically:

# good
aRc = adjoint(bRa)*bRc

# vs bad
bRa*adjoint(bRc)

since the latter would give incorrect answers. I'm not sure and would need to dig more to learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xcs is in coordinates, and transpose is just used to build the matrix to be used for the covariance

Copy link
Member Author

@Affie Affie Jul 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #1280, we can perhaps continue there

src/ApproxConv.jl Outdated Show resolved Hide resolved
src/ApproxConv.jl Show resolved Hide resolved
@dehann
Copy link
Member

dehann commented Jul 8, 2021

HI @Affie , the error on serialization has to do with the new ccw.manifolds field:

The issue is that during unpackFactor, we need to construct a ccw without yet knowing what the manifolds are from variables to which it will be attached,
https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/blob/54c128944f02193dfbbb685eb439737be8909d78/src/services/Serialization.jl#L357

see the DFGVariable[] argument here:

ccw = prepgenericconvolution(DFG.DFGVariable[], usrfnc, multihypo=mhcat, nullhypo=nh, inflation=packed.inflation)

which creates the problem on the new line of code here (getManifolds on an empty array):

manifolds = tuple(getManifold.(Xi)...)

@dehann
Copy link
Member

dehann commented Jul 8, 2021

ill look more tomorrow

@Affie
Copy link
Member Author

Affie commented Jul 8, 2021

About serialization issue of new manifolds field.

Yes, I know it's caused by serialization. I just didn't know how to fix it.
After yesterday's chat I decided to change it to a vector of variable types and use getManifold, ie Vector{DataType}

And skip it in the specific test for now.

@Affie Affie self-assigned this Jul 8, 2021
@Affie Affie marked this pull request as ready for review July 8, 2021 08:44
@Affie Affie merged commit 58d7be2 into master Jul 8, 2021
@dehann dehann deleted the 21Q2/enh/on_manifold_optim2 branch March 6, 2022 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants