original_docstring: 
      calculate performance measure for label ranking
      with normal ranking input y_pred and y_test, rankopt = True
      with votes for each label input y_pred and y_test (for LogR and NAIVE specifically), rankopt = False
      
docstring: calculate performance measure for label ranking
  with normal ranking input y_pred and y_test, rankopt = True
  with votes for each label input y_pred and y_test (for LogR and NAIVE specifically), rankopt = False
docstring_tokens: calculate performance measure for label ranking with normal ranking input y_pred and y_test rankopt = True with votes for each label input y_pred and y_test ( for LogR and NAIVE specifically ) rankopt = False
code: def perfMeasure(y_pred, y_test, rankopt = False):
      """
      calculate performance measure for label ranking
      with normal ranking input y_pred and y_test, rankopt = True
      with votes for each label input y_pred and y_test (for LogR and NAIVE specifically), rankopt = False
      """
      # performance measurement #
      # with background noise probability distribution
      if type(y_test)!= np.ndarray:
          y_test = np.array(y_test)
      Nsamp = y_test.shape[0]
      Nclass = y_test.shape[1]
  
      perf_list={"acc3":0, "dcg":1, "llh":2, "recall":3, "recallsub": 3+Nclass, "Nsc": 3+2*Nclass, "kld": 3 + 3*Nclass,
                 "g_mean":4+3*Nclass, "kendalltau": 5+3*Nclass,
                 "recallpair": 6+3*Nclass, "Nsp": 6+3*Nclass+Nclass*Nclass, "g_mean_pair": 6+3*Nclass+2*Nclass*Nclass}
      Nperf = max(perf_list.values())+1
      perf=[0 for i in range(Nperf)]
  
      if not rankopt:
          rank_test = map(rankOrder,y_test)
          rank_pred = map(rankOrder,y_pred)
      else:
          if type(y_test) == np.ndarray:
              rank_test = y_test.tolist()
          else:
              rank_test = y_test
          if type(y_pred) == np.ndarray:
              rank_pred = y_pred.tolist()
          else:
              rank_pred = y_pred
  
      # acc3 #
      if Nclass>=3:
          for i in range(Nsamp):
              acc3 = 1
              for j in range(3):
                  if rank_test[i][j]>=0 and rank_pred[i][j]>=0 and rank_test[i][j]!=rank_pred[i][j]:
                      acc3 = 0
              perf[perf_list["acc3"]] += acc3
          perf[perf_list["acc3"]]=perf[perf_list["acc3"]]/(1.0*Nsamp)
      else:
          print "cannot calculate acc@3 for less than 3 classes"
  
      # recall #
      recall = map(recallAll, itertools.izip(rank_pred, rank_test))
      recall = np.array(recall)
      recall = np.mean(recall, axis=0)
      for i in range(Nclass):
          perf[perf_list["recall"] + i] = recall[i]
  
      # recallsub #
      recall_sub, Nsamp_class = recallSub(rank_pred, rank_test)
      for i in range(Nclass):
          perf[perf_list["recallsub"] + i] = recall_sub[i]
          perf[perf_list["Nsc"] + i] = Nsamp_class[i]
  
      # recallpair #
      recall_pair, Nsamp_pair = recallPair(rank_pred, rank_test)
      cnt = 0
      for i in range(Nclass):
          for j in range(Nclass):
              perf[perf_list["recallpair"] + cnt] =recall_pair[i][j]
              perf[perf_list["Nsp"] + cnt] = Nsamp_pair[i][j]
              cnt += 1
  
      # G-Mean-pair #
      recall_pair = np.array(recall_pair)
      recall_pair_masked = np.ma.masked_invalid(recall_pair)
      g_mean_pair = gmean(recall_pair_masked, axis=None)
      perf[perf_list["g_mean_pair"]] = g_mean_pair
  
      # G-Mean #
      recall_sub = np.array(recall_sub)
      recall_sub_masked = np.ma.masked_invalid(recall_sub)
      g_mean = gmean(recall_sub_masked)
      # g_mean = gmean(recall)
      perf[perf_list["g_mean"]] = g_mean
  
      # Kendall's Tau traditional one#
      perf[perf_list["kendalltau"]] = KendallTau(rank_pred, rank_test)
      # #
      if rankopt:
          return perf
  
      # --------------- for probability output ------------------------ #
      # llh (log-likelihood)#
      y_pred_noise=addNoise(y_pred)# add noise prior
      # y_pred_noise = y_pred
      for i in range(Nsamp):
          llh = 0
          for j in range(Nclass):
              if y_test[i][j]==0:
                  maxllh=0
              else:
                  maxllh=y_test[i][j]*math.log(y_test[i][j])
              llh += (y_test[i][j]*math.log(y_pred_noise[i][j])-maxllh)
          try:
              llh = llh + sum(y_test[i])*math.log(sum(y_test[i]))
          except ValueError, e:
              print y_test[i]
              raise e
          perf[perf_list["llh"]] += llh
      perf[perf_list["kld"]] = perf[perf_list["llh"]]/(1.0*np.sum(y_test)) ## normalized by total emoticons
      perf[perf_list["llh"]]=perf[perf_list["llh"]]/(1.0*Nsamp) ## normalized by # samples
  
      # dcg #
      for i in range(Nsamp):
          dcg = 0
          maxdcg = 0
          for j in range(Nclass):
              if rank_pred[i][j]>=0:
                  dcg += y_test[i][rank_pred[i][j]]/math.log(j+2)
              if rank_test[i][j]>=0:
                  maxdcg += y_test[i][rank_test[i][j]]/math.log(j+2)
          perf[perf_list["dcg"]] += dcg*1.0/maxdcg
      perf[perf_list["dcg"]]= perf[perf_list["dcg"]] /(1.0*Nsamp)
  
      return perf
