Skip to content

Commit

Permalink
Merge pull request #184 from eternal-f1ame/master
Browse files Browse the repository at this point in the history
Updated distance_metrics.py
  • Loading branch information
kwanit1142 authored Oct 6, 2021
2 parents 3eab846 + 91e6937 commit 1cfea73
Showing 1 changed file with 69 additions and 15 deletions.
84 changes: 69 additions & 15 deletions MLlib/distance_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Distance_metrics:
Calculate distance between each corresponding points
of two arrays using different distance metrics
"""
def Eucledian_distance(self,X1,X2):
def Eucledian_Distance(X1,X2):
""""
Returns the list of eucledian distance
between two corresponding points of
Expand All @@ -18,13 +18,10 @@ def Eucledian_distance(self,X1,X2):
X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension
distance:list
list containing eucledian distance of points
RETURNS
=========
float
distance:list
Returns the list of eucledian distance
between two corresponding points of
two arrays
Expand All @@ -36,7 +33,7 @@ def Eucledian_distance(self,X1,X2):
distance.append(np.sqrt(single))
return(distance)

def Manhattan_distance(self,X1,X2):
def Manhattan_Distance(X1,X2):
""""
Returns the list of manhattan distance
between two corresponding points of
Expand All @@ -50,13 +47,10 @@ def Manhattan_distance(self,X1,X2):
X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension
distance:list
list containing manhattan distance of points
RETURNS
=========
float
distance:list
Returns the list of manhattan distance
between two corresponding points of
two arrays
Expand All @@ -68,7 +62,7 @@ def Manhattan_distance(self,X1,X2):
distance.append(single)
return(distance)

def Chebyshev_Distance(self,X1,X2):
def Chebyshev_Distance(X1,X2):
""""
Returns the list of chebyshev distance
between two corresponding points of
Expand All @@ -82,13 +76,10 @@ def Chebyshev_Distance(self,X1,X2):
X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension
distance:list
list containing chebyshev distance of points
RETURNS
=========
float
distance:list
Returns the list of chebyshev distance
between two corresponding points of
two arrays
Expand All @@ -100,7 +91,70 @@ def Chebyshev_Distance(self,X1,X2):
distance.append(single)
return(distance)

def Minkowski_Distance(X1,X2,p):
""""
Returns list of minkowski distance of order 'p'
between two corresponding vectors of
two arrays
PARAMETERS
==========
X1:ndarray(dtype=int,axis=1)
input array with more than 1 dimension
X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension
p:float
input order value between 1 and 2 inclusive
RETURNS
=========
distance:list
Returns the list of minkowski distance
between two corresponding vectors of
two arrays
"""
distance=[]
for i in range(len(X1)):
single=0
single=np.sum((abs(X1[i]-X2[i]))**p)
distance.append((single)**(1/p))
return(distance)

def WMinkowski_Distance(X1,X2,p,W):
""""
Returns list of weighted minkowski distance of order 'p'
between two corresponding vectors weighted by W of
two arrays
PARAMETERS
==========
X1:ndarray(dtype=int,axis=1)
input array with more than 1 dimension
X2:ndarray(dtype=int,axis=1)
input array with more than 1 dimension
p:float
input order value between 1 and 2 inclusive
W:array(dtype=int,axis=1)
input 1 dimensional array
RETURNS
=========
distance:list
Returns the list of weighted minkowski distance
between two corresponding vectors of
two arrays
"""
distance=[]
for i in range(len(X1)):
single=0
single=np.sum((abs(W*(X1[i]-X2[i])))**p)
distance.append((single)**(1/p))
return(distance)

0 comments on commit 1cfea73

Please sign in to comment.