SHARE
TWEET

Untitled

a guest Oct 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import numpy as np
  2.  
  3. # parameters of Gaussian distribution
  4. mu = 1
  5. sigma = 1
  6. # dimensions
  7. d = 100
  8. k = 10
  9. # Gaussian matrix
  10. G = np.random.normal(mu, sigma, (k, d))
  11.  
  12. # isotropic vector on the unit sphere
  13. x = np.random.normal(mu, sigma, (d, 1))
  14. # L2 Norm of X
  15. l2NormX = np.sqrt(np.dot(np.transpose(x), x))
  16. # re-sample x if norm too small to avoid floating point errors due to finite precision
  17. while l2NormX < 0.001:
  18.     x = np.random.normal(mu, sigma, d)
  19.     l2NormX = np.sqrt(np.dot(np.transpose(x), x))
  20.  
  21. # normalize x
  22. x /= l2NormX
  23. # mapping function phi
  24. phi_x = 1 / np.sqrt(k) * np.matmul(G, x)  # matrix multiplication
  25. groundTruthValue = np.dot(np.transpose(x), x)[0][0]
  26. estimate = np.sqrt(np.dot(np.transpose(phi_x), phi_x))[0][0]
  27. print(groundTruthValue)
  28. print(estimate)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top