Author: Not specified Language: python
Description: Not specified Timestamp: 2018-06-11 02:49:25 +0000
View raw paste Reply
  1. def draw_z():
  2.     return np.random.normal(mu_Z, sigma_Z, 2)
  3. def draw_noise():
  4.     return np.random.multivariate_normal(mu_noise, sigma_noise, 1)
  5. #Component 1
  6. def gen_component_1(u):
  7.     z = draw_z()
  8.     n = draw_noise()
  9.     X_1 = u[0] + z[0] * u[1] + z[1] * u[2] + n
  10.     return X_1
  11.  
  12. #Component 2
  13. def gen_component_2(u):
  14.     z = draw_z()
  15.     n = draw_noise()
  16.     X_2 = 2 * u[3] + math.sqrt(2) * z[0] * u[4] + z[1] * u[5] + n
  17.     return X_2
  18.  
  19. #Component 3
  20. def gen_component_3(u):
  21.     z = draw_z()
  22.     n = draw_noise()
  23.     X_3 = math.sqrt(2) * u[5] + z[0] * (u[0]+u[1]) + (1/math.sqrt(2)) * z[1] * u[4] + n
  24.     return X_3
  25.  
  26. N = 2000
  27. dataset = np.ndarray((N,D))
  28. labels = np.zeros((N,3))
  29. sample1_num = 0
  30. sample2_num = 0
  31. sample3_num = 0
  32. for i in range(N):
  33.     r = np.random.randint(0,3)
  34.     if r ==0:
  35.         sample1_num += 1
  36.         dataset[i,:]= gen_component_1(u)
  37.     elif r ==1:
  38.         sample2_num += 1
  39.         dataset[i,:]= gen_component_2(u)
  40.     elif r ==2:
  41.         sample3_num += 1
  42.         dataset[i,:]= gen_component_3(u)
  43.    
  44.     labels[i,r] =1
View raw paste Reply