main.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import math
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import random
  5. L = 28948022309329048855892746252171976963363056481941560715954676764349967630337
  6. def target(f, rel_stake):
  7. T = L * (1 - (1-f)**rel_stake)
  8. return T
  9. def approx_target(f, stake, Sigma):
  10. stake = int(stake)
  11. x = (1-f)
  12. c = math.log(x)
  13. k = L*c
  14. kp = k*c
  15. kpp = kp/2
  16. # approx sigma
  17. sigma_1 = -1 * k/Sigma
  18. sigma_2 = -1 * kpp/(Sigma**2)
  19. # sigma is in Z
  20. sigma_2 = int(sigma_2)
  21. sigma_1 = int(sigma_1)
  22. T = sigma_1 * stake + sigma_2*stake**2
  23. return T
  24. f = 0.5
  25. # let's assume stakeholde having 1% of the stake, 1/100.
  26. # each iteration increases stake by value 1.
  27. TOTAL = 10000
  28. S = []
  29. stake = 0
  30. T = []
  31. T_approx = []
  32. for i in range(TOTAL):
  33. if random.random()>=0.9:
  34. stake+=1
  35. S+=[(stake, i+1.0)]
  36. t = target(f, stake/(i+1.0))
  37. T+=[t]
  38. t_approx = approx_target(f, stake, (i+1.0))
  39. T_approx+=[t_approx]
  40. plt.plot(T)
  41. plt.plot(T_approx)
  42. plt.legend(["target", "approximation"])
  43. plt.savefig('plot.png')