Author: Not specified Language: python Description: Not specified Timestamp: 2018-06-11 02:47:24 +0000
1. import numpy as np
2. import random
3. import math
4. import matplotlib.pyplot as plt
5. D = 100
6. J = 7
7. p_1 = 2/3.0
8. p_2 = 1/6.0
9. p_3 = 1/6.0
10. u = np.ndarray((J,D))
11. angles = np.zeros((J,J))
12. deviation = 10
13. mu_Z = 0
14. sigma_Z = 1
15. mu_noise = np.zeros(D)
16. sigma_noise = 0.01*np.identity(D)
17. def draw_vector(D):
18.     u = np.zeros(D)
19.     for i in range(D):
20.         r_num = random.random()
21.         if r_num > 0 and r_num <= p_1:
22.             u[i] = 0
23.             continue
24.         if r_num > p_1 and r_num <= p_1+p_2:
25.             u[i] = 1
26.             continue
27.         if r_num > p_1+p_2 and r_num <= 1:
28.             u[i] = -1
29.             continue
30.     return u
31. u = np.zeros((J,D))
32. for j in range(J):
33.     u[j] = draw_vector(D)
34.
35. for i in range(J):
36.     u[i] = draw_vector(D)
37.     for k in range(i):
38.         dot_product = np.dot(u[i] , u[k])
39.         if ((dot_product) <= 7 and (dot_product == 0)):
40.             i = i+1
41.             break