daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Dec 13th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''
  2. Group Members
  3. =============
  4. '''
  5.  
  6. userids = ["Thormundur15","Ernir17"] # fill in this array with strings of usernames
  7. def mCp1(x,y):
  8.     '''Return the Euclidean distance between x and y
  9.     '''
  10.     summ = 0.0
  11.     for i in xrange(0, len(x)):
  12.         summ = summ + (x[i] - y[i])**2
  13.     summ = sqrt(summ)
  14.     return float(round(summ,2))
  15.  
  16. def mCp2(x, y):
  17.     '''Return the Manhattan distance between x and y
  18.     '''
  19.     summ = 0.0
  20.     for i in xrange(0, len(x)):
  21.         summ = summ + abs(x[i] - y[i])
  22.    
  23.     return float(round(summ,2))
  24.  
  25. def mCp3(x, y):
  26.     '''Retun the Hamming distance between x and y
  27.     '''
  28.     summ = 0.0
  29.     for i in xrange(0, len(x)):
  30.         if x[i] != y[i]:
  31.             summ += 1
  32.     return summ
  33.  
  34. def mCp4(x, y):
  35.     '''Return the Levenshtein distance between x and y
  36.     '''
  37.     return mCp3(x, y)
  38.  
  39. def mCp5(x, y):
  40.     '''Return the rank distance of the matrices constructed from x and y
  41.     '''
  42.     return -1
  43.  
  44. def mCp6(L):
  45.     '''Check whether L satisfies the axiom of neighborliness w.r.t the Hamming distance
  46.     '''
  47.     if(len(L) == 1):
  48.         return True
  49.     for i in xrange(0, len(L)):
  50.         foundit = False
  51.         for j in xrange(0, len(L)):
  52.             if(i == j and L[i][1] != L[j][1]):
  53.                 continue
  54.                 if 1 >= mCp3(L[i][0], L[j][0]):
  55.                     foundit = True
  56.         if not foundit:
  57.             return False
  58.     return True
  59.  
  60. def mCp7(L, J):
  61.     '''Use the labeled points in L to label the points in J using the nearest neighbor in the Hamming distance
  62.     '''
  63.     values = []
  64.     for i in xrange(0, len(J)):
  65.         minLength = 100
  66.         val = 100
  67.         for j in xrange(0, len(L)):
  68.             temp = mCp3(L[j][0], J[i])
  69.             if(temp <= minLength):
  70.                 if minLength == temp:
  71.                     if L[j][1] < val:
  72.                         val = L[j][1]
  73.                 else:
  74.                     minLength = temp
  75.                     val = L[j][1]
  76.         tempo = (J[i], val)
  77.         values.append(tempo)
  78.     return values
  79.  
  80. def mCp8(L, J, k):
  81.     '''Use the labeled points in L to label the points in J using the k nearest neighbors in the Hamming distance
  82.     '''
  83.     values = []
  84.     for i in xrange(0, len(J)):
  85.         valuesFori = []
  86.         for j in xrange(0, len(L)):
  87.             valuesFori.append([(L[j][1]), mCp3(L[j][0], J[i])])
  88.         if(len(L) < k):
  89.             k = len(L)
  90.         counts = {}
  91.         for j in xrange(0, k):
  92.             if valuesFori[j][0] in counts:
  93.                 counts[valuesFori[j][0]] += 1
  94.             else:
  95.                 counts[valuesFori[j][0]] = 1
  96.         print(max(counts))
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