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

Lie Bracket operation #267

Closed
willat343 opened this issue May 8, 2023 · 12 comments · Fixed by #300
Closed

Lie Bracket operation #267

willat343 opened this issue May 8, 2023 · 12 comments · Fixed by #300
Assignees
Labels
enhancement New feature or request

Comments

@willat343
Copy link
Contributor

I can't seem to find the Lie Bracket (sometimes called commutator) operation in any of the code, documentation or issues and wondered if this exists yet in manif, perhaps under a different name?

This is quite a hard blocker for my application (Manif with ceres, where i need the lie bracket operator in my computation).

If $A$ is a Lie algebra, then the lie bracket is is a mapping of form $[\cdot, \cdot]: A \times A \rightarrow A$. I noticed Sophus has a function Tangent lieBracket(Tangent const& a, Tangent const& b) which performs this operation with tangents instead.

As far as I know the lie bracket operation is unique to each lie algebra, so its not really something that is easy to implement in my code (I template for different lie groups) but would belong in manif. Most of the Lie brackets for common groups are not difficult to compute. Off the top of my head:

  • For R^n lie algebra the lie bracket returns the zero vector
  • For SO(3), the lie bracket returns (the hat of) the cross product of the tangent vectors
  • For SE(3), I think the lie bracket is (the hat of) the small adjoint of the first element multiplied with the second element as a tangent
  • SO(2) and SE(2) should also have nice closed forms, but I don't have a textbook handy.

Is this something you would consider implementing, or perhaps already exists that I haven't found?

@joansola
Copy link
Collaborator

joansola commented May 9, 2023

We did not implement the Lie bracket in manif. But I agree this could be a valuable tool, and it should be easy.

@artivis ?

Regarding the formulas, if I am not wrong the Lie bracket can be computed as [a,b] = a^ b^ - b^ a^ for all matrix Lie groups. Then, for some groups perhaps there exist simplified forms. The result is an element of the Lie Algebra. In manif, this element could be represented back into the Cartesian tangent space:

[ a, b ]v = (a^ b^ - b^ a^)v

where v is the vee operator, so we would have the general implementation as

LieGroupTangent a, b;
LieGroupTangent ab_bracket = ( a.hat() * b.hat() - b.hat() * a.hat() ).vee();

I am not fully sure of what I wrote here. If you can confirm this, then this would be possibly added to manif.

@joansola
Copy link
Collaborator

joansola commented May 9, 2023

The infos above are confirmed here

https://math.stackexchange.com/questions/460079/is-the-lie-bracket-of-a-lie-algebra-of-a-matrix-lie-group-always-the-commutator

and here

"The standard Lie bracket for Lie algebras of matrix Lie groups is given by [A, B] = AB − BA."

which can be found here:

http://www.math.uchicago.edu/~may/VIGRE/VIGRE2010/REUPapers/Turzillo.pdf

@willat343
Copy link
Contributor Author

Yes @joansola that seems right to me. I didn't realise that before, and i can use ( a.hat() * b.hat() - b.hat() * a.hat() ).vee() in the meantime for my application. I've had a chance to skim a couple textbooks (e.g. Barfoot's State Estimation for Robotics) and I believe this applies for matrix lie groups.

For reference, Sophus implements this as a static function in each lie group class, taking A and B as arguments and returning the simplified form of [A, B] for that group. I don't see the general commutator implementation above, perhaps because they don't need it.

manif uses CRTP rather than virtual polymorphism, so i'm not sure off the top of my head what the best implementation would be. Something equivalent to the general commutator in lie_group_base.h (or tangent_base.h) and simplified implmentations in each derived class.

@joansola
Copy link
Collaborator

joansola commented May 9, 2023

For all immplementation issues, @artivis is the man :-) but yes, it seems that in the Tangent base class we could add this implementation, it would become immediately available to all Tangent classes.

@willat343
Copy link
Contributor Author

One additional note is that it would be convenient to have a lie bracket function on the lie algebra elements themselves, which would avoid recomputation / unnecessary mapping to/from the tangent vector in my case. Perhaps this could be an overload, or a different function. For example:

LieGroupTangent lie_bracket(const LieGroupTangent::LieAlg& A, const LieGroupTangent::LieAlg& B) {
    return (A * B - B * A).vee();
}
LieGroupTangent lie_bracket(const LieGroupTangent& a, const LieGroupTangent& b) {
    return lie_bracket(a.hat(), b.hat());
}

Implementation of course will differ, but this is the idea.

@artivis
Copy link
Owner

artivis commented May 10, 2023

Hello there,

This feature is indeed missing and would be a nice addition. However I'm not sure what the syntax would be at the moment. Let me play with it a little and I'll come back with a proposal.

@joansola
Copy link
Collaborator

joansola commented May 10, 2023

One key issue is: we do not have a class for the LieAlgebra space apart from the TangentBase::LieAlg type, and so the vee() operator is missing in manif. I wonder whether it can be added to the TangentBase class, with an API like so:

static TangentBase vee( TangentBase::LieAlg _v_hat)
{
   TangentBase v;
   // build v from _v_hat
   return v;
}

or even from the constructor, with someting like

TangentBase::TangentBase(TangentBase::LieAlg _v_hat)
{
   // build v from _v_hat
   coeffs() = v;
}

@willat343
Copy link
Contributor Author

An additional note is that the lie bracket also equals $[X, Y] = adj(X)Y = XY - YX$. where $adj$ is the small adjoint. See section 10.2.6 equation 10.37 of "Stochastic Models, Information Theory, and Lie Groups, Vol 2".

I thought I would point this out since the small adjoint operation is already defined in code, but it may not help at all.

@nielsvd
Copy link

nielsvd commented Jul 12, 2024

Is there an update regarding this request? I'm refactoring code here, and I would like to get rid of our definitions of the Lie-bracket operations outside of manif. If it is still unclear how this should look like, at least the .vee() operator would be nice to have to allow for a single generic expression for the Lie-bracket operation for all manif types. Perhaps Eigen's expression templates would even be able to go a long way in optimizing these (e.g., Rn commutators always being zero).

I it helps, I could open a PR for the .vee() operators.

@willat343
Copy link
Contributor Author

Perhaps the lie bracket could be implemented something like:

TangentBase::LieAlg TangentBase::lieBracket(TangentBase rhs)
{
   return TangentBase(smallAdj() * rhs.coeffs()).hat();
}

In equation form, this is $(\text{adj}(l^{\wedge}) r)^{\wedge}$, which I'm pretty sure should be exactly $[l^{\wedge}, r^{\wedge}]$.

Potentially this could be specialised for each type to avoid computation (e.g. Rn commutators always being zero as @nielsvd said).

@artivis
Copy link
Owner

artivis commented Jul 18, 2024

Hi there, sorry for not coming back to this earlier.
I appreciate all the comments and suggestions, they're really helpful. I'm currently on vacation but I should have some free time to look at implementing the bracket once back and before the routine kicks back in 👍

@artivis
Copy link
Owner

artivis commented Jul 24, 2024

Hi @willat343, @nielsvd,
the bracket is implemented in #300. If you could provide some feedback as to wether this works for you that would be much appreciated :)

@artivis artivis self-assigned this Jul 26, 2024
@artivis artivis added the enhancement New feature or request label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants