Author: Not specified Language: python
Description: Not specified Timestamp: 2018-06-11 02:57:56 +0000
View raw paste Reply
  1. lambda_list = [0.05,0.07,0.08,0.09,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
  2. normal_mse_list=[]
  3. normal_mse_comp1_list = []
  4. normal_mse_comp2_list = []
  5. normal_mse_comp3_list = []
  6.  
  7. for l in lambda_list:
  8.     mse_list = []
  9.     mse_list_1 = []
  10.     mse_list_2 = []
  11.     mse_list_3 = []
  12.     s_1=0
  13.     s_2=0
  14.     s_3=0
  15.    
  16.     for i in range(N):
  17.         y = np.matmul(phi,np.transpose(x[i]))/(math.sqrt(alpha))
  18.         B = np.transpose(u)
  19.         matrix = np.matmul(phi,B)/(math.sqrt(alpha))
  20.         clf = linear_model.Lasso(alpha=l)
  21.         clf.fit(matrix,y)
  22.         a_hat = clf.coef_
  23.         s_hat = np.matmul(B,np.transpose(a_hat))
  24.        
  25.         #for i in range(N):
  26.         mse = (np.linalg.norm(s_hat - s[i])/np.linalg.norm(s[i]))**2
  27.         index = np.where(labels[i]==1)[0]
  28.         if index == 0: #component 1
  29.             mse_1 = mse
  30.             mse_list_1.append(mse_1)
  31.             s_1+=1
  32.         if index == 1:
  33.             mse_2 = mse
  34.             mse_list_2.append(mse_2)
  35.             s_2+=1
  36.         if index == 2:
  37.             mse_3 = mse
  38.             mse_list_3.append(mse_3)
  39.             s_3+=1
  40.         mse_list.append(mse)
  41.        
  42.     normal_mse = sum(mse_list)/float(len(mse_list))
  43.     normal_mse_comp1  = sum(mse_list_1)/float(len(mse_list_1))
  44.     normal_mse_comp2  = sum(mse_list_2)/float(len(mse_list_2))
  45.     normal_mse_comp3  = sum(mse_list_3)/float(len(mse_list_3))
  46.     normal_mse_list.append(normal_mse)
  47.     normal_mse_comp1_list.append(normal_mse_comp1)
  48.     normal_mse_comp2_list.append(normal_mse_comp2)
  49.     normal_mse_comp3_list.append(normal_mse_comp3)
View raw paste Reply