-
Notifications
You must be signed in to change notification settings - Fork 57
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 support for calculating the permanent using the BBFG algorithm #267
Conversation
…BFG algorithm and Gray code ordering (XanaduAI#263)
A brief discussion on new algorithms in My first implementation of BBFG algorithm is
Please, let me know what you think about further improvements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @maliasadi
Just a few questions and suggestions from my side.
Thank you @mlxd for the suggestions! New benchmark comparing permanent algorithms:
|
Hi @maliasadi, I'd be interested to see if there are any numerical accuracy differences between the Ryser and BBFG algorithms. I have a feeling that BBFG may perform better. The simplest test for this I can think of is that the permant of an n x n all-ones matrix, M, should give n!, so computing |perm(M) - n!| / n! for different n should be interesting. |
Hi @jakeffbulmer, although both Ryser and BBFG are among "exact" algorithms and not statistical, like Markov Chain Monte Carlo algorithm for calculating permanent, that's a very good concern. Thanks for the proposed test formula! I gave it a try with these algorithms and the results are as follows. It seems that your feeling is right :)
|
Codecov Report
@@ Coverage Diff @@
## master #267 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 1418 1419 +1
=========================================
+ Hits 1418 1419 +1
Continue to review full report at Codecov.
|
Thanks @maliasadi - that's exactly what I was hoping to see! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on this @maliasadi !
Nothing more to add on my side. We'll follow-up shortly.
Hey @maliasadi : could you also add your name here: https://github.com/XanaduAI/thewalrus/blob/master/.github/ACKNOWLEDGMENTS.md |
thewalrus/_permanent.py
Outdated
def perm(A, quad=True, fsum=False): | ||
"""Returns the permanent of a matrix via the | ||
`Ryser formula <https://en.wikipedia.org/wiki/Computing_the_permanent#Ryser_formula>`_. | ||
def perm(A, quad=True, fsum=False, method="ryser"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def perm(A, quad=True, fsum=False, method="ryser"): | |
def perm(A, quad=True, fsum=False, method="bbfg"): |
Thanks @maliasadi! |
indeed, really nice addition @maliasadi , aka commander of threads :) |
|
Context:
Currently, The Walrus uses the Ryser's formula to calculate permanents of arbitrary matrices that has time-complexity of O(n 2^n) if it's implemented with Gray code ordering. Another useful permanent algorithm with the same complexity is through BBFG's formula that's introduced by David G. Glynn in"The permanent of a square matrix". This pull request adds both C++ and Python support for permanent calculation using the latter formula.
Description of the Change:
./include/permanent.hpp
.perm_BBFG_qp
andperm_BBFG_cmplx
) and one for the future parallel vs. serial integration (perm_BBFG
)../tests/libwalrus_unittest.cpp
./thewalrus/libwalrus.pyx
./thewalrus/tests/test_permanent.py
for integrated python methods namingperm_BBFG
,perm_BBFG_real
andperm_BBFG_complex
.Benefits:
As @mlxd suggested, having both methods implemented will allow for performance and accuracy comparisons and trade-offs.
Possible Drawbacks:
Related GitHub Issues:
Issue #263 created by @mlxd