code_tokens: def perfMeasure ( y_pred , y_test , rankopt = False ) : if type ( y_test ) != np . ndarray : y_test = np . array ( y_test ) Nsamp = y_test . shape [ 0 ] Nclass = y_test . shape [ 1 ] perf_list = { "acc3" : 0 , "dcg" : 1 , "llh" : 2 , "recall" : 3 , "recallsub" : 3 + Nclass , "Nsc" : 3 + 2 * Nclass , "kld" : 3 + 3 * Nclass , "g_mean" : 4 + 3 * Nclass , "kendalltau" : 5 + 3 * Nclass , "recallpair" : 6 + 3 * Nclass , "Nsp" : 6 + 3 * Nclass + Nclass * Nclass , "g_mean_pair" : 6 + 3 * Nclass + 2 * Nclass * Nclass } Nperf = max ( perf_list . values ( ) ) + 1 perf = [ 0 for i in range ( Nperf ) ] if not rankopt : rank_test = map ( rankOrder , y_test ) rank_pred = map ( rankOrder , y_pred ) else : if type ( y_test ) == np . ndarray : rank_test = y_test . tolist ( ) else : rank_test = y_test if type ( y_pred ) == np . ndarray : rank_pred = y_pred . tolist ( ) else : rank_pred = y_pred if Nclass >= 3 : for i in range ( Nsamp ) : acc3 = 1 for j in range ( 3 ) : if rank_test [ i ] [ j ] >= 0 and rank_pred [ i ] [ j ] >= 0 and rank_test [ i ] [ j ] != rank_pred [ i ] [ j ] : acc3 = 0 perf [ perf_list [ "acc3" ] ] += acc3 perf [ perf_list [ "acc3" ] ] = perf [ perf_list [ "acc3" ] ] / ( 1.0 * Nsamp ) else : print "cannot calculate acc@3 for less than 3 classes" recall = map ( recallAll , itertools . izip ( rank_pred , rank_test ) ) recall = np . array ( recall ) recall = np . mean ( recall , axis = 0 ) for i in range ( Nclass ) : perf [ perf_list [ "recall" ] + i ] = recall [ i ] recall_sub , Nsamp_class = recallSub ( rank_pred , rank_test ) for i in range ( Nclass ) : perf [ perf_list [ "recallsub" ] + i ] = recall_sub [ i ] perf [ perf_list [ "Nsc" ] + i ] = Nsamp_class [ i ] recall_pair , Nsamp_pair = recallPair ( rank_pred , rank_test ) cnt = 0 for i in range ( Nclass ) : for j in range ( Nclass ) : perf [ perf_list [ "recallpair" ] + cnt ] = recall_pair [ i ] [ j ] perf [ perf_list [ "Nsp" ] + cnt ] = Nsamp_pair [ i ] [ j ] cnt += 1 recall_pair = np . array ( recall_pair ) recall_pair_masked = np . ma . masked_invalid ( recall_pair ) g_mean_pair = gmean ( recall_pair_masked , axis = None ) perf [ perf_list [ "g_mean_pair" ] ] = g_mean_pair recall_sub = np . array ( recall_sub ) recall_sub_masked = np . ma . masked_invalid ( recall_sub ) g_mean = gmean ( recall_sub_masked ) perf [ perf_list [ "g_mean" ] ] = g_mean perf [ perf_list [ "kendalltau" ] ] = KendallTau ( rank_pred , rank_test ) if rankopt : return perf y_pred_noise = addNoise ( y_pred ) for i in range ( Nsamp ) : llh = 0 for j in range ( Nclass ) : if y_test [ i ] [ j ] == 0 : maxllh = 0 else : maxllh = y_test [ i ] [ j ] * math . log ( y_test [ i ] [ j ] ) llh += ( y_test [ i ] [ j ] * math . log ( y_pred_noise [ i ] [ j ] ) - maxllh ) try : llh = llh + sum ( y_test [ i ] ) * math . log ( sum ( y_test [ i ] ) ) except ValueError , e : print y_test [ i ] raise e perf [ perf_list [ "llh" ] ] += llh perf [ perf_list [ "kld" ] ] = perf [ perf_list [ "llh" ] ] / ( 1.0 * np . sum ( y_test ) ) perf [ perf_list [ "llh" ] ] = perf [ perf_list [ "llh" ] ] / ( 1.0 * Nsamp ) for i in range ( Nsamp ) : dcg = 0 maxdcg = 0 for j in range ( Nclass ) : if rank_pred [ i ] [ j ] >= 0 : dcg += y_test [ i ] [ rank_pred [ i ] [ j ] ] / math . log ( j + 2 ) if rank_test [ i ] [ j ] >= 0 : maxdcg += y_test [ i ] [ rank_test [ i ] [ j ] ] / math . log ( j + 2 ) perf [ perf_list [ "dcg" ] ] += dcg * 1.0 / maxdcg perf [ perf_list [ "dcg" ] ] = perf [ perf_list [ "dcg" ] ] / ( 1.0 * Nsamp ) return perf
short_docstring: calculate performance measure for label ranking
  with normal ranking input y_pred and y_test, rankopt = True
  with votes for each label input y_pred and y_test (for LogR and NAIVE specifically), rankopt = False
short_docstring_tokens: calculate performance measure for label ranking with normal ranking input y_pred and y_test rankopt = True with votes for each label input y_pred and y_test ( for LogR and NAIVE specifically ) rankopt = False
comment: """
      calculate performance measure for label ranking
      with normal ranking input y_pred and y_test, rankopt = True
      with votes for each label input y_pred and y_test (for LogR and NAIVE specifically), rankopt = False
      """$SEP$# performance measurement #$SEP$# with background noise probability distribution$SEP$# acc3 #$SEP$# recall #$SEP$# recallsub #$SEP$# recallpair #$SEP$# G-Mean-pair #$SEP$# G-Mean #$SEP$# g_mean = gmean(recall)$SEP$# Kendall's Tau traditional one#$SEP$# #$SEP$# --------------- for probability output ------------------------ #$SEP$# llh (log-likelihood)#$SEP$# add noise prior$SEP$# y_pred_noise = y_pred$SEP$## normalized by total emoticons$SEP$## normalized by # samples$SEP$# dcg #