CURVE SIMILARITY MEASUREMENT














































CURVE SIMILARITY MEASUREMENT



Untitled96

Curve Similarity MeasureMENT

Curves are: - discretized by inidviudal data points - ordered from a beginning to an ending

Curve similarity measurement based on it's length.

1.png

Curve similarity measurement based on it's area covered.

2.png

This means when two curves would appear directly on top of each other. Our measures of similarity would return a zero distance between two curves that were on top of each other.

installing similaritymeasures library

In [2]:
!pip install similaritymeasures

importing required libraries

In [3]:
import numpy as np
import similaritymeasures
import matplotlib.pyplot as plt

1. Curve similarity measurement based on it's length

First Example

Creating curve in the X-Y plane

In [4]:
# first curve having 5 points on the X-Y axis
fx1 = np.zeros((5, 2))
fx1[:, 0] = [1, 2, 3, 4, 5]
fx1[:, 1] = [1, 2, 3, 4, 5]

#second curve having 4 points on the X-Y axis
gx1 = np.zeros((4, 2))
gx1[:, 0] = [1, 2, 3, 4]
gx1[:, 1] = [1, 2, 3, 4]

fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(12,4))

axs[0].plot(fx1[:, 0], fx1[:, 1],  marker='o', linewidth=2)
axs[1].plot(gx1[:, 0], gx1[:, 1], color='red',  marker='o', linewidth=2)
Out[4]:
[<matplotlib.lines.Line2D at 0x27dcd5ea0c8>]
In [8]:
# quantify the difference between the two curves using
# Curve Length based similarity measure
curve_length = similaritymeasures.curve_length_measure(fx1, gx1)

# print the results
print("difference between first curve length and second curve length  is {}".format(curve_length))
difference between first curve length and second curve length  is 0.57047924843273
In [9]:
plt.plot(fx1[:, 0], fx1[:, 1], marker='o', linewidth=2)
plt.plot(gx1[:, 0], gx1[:, 1], marker='o', linewidth=2)
Out[9]:
[<matplotlib.lines.Line2D at 0x27dcd84c7c8>]

Second Example

In [10]:
# first curve having 5 points on the X-Y axis
fx2 = np.zeros((5, 2))
fx2[:, 0] = [1, 2, 3, 4, 5]
fx2[:, 1] = [1, 2, 3, 4, 5]

#second curve having 4 points on the X-Y axis
gx2 = np.zeros((4, 2))
gx2[:, 0] = [2, 4, 6, 8]
gx2[:, 1] = [3, 6, 9, 12]

fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(12,4))

axs[0].plot(fx2[:, 0], fx2[:, 1],  marker='o', linewidth=2)
axs[1].plot(gx2[:, 0], gx2[:, 1], color='red',  marker='o', linewidth=2)
Out[10]:
[<matplotlib.lines.Line2D at 0x27dcd93dec8>]
In [11]:
# quantify the difference between the two curves using
# Curve Length based similarity measure
curve_length = similaritymeasures.curve_length_measure(fx2, gx2)

# print the results
print("difference between first curve length and second curve length is {}".format(curve_length))
difference between first curve length and second curve length is 2.3644443270061015
In [12]:
plt.plot(fx2[:, 0], fx2[:, 1], marker='o', linewidth=2)
plt.plot(gx2[:, 0], gx2[:, 1], marker='o', linewidth=2)
Out[12]:
[<matplotlib.lines.Line2D at 0x27dcd9aae48>]

1. Curve similarity measurement based on it's area covered

applying similarity measures over first curves i.e over fx1 and gx1

In [13]:
# quantify the difference between the two curves using
# area between two curves
area = similaritymeasures.area_between_two_curves(fx1, gx1)

# print the results
print("difference between the two curve areas {}".format(area))
difference between the two curve areas 0.0
In [14]:
plt.plot(fx1[:, 0], fx1[:, 1], marker='o', linewidth=2)
plt.plot(gx1[:, 0], gx1[:, 1], marker='o', linewidth=2)
Out[14]:
[<matplotlib.lines.Line2D at 0x27dcda20b88>]

applying similarity measures over second curves i.e over fx2 and gx2

In [15]:
# quantify the difference between the two curves using
# Curve Length based similarity measure
area = similaritymeasures.area_between_two_curves(fx2, gx2)

