From c035ad130b4c1b4347121b26ca5cc72c94b880f8 Mon Sep 17 00:00:00 2001 From: Benjamin_Loison Date: Tue, 2 May 2023 23:16:34 +0200 Subject: [PATCH] Update `statisticsFromHashes.py` before trying not to round in any manner --- statisticsFromHashes.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/statisticsFromHashes.py b/statisticsFromHashes.py index c1d5780..5dffbfd 100644 --- a/statisticsFromHashes.py +++ b/statisticsFromHashes.py @@ -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() +