Giter Club home page Giter Club logo

liegroups's Introduction

liegroups

Python implementation of SO2, SE2, SO3, and SE3 matrix Lie groups using numpy or PyTorch.

[Documentation]

Installation

To install, cd into the repository directory (the one with setup.py) and run:

pip install .

or

pip install -e .

The -e flag tells pip to install the package in-place, which lets you make changes to the code without having to reinstall every time. Do not do this on shared workstations!

Testing

Ensure you have pytest installed on your system, or install it using conda install pytest or pip install pytest. Then run pytest in the repository directory.

Usage

Numpy and torch implementations are accessible through the liegroups.numpy and liegroups.torch subpackages. By default, the numpy implementation is available through the top-level package.

Access the numpy implementation using something like

from liegroups import SE3

or

from liegroups.numpy import SO2

Access the pytorch implementation using something like

from liegroups.torch import SE2

liegroups's People

Contributors

brandonwagstaff avatar icradebates avatar leeclemnet avatar trevorablett avatar valentinp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

liegroups's Issues

Bug in quaternion conversion?

Code to reproduce

R = np.array([[-0.26588199,  0.0721791,  -0.96129961],
                      [ 0.01772801,  0.99739046,  0.06998566],
                      [ 0.96384256,  0.001566,   -0.26646775]])
R = SO3.from_matrix(R, True)
q = R.to_quaternion()
print(np.isclose(la.norm(q), 1))

prints False

one problem on left multiply distrub

Hi, thank you for professional Liegroup package.

I can get different results when trying left multiply disturbance by two ways :

T : a 4x4 transition numpy array
delta_t=np.array([1,0,0,0,0,0]) #liealgebra

print(SE3.exp(delta_t).as_matrix().dot(T)) #1st way
print(SE3.exp(delta_t).dot(T)) #2nd way which delivered a wrong result

Should the result from the 2nd way be equal to the 1st way from your original idea?
Or, is T an illegal input in the 2nd way?

Extra care needed for np.sin(theta) where theta = +np.pi or -np.pi ?

Hello,

In the so3.log function

return self.vee((0.5 * angle / np.sin(angle)) * (self.mat - self.mat.T))

There's a division by np.sin(angle) but there isn't a check to see if angle is +np.pi or -np.pi. I understand that due to numerical precision, np.sin(np.pi) != 0.0 but I'm wondering if there needs to be some extra care taken here.

See

https://en.wikipedia.org/wiki/Axis–angle_representation#Log_map_from_SO(3)_to_%7F'%22%60UNIQ--postMath-0000000D-QINU%60%22'%7F(3)

Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.

When I use liegroups in a loss function, it reports error as follows:
Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.

Here is the code:

    print('rotation_ab_pred size = {} type = {}'.format(rotation_ab_pred.size(), rotation_ab_pred.type()))
    rvec_ab_pred = SO2.from_matrix(rotation_ab_pred)

And the result:

rotation_ab_pred size = torch.Size([32, 2, 2]) type = torch.cuda.FloatTensor

Error with exponential map and logarithm map

Hi,
first of all thanks for your work.
My problem is linked to transformation of SE3 matrix to xi vector and vice versa. This code section below is a test that shows that the original SE3 matrix has different values compare to output matrix, but this happens with just values that have small module.

import torch
from liegroups.torch import SE3

print("Test 1:")
test_SE3_matrix = torch.tensor([[0.9999957085, -0.002008878859, -0.002134637441, 1.187580466], [0.002002746798, 0.9999938607, -0.002870822791, 0.06579889357], [0.002140391385, 0.002866535215, 0.9999936223, -0.05322432518], [0., 0., 0., 1.]])
print("Testing SE3 matrix:\n", test_SE3_matrix)
test_xi = SE3.from_matrix(test_SE3_matrix).log()
print("Output xi value:", test_xi)
test_original_value_SE3_matrix = SE3.exp(test_xi).as_matrix()
print("It should be the same as the start test matrix:\n", test_original_value_SE3_matrix)

print("\nTest 2:")
test_SE3_matrix_2 = torch.tensor([[1.000000e-00, 9.043681e-12, 2.326810e-11, -5.551115e-17], [9.043682e-12, 1.000000e+00, 2.392370e-10, 0.000000e+00], [2.326809e-11, 2.392370e-10, 9.999999e-01, -2.220446e-16], [0., 0., 0., 1.]])
print("Testing SE3 matrix:\n", test_SE3_matrix_2)
test_xi_2 = SE3.from_matrix(test_SE3_matrix_2).log()
print("Output xi value:", test_xi_2)
test_original_value_SE3_matrix_2 = SE3.exp(test_xi_2).as_matrix()
print("It should be the same as the start test matrix:\n", test_original_value_SE3_matrix_2)

And this is the output:

Test 1:
Testing SE3 matrix:
tensor([[ 1.0000, -0.0020, -0.0021, 1.1876], [ 0.0020, 1.0000, -0.0029, 0.0658], [ 0.0021, 0.0029, 1.0000, -0.0532], [ 0.0000, 0.0000, 0.0000, 1.0000]])
Output xi value: tensor([ 1.1876, 0.0645, -0.0546, 0.0029, -0.0021, 0.0020])
It should be the same as the start test matrix:
tensor([[ 1.0000, -0.0020, -0.0021, 1.1876], [ 0.0020, 1.0000, -0.0029, 0.0658], [ 0.0021, 0.0029, 1.0000, -0.0532], [ 0.0000, 0.0000, 0.0000, 1.0000]])

Test 2:
Testing SE3 matrix:
tensor([[ 1.0000e+00, 9.0437e-12, 2.3268e-11, -5.5511e-17], [ 9.0437e-12, 1.0000e+00, 2.3924e-10, 0.0000e+00], [ 2.3268e-11, 2.3924e-10, 1.0000e+00, -2.2204e-16], [ 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00]])
Output xi value: tensor([-5.5511e-17, -2.6310e-26, -2.2204e-16, 2.3924e-10, 2.3268e-11, 9.0437e-12])
It should be the same as the start test matrix:
tensor([[ 1.0000e+00, -9.0437e-12, 2.3268e-11, -5.5511e-17], [ 9.0437e-12, 1.0000e+00, -2.3924e-10, 0.0000e+00], [-2.3268e-11, 2.3924e-10, 1.0000e+00, -2.2204e-16], [ 0.0000e+00, 0.0000e+00, 0.0000e+00, 1.0000e+00]])

As you can see, in Test 2, the element (3,1), (1,2) and (2,3) have wrong sign.

Update mask inversion inside torch/so3.py

I recently found two occurrences of this error, both in torch/so3.py:

Traceback (most recent call last):
File "", line 1, in
File "/home/ubuntu/.local/lib/python3.6/site-packages/liegroups/torch/se3.py", line 80, in exp
rot_jac = cls.RotationType.left_jacobian(phi)
File "/home/ubuntu/.local/lib/python3.6/site-packages/liegroups/torch/so3.py", line 187, in left_jacobian
#large_angle_mask = 1 - small_angle_mask # element-wise not
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/tensor.py", line 362, in rsub
return _C._VariableFunctions.rsub(self, other)
RuntimeError: Subtraction, the - operator, with a bool tensor is not supported. If you are trying to invert a mask, use the ~ or logical_not() operator instead.

I could verify locally that it is just a matter of doing what is suggested and it works fine.
P.S.: My pytorch version is 1.3

exp and log not invertible

This assertion fails.

import numpy as np
from liegroups import SO3
s = SO3.from_rpy(np.pi, 0, np.pi/2)
es = SO3.exp(s.log())
assert np.allclose(s.mat, es.mat)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.