# print the results
print("difference between the two curve areas {}".format(area))
difference between the two curve areas 9.5
In [16]:
plt.plot(fx2[:, 0], fx2[:, 1], marker='o', linewidth=2)
plt.plot(gx2[:, 0], gx2[:, 1], marker='o', linewidth=2)
Out[16]:
[<matplotlib.lines.Line2D at 0x27dcda7e208>]

More Articles of ML_coderzz unknown:

Name Views Likes
Facial Attribute Analysis 509 1
Generate QR Codes with Python and add Style 434 1
Create a simple chatbot in Python 226 1
Currency Converter using python 208 1
Pixel Level Image Comparison 1752 1
Neural Style Transfer With 2 Lines Of Code 341 1
Graph Based Text Representation 274 1
Semantic Segmentation With 2 Lines Of Code 336 1
Pose Estimation With 4 Lines Of Code 300 1
Question the Text and Summarize it 408 1
Cartooning an Image 247 1
Image to Sketch 245 1
Fine Tuning BERT for Text classification 569 1
Encoding-Decoding Text-to-Image 758 1
Create Pattern in Python 195 1
Spell Checker 419 1
Cropping Part of an image using OpenCV (grabcut algorithm) 1253 2
Transformers : All In One 449 1
Deep Convolutional GAN (DCGAN) 515 1
Spectral Normalization for Generative Adversarial Networks (SN-GAN) 712 1
ENGLISH DICTIONARY using PYTHON 357 2
GENDER CLASSIFICATION 590 1
India Air Quality Data Analysis 526 1
WINE QUALITY PREDICTION 1456 1
PREDICT NEXT N WORDS TO GENERATE COMPLETE SENTENCE 409 2
Denoising colored image 360 1
Print Emojis in Python 256 0
EMOTION DETECTION FROM TEXT 407 2
WORD EMBEDDING REPRESENTATION AND VISUALISATION (using GLOVE vector) 1016 2
Age Detection of Actors 1067 2
IMAGE CLASSIFICATION USING PRE-TRAINED MODEL 611 1
MNIST HANDWRITTEN DIGIT CLASSIFICATION (end to end project using TensorFlowJS) 668 2
IMAGE SIMILARITY USING SIAMESE NETWORK WITH TRIPLET LOSS 3199 1
CONDITIONAL GAN 1020 3
SIMILAR SENTENCE GENERATION 1533 1
TEXT TO SPEECH using gTTS 385 2
PLANT DISEASE CLASSIFICATION (end to end project) 745 1
WASSERSTEIN GAN WITH GRADIENT PENALTY (WGAN GP) 909 1
TRAFFIC SIGN CLASSIFICATION 721 1
K-MEANS CLUSTERING OVER IMAGES 1073 1
Hindi OCR 984 1
GENERATING HANDWRITTEN MNIST DIGITS USING GAN 461 0
CURVE SIMILARITY MEASUREMENT 3049 2
Stock Price Prediction and Forecasting using LSTM 1267 1
LANGUAGE TRANSLATION 603 2
FACIAL EXPRESSION RECOGNITION 684 1
FACE COUNTING (COUNT THE NUMBER OF FACES PRESENT IN AN IMAGE) 2183 2
Image Quality Assessment 3099 1
Text Extraction From An Image 1128 2
NAMED ENTITY RECOGNITION 532 2

Comments




























Curve Similarity MeasureMENT








Curves are: - discretized by inidviudal data points - ordered from a beginning to an ending









Curve similarity measurement based on it's length.









\"1.png\"









Curve similarity measurement based on it's area covered.









\"2.png\"









This means when two curves would appear directly on top of each other. Our measures of similarity would return a zero distance between two curves that were on top of each other.









installing similaritymeasures library








In [2]:



!pip install similaritymeasures




























importing required libraries








In [3]:



import numpy as np
import similaritymeasures
import matplotlib.pyplot as plt










1. Curve similarity measurement based on it's length








First Example









Creating curve in the X-Y plane








In [4]:



# first curve having 5 points on the X-Y axis
fx1 = np.zeros((5, 2))
fx1[:, 0] = [1, 2, 3, 4, 5]
fx1[:, 1] = [1, 2, 3, 4, 5]

#second curve having 4 points on the X-Y axis
gx1 = np.zeros((4, 2))
gx1[:, 0] = [1, 2, 3, 4]
gx1[:, 1] = [1, 2, 3, 4]

fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(12,4))

axs[0].plot(fx1[:, 0], fx1[:, 1], marker='o', linewidth=2)
axs[1].plot(gx1[:, 0], gx1[:, 1], color='red', marker='o', linewidth=2)












Out[4]:






[<matplotlib.lines.Line2D at 0x27dcd5ea0c8>]













\">










In [8]:



# quantify the difference between the two curves using
# Curve Length based similarity measure
curve_length = similaritymeasures.curve_length_measure(fx1, gx1)

# print the results
print(\"difference between first curve length and second curve length is {}\".format(curve_length))
















difference between first curve length and second curve length  is 0.57047924843273










In [9]:



plt.plot(fx1[:, 0], fx1[:, 1], marker='o', linewidth=2)
plt.plot(gx1[:, 0], gx1[:, 1], marker='o', linewidth=2)












Out[9]:






[<matplotlib.lines.Line2D at 0x27dcd84c7c8>]













\">











Second Example








In [10]:



# first curve having 5 points on the X-Y axis
fx2 = np.zeros((5, 2))
fx2[:, 0] = [1, 2, 3, 4, 5]
fx2[:, 1] = [1, 2, 3, 4, 5]

#second curve having 4 points on the X-Y axis
gx2 = np.zeros((4, 2))
gx2[:, 0] = [2, 4, 6, 8]
gx2[:, 1] = [3, 6, 9, 12]

fig, axs = plt.subplots(nrows=1, ncols=2, figsize=(12,4))

axs[0].plot(fx2[:, 0], fx2[:, 1], marker='o', linewidth=2)
axs[1].plot(gx2[:, 0], gx2[:, 1], color='red', marker='o', linewidth=2)












Out[10]:






[<matplotlib.lines.Line2D at 0x27dcd93dec8>]













\">










In [11]:



# quantify the difference between the two curves using
# Curve Length based similarity measure
curve_length = similaritymeasures.curve_length_measure(fx2, gx2)

# print the results
print(\"difference between first curve length and second curve length is {}\".format(curve_length))
















difference between first curve length and second curve length is 2.3644443270061015










In [12]:



plt.plot(fx2[:, 0], fx2[:, 1], marker='o', linewidth=2)
plt.plot(gx2[:, 0], gx2[:, 1], marker='o', linewidth=2)












Out[12]:






[<matplotlib.lines.Line2D at 0x27dcd9aae48>]













\">











1. Curve similarity measurement based on it's area covered








applying similarity measures over first curves i.e over fx1 and gx1








In [13]:



# quantify the difference between the two curves using
# area between two curves
area = similaritymeasures.area_between_two_curves(fx1, gx1)

# print the results
print(\"difference between the two curve areas {}\".format(area))
















difference between the two curve areas 0.0










In [14]:



plt.plot(fx1[:, 0], fx1[:, 1], marker='o', linewidth=2)
plt.plot(gx1[:, 0], gx1[:, 1], marker='o', linewidth=2)












Out[14]:






[<matplotlib.lines.Line2D at 0x27dcda20b88>]













\">











applying similarity measures over second curves i.e over fx2 and gx2








In [15]:



# quantify the difference between the two curves using
# Curve Length based similarity measure
area = similaritymeasures.area_between_two_curves(fx2, gx2)

# print the results
print(\"difference between the two curve areas {}\".format(area))
















difference between the two curve areas 9.5










In [16]:



plt.plot(fx2[:, 0], fx2[:, 1], marker='o', linewidth=2)
plt.plot(gx2[:, 0], gx2[:, 1], marker='o', linewidth=2)












Out[16]:






[<matplotlib.lines.Line2D at 0x27dcda7e208>]













\">









"; var editylink = ""; var editcategory = "13"; /*editheading = encodeURIComponent(editheading); editcontents = encodeURIComponent(editcontents); editarticle = encodeURIComponent(editarticle); window.alert(editheading); window.alert(editcontents); window.alert(editarticle);*/ editheading = escapeHtml(encodeURIComponent(editheading)); //editcontents = escapeHtml(editcontents); editarticle = escapeHtml(encodeURIComponent(editarticle)); editylink = escapeHtml(encodeURIComponent(editylink)); editheading = editheading.replaceAll("+","%2b"); editarticle = editarticle.replaceAll("+","%2b"); var form = $('
' + '' + /*'' +*/ '' + '' + '' + '
'); $('body').append(form); form.submit(); }