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

Add the shirokov inverse #373

Merged
merged 14 commits into from
Jun 8, 2021
Merged

Conversation

hugohadfield
Copy link
Member

Does what it says on the tin, see #369

clifford/_layout.py Outdated Show resolved Hide resolved
clifford/_layout.py Outdated Show resolved Hide resolved
@hugohadfield
Copy link
Member Author

hugohadfield commented Dec 28, 2020

Thinking about numerical accuracy etc. I knocked up a quick comparison:

from clifford import Cl
import numpy as np

def measure_error(layout):
    rand_mv = layout.randomMV()
    unity = layout.scalar.value
    error_shirokov = np.linalg.norm(unity - (rand_mv*rand_mv.shirokov_inverse()).value)
    error_hitzer = np.linalg.norm(unity - (rand_mv*rand_mv.hitzer_inverse()).value)
    return error_shirokov, error_hitzer

for p in range(1, 6):
    layout, blades = Cl(p=p)
    error_shirokov, error_hitzer = zip(*[measure_error(layout) for i in range(200)])
    print('P: ', p)
    print('Shirokov', 'Hitzer')
    print(np.mean(error_shirokov), np.mean(error_hitzer))
    print(np.std(error_shirokov), np.std(error_hitzer))
    print()

Which produces

P:  1
Shirokov Hitzer
3.649271807406798e-16 3.649271807406798e-16
1.4566808659104976e-15 1.4566808659104976e-15

P:  2
Shirokov Hitzer
6.508691648288092e-16 6.508691648288092e-16
2.487589974051038e-15 2.487589974051038e-15

P:  3
Shirokov Hitzer
2.8485322231863833e-15 3.848218632954542e-16
1.813845517640471e-14 4.0117595566385547e-16

P:  4
Shirokov Hitzer
7.526109166859676e-16 4.448032513664149e-16
6.899802749548069e-16 3.8918760978280135e-16

P:  5
Shirokov Hitzer
1.7353364908081022e-14 1.7874116654496292e-14
7.064224091878557e-14 9.111388037030311e-14

Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

Flake8 is complaining because:

clifford/test/test_multivector_inverse.py Outdated Show resolved Hide resolved
clifford/test/test_multivector_inverse.py Outdated Show resolved Hide resolved
@eric-wieser
Copy link
Member

Well the new tests were all fast, but that's mainly because they all failed due to accuracy issues.

@hugohadfield
Copy link
Member Author

Well the new tests were all fast, but that's mainly because they all failed due to accuracy issues.

Yes indeed... any smart ideas for attempting to improve the accuracy? I had a brief look but made no headway

@eric-wieser
Copy link
Member

eric-wieser commented Dec 28, 2020

Well, the simple answer is "reduce the expected accuracy of the high-dimensional test". The failing ones are all very high dimensional:

FAILED clifford/test/test_multivector_inverse.py::TestClosedForm::test_shirokov_inverse[0-8-1]
FAILED clifford/test/test_multivector_inverse.py::TestClosedForm::test_shirokov_inverse[1-7-1]
FAILED clifford/test/test_multivector_inverse.py::TestClosedForm::test_shirokov_inverse[2-6-1]
FAILED clifford/test/test_multivector_inverse.py::TestClosedForm::test_shirokov_inverse[3-5-1]
FAILED clifford/test/test_multivector_inverse.py::TestClosedForm::test_shirokov_inverse[4-4-1]
FAILED clifford/test/test_multivector_inverse.py::TestClosedForm::test_shirokov_inverse[5-3-1]
FAILED clifford/test/test_multivector_inverse.py::TestClosedForm::test_shirokov_inverse[6-2-1]
FAILED clifford/test/test_multivector_inverse.py::TestClosedForm::test_shirokov_inverse[7-1-1]
FAILED clifford/test/test_multivector_inverse.py::TestClosedForm::test_shirokov_inverse[8-0-1]

@eric-wieser
Copy link
Member

Wait actually I think your tests is just bad. The higher dimensional your space, the more multivectors there are which are simply not invertible (and the closer you get to those, the more inaccurate your results are). The failures are all in the algebras with r=0 because in those algebras the spaces of non-invertible multivectors are much higher in dimension

Ck = (N / k) * Uk.value[0]
adjU = (Uk - Ck)
Uk = U * adjU
if Uk.value[0] == 0:
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I think that is a good point, perhaps this just needs to be some reasonable range about 0 then

@hugohadfield hugohadfield changed the title Add the shirokov inverse and make it the default Add the shirokov inverse and ~~make it the default~~ Mar 2, 2021
@hugohadfield hugohadfield changed the title Add the shirokov inverse and ~~make it the default~~ Add the shirokov inverse Mar 2, 2021
Comment on lines 15 to 17
* The default multivector inverse method is now the arbitrary signature algorithm described
in Theorem 4, page 16 of Dmitry Shirokov's ICCA 2020 paper :cite:`shirokov2020inverse`.
Copy link
Member

@eric-wieser eric-wieser Mar 3, 2021

Choose a reason for hiding this comment

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

Suggested change
* The default multivector inverse method is now the arbitrary signature algorithm described
in Theorem 4, page 16 of Dmitry Shirokov's ICCA 2020 paper :cite:`shirokov2020inverse`.
* A new multivector inverse method is available, :meth:`clifford.MultiVector.shirokov_inverse`,
which is the arbitrary signature algorithm described
in Theorem 4, page 16 of Dmitry Shirokov's ICCA 2020 paper :cite:`shirokov2020inverse`.

rtol=1E-5,
atol=1E-6)

@pytest.mark.parametrize('r', range(2))
@pytest.mark.parametrize('p, q', [
(p, total_dims - p)
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/pygae/clifford/pull/373/files#r549352578 still applies. At a guess:

Suggested change
(p, total_dims - p)
pytest.param(p, total_dims - p, marks=[pytest.mark.slow] if total_dims >= 6 else [])

@eric-wieser
Copy link
Member

Test failures are real at the moment; perhaps adjust the precision based on the dimension? Since it's all multiplication, I'd perhaps expect the number of digits of error to scale with the dimension of the algebra.

@hugohadfield
Copy link
Member Author

Build failure is unrelated... @eric-wieser shall we merge this thing finally?

@eric-wieser eric-wieser merged commit 8ad4913 into pygae:master Jun 8, 2021
@eric-wieser eric-wieser added this to the 1.4 release milestone Jul 19, 2021
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