Arbitrary precision Mallows Model under Hamming distance + solved numpy float type deprecation bug #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
First of all thank you for your work! This package has been really useful to understand distance-based statistical models for permutations.
Arbitrary precision sampling for Mallows Model under Hamming distance
This PR implements arbitrary precision math (using the Python
mpmath
library) in the sampling of permutations using the Mallows Model under the Hamming distance. This makes it possible to sample from very long permutations without running into overflows of the built-in Python integer type, which result in 0s or NaNs appearing in the calculation of the number of permutations at large Hamming distances.I am working on large Traveling-Salesman-like problems (1000s of destinations) where it's interesting to sample around known "good" solutions (see RAAN walks in multi-target trajectory optimization for spacecraft), so this capability has been quite useful.
I have tested permutations of up to 5000 elements. Sampling 10000 permutations of 5000 elements takes approximately 1 minute. You can see the resulting distance histogram and the code used to generate it below.

As expected, the new

sample
function returns identical output to that of the original one for smaller permutations:Bug fix: Solved NumPy float type deprecation bug
This PR replaces
np.float
bynp.float64
in the code to solve the following Numpy deprecation error:Cheers!