Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Group Members
- =============
- '''
- userids = ["Thormundur15","Ernir17"] # fill in this array with strings of usernames
- def mCp1(x,y):
- '''Return the Euclidean distance between x and y
- '''
- summ = 0.0
- for i in xrange(0, len(x)):
- summ = summ + (x[i] - y[i])**2
- summ = sqrt(summ)
- return float(round(summ,2))
- def mCp2(x, y):
- '''Return the Manhattan distance between x and y
- '''
- summ = 0.0
- for i in xrange(0, len(x)):
- summ = summ + abs(x[i] - y[i])
- return float(round(summ,2))
- def mCp3(x, y):
- '''Retun the Hamming distance between x and y
- '''
- summ = 0.0
- for i in xrange(0, len(x)):
- if x[i] != y[i]:
- summ += 1
- return summ
- def mCp4(x, y):
- '''Return the Levenshtein distance between x and y
- '''
- return mCp3(x, y)
- def mCp5(x, y):
- '''Return the rank distance of the matrices constructed from x and y
- '''
- return -1
- def mCp6(L):
- '''Check whether L satisfies the axiom of neighborliness w.r.t the Hamming distance
- '''
- if(len(L) == 1):
- return True
- for i in xrange(0, len(L)):
- foundit = False
- for j in xrange(0, len(L)):
- if(i == j and L[i][1] != L[j][1]):
- continue
- if 1 >= mCp3(L[i][0], L[j][0]):
- foundit = True
- if not foundit:
- return False
- return True
- def mCp7(L, J):
- '''Use the labeled points in L to label the points in J using the nearest neighbor in the Hamming distance
- '''
- values = []
- for i in xrange(0, len(J)):
- minLength = 100
- val = 100
- for j in xrange(0, len(L)):
- temp = mCp3(L[j][0], J[i])
- if(temp <= minLength):
- if minLength == temp:
- if L[j][1] < val:
- val = L[j][1]
- else:
- minLength = temp
- val = L[j][1]
- tempo = (J[i], val)
- values.append(tempo)
- return values
- def mCp8(L, J, k):
- '''Use the labeled points in L to label the points in J using the k nearest neighbors in the Hamming distance
- '''
- values = []
- for i in xrange(0, len(J)):
- valuesFori = []
- for j in xrange(0, len(L)):
- valuesFori.append([(L[j][1]), mCp3(L[j][0], J[i])])
- if(len(L) < k):
- k = len(L)
- counts = {}
- for j in xrange(0, k):
- if valuesFori[j][0] in counts:
- counts[valuesFori[j][0]] += 1
- else:
- counts[valuesFori[j][0]] = 1
- print(max(counts))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement