Update statisticsFromHashes.py before trying not to round in any manner

This commit is contained in:
2023-05-02 23:16:34 +02:00
parent b2edfc7edd
commit c035ad130b

View File

@@ -18,8 +18,8 @@ with open('hashes.txt') as f:
target = lineParts[1]
hashDifficulty = getDifficultyOfHash(hash)
targetDifficulty = getDifficultyOfHash(target)
#difficultyRatio = targetDifficulty // hashDifficulty
difficultyRatio = int(math.log2(targetDifficulty / hashDifficulty))
# If use `round` instead of `int`, then it gives the same result as before.
difficultyRatio = round(math.log2(targetDifficulty / hashDifficulty))
if difficultyRatio in difficultyRatios:
difficultyRatios[difficultyRatio] += 1
else:
@@ -32,22 +32,16 @@ for i in range(max(difficultyRatios) + 1):
## To improve the readability:
#plt.semilogx(X, Y, base = 2)
XMain = [2 ** i for i in range(math.ceil(math.log2(X[-1])))]
XP = [0] + XMain + ([X[-1]] if not X[-1] in XMain else [])
YP = [difficultyRatios[difficultyRatio] / len(lines) for difficultyRatio in XP]
plt.scatter(X, Y)
plt.scatter(XP, YP)
plt.xticks(X, X)
plt.xticks(XP, XP)
upperBound = math.ceil(math.log2(X[-1])) + 2
YP = [2 ** -i for i in range(upperBound)]
YP = [2 ** -i for i in range(len(X))][:7]
plt.yticks(YP, YP)
for x, y in zip(X, Y):
if x == 0 or math.log2(x) == int(math.log2(x)):
if x <= 5:
plt.text(x, y, f'({x}, {round(y, 4)})', ha='center', va='top')
##
@@ -55,3 +49,17 @@ for x, y in zip(X, Y):
plt.plot(X, Y)
plt.show()
## To understand the difference between `int` and `round:`
import numpy as np
x = np.linspace(0, 10, 1000)
plt.plot(x, np.vectorize(int)(x), label = 'int')
plt.plot(x, np.vectorize(round)(x), label = 'round')
plt.legend(loc = 'upper left')
plt.show()