Advertisement
Guest User

Untitled

a guest
May 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import numpy as np
  2.  
  3. # Utilities
  4. def gen_iid_truncated_normal_utils(n, mean, var):
  5. pass
  6.  
  7. def gen_iid_scaled_beta_utils(n=1000, a=1, b=1, low=-1, high=1):
  8. return np.random.beta(a, b, size=n) * (high-low) + low
  9.  
  10. def gen_iid_uniform_utils(n, low=-1, high=1):
  11. return np.random.random(size=n) * (high-low) + low
  12.  
  13. # Gammas
  14. def gen_uniform_gamma(n):
  15. # Generate a single uniform distribution
  16. x = np.random.random(size=n)
  17. return x / x.sum()
  18.  
  19. def gen_normed_beta_gamma(n, a=1, b=1):
  20. # Generate a single beta normed distribution
  21. x = np.random.beta(a, b, size=n)
  22. return x / x.sum()
  23.  
  24. def gen_uniform_gamma_cb(n, ut, s):
  25. # Generate a single cost bounded uniform distribution
  26. # Calculate the E[C(A)]
  27. # while E[C(A)] > S:
  28. # D = E[C(A)] - S
  29. # Increase utility of each element of x by D
  30. # Renormalize x
  31. # return x
  32. x = np.random.random(size=n)
  33. x = x / x.sum()
  34. E_cost = np.dot(x, ut)
  35. print "E_cost: %s, s: %s" % (E_cost, s)
  36. while E_cost > s:
  37. diff = E_cost - s
  38. for i, g in enumerate(x):
  39. delta = diff / ut[i]
  40. x[i] += delta
  41. x = x / x.sum()
  42. return x
  43.  
  44. # def gen_normed_beta_gamma_cb(n, ut, a=1, b=1):
  45. # # Generate a single beta normed distribution
  46. # x = np.random.beta(a, b, size=n)
  47. # return x / x.sum()
  48.  
  49. # Lists
  50. def generate_utils_list(n):
  51. uts = []
  52. uts += [gen_iid_scaled_beta_utils(n).tolist()]
  53. uts += [gen_iid_scaled_beta_utils(n, a=10, b=10).tolist()]
  54. uts += [gen_iid_scaled_beta_utils(n, a=10).tolist()]
  55. return uts
  56.  
  57. def generate_gamma_list(n):
  58. # Generate list of gamma distributions
  59. gs = []
  60. gs += [gen_uniform_gamma(n).tolist()]
  61. gs += [gen_normed_beta_gamma(n, a=3).tolist()]
  62. return gs
  63.  
  64. def generate_gamma_list_ut(n, ut, s):
  65. # Generate list of gamma distributions
  66. # number of worlds, utility, cost bound
  67. gs = []
  68. gs += [gen_uniform_gamma_cb(n, ut, s).tolist()]
  69. # gs += [gen_normed_beta_gamma_cb(n, ut, a=3, s).tolist()]
  70. gs += [gen_normed_beta_gamma(n, a=3).tolist()]
  71. return gs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement