sigmas_test_samples.py 864 B

1234567891011121314151617181920212223242526272829303132333435
  1. '''
  2. generating a test case for sigmas in pallas field.
  3. the output in csv format: f,Sigma,sigma1,sigma2 respectively for 2-term approximation.
  4. '''
  5. from lottery import *
  6. import numpy as np
  7. SEP=','
  8. def calc_sigmas(f, Sigma):
  9. k=N_TERM
  10. x = (1-f)
  11. c = math.log(x)
  12. neg_c = -1*c
  13. sigmas = [(int((neg_c/Sigma)**i * (L/fact(i)))) for i in range(1, k+1)]
  14. return sigmas
  15. sigmas = calc_sigmas(0.5, 1000)
  16. assert(len(sigmas)==2)
  17. with open("pallas_unittests.csv", 'w') as file:
  18. buf = ''
  19. for f in np.arange(0.01, 0.99, 10):
  20. for total_stake in np.arange(100, 1000, 10):
  21. sigmas = calc_sigmas(f, total_stake)
  22. line=str(f) + SEP + \
  23. str(total_stake) + SEP + \
  24. '{:x}'.format(sigmas[0]) + SEP + \
  25. '{:x}'.format(sigmas[1]) + '\n'
  26. buf+=line
  27. file.write(buf)