Last active
January 1, 2020 05:30
-
-
Save ilius/123888928b7a050392d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from math import log | |
''' | |
findMaxDisplace = lambda array: \ | |
max( | |
origIndex - sortedIndex \ | |
for sortedIndex, (origIndex, value) in \ | |
enumerate( | |
sorted( | |
enumerate(array), | |
key=lambda x: x[1], | |
) | |
) | |
) | |
''' | |
## MDR = Maximum Displace Ratio | |
findSortedRatio = lambda array: \ | |
max( | |
origIndex - sortedIndex \ | |
for sortedIndex, (origIndex, value) in \ | |
enumerate( | |
sorted( | |
enumerate(array), | |
key=lambda x: x[1], | |
) | |
) | |
)/float( | |
(len(array) - 1) ** 1.02 | |
) | |
if __name__=='__main__': | |
print '%8s %10s'%('length', 'avgSR') | |
tryTimes = 10000 | |
for length in xrange(100, 100000, 100): | |
array = list(range(length)) | |
#SR = 1 - MDR | |
sumSR = 0 | |
for _ in range(tryTimes): | |
random.shuffle(array) | |
sumSR += findSortedRatio(array) | |
avgSR = float(sumSR) / tryTimes | |
print '%8s %10.6f'%(length, avgSR) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment