Curves are: - discretized by inidviudal data points - ordered from a beginning to an ending
Curve similarity measurement based on it's length.
Curve similarity measurement based on it's area covered.
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
!pip install similaritymeasures
importing required libraries
import numpy as np
import similaritymeasures
import matplotlib.pyplot as plt
First Example
Creating curve in the X-Y plane
# 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)
# 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))
plt.plot(fx1[:, 0], fx1[:, 1], marker='o', linewidth=2)
plt.plot(gx1[:, 0], gx1[:, 1], marker='o', linewidth=2)
Second Example
# 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)
# 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))
plt.plot(fx2[:, 0], fx2[:, 1], marker='o', linewidth=2)
plt.plot(gx2[:, 0], gx2[:, 1], marker='o', linewidth=2)
applying similarity measures over first curves i.e over fx1 and gx1
# 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))
plt.plot(fx1[:, 0], fx1[:, 1], marker='o', linewidth=2)
plt.plot(gx1[:, 0], gx1[:, 1], marker='o', linewidth=2)
applying similarity measures over second curves i.e over fx2 and gx2
# 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))
plt.plot(fx2[:, 0], fx2[:, 1], marker='o', linewidth=2)
plt.plot(gx2[:, 0], gx2[:, 1], marker='o', linewidth=2)
Comments