From db1fd2a6550692c41cd77f66fb2509412f124b7c Mon Sep 17 00:00:00 2001 From: Michael Shields Date: Thu, 7 Apr 2022 19:27:09 -0400 Subject: [PATCH 1/2] Changes to the Distance module --- .../distances/euclidean_distances.rst | 62 +++++++++++++++++-- .../utilities/distances/baseclass/Distance.py | 6 +- .../distances/baseclass/EuclideanDistance.py | 2 +- .../euclidean_distances/BrayCurtisDistance.py | 8 +++ .../euclidean_distances/CanberraDistance.py | 8 +++ .../euclidean_distances/ChebyshevDistance.py | 7 +++ .../euclidean_distances/CityBlockDistance.py | 8 +++ .../utilities/kernels/baseclass/Kernel.py | 2 +- 8 files changed, 93 insertions(+), 10 deletions(-) diff --git a/docs/source/utilities/distances/euclidean_distances.rst b/docs/source/utilities/distances/euclidean_distances.rst index bf677dae9..a444229d9 100644 --- a/docs/source/utilities/distances/euclidean_distances.rst +++ b/docs/source/utilities/distances/euclidean_distances.rst @@ -12,58 +12,108 @@ It allows the user to define a set of methods that must be created within any ch .. autoclass:: UQpy.utilities.distances.baseclass.EuclideanDistance :members: calculate_distance_matrix -All the distances classes below are wrappers around the :py:mod:`scipy.spatial.distance` module, written in an -object-oriented fashion to fit the needs of :py:mod:`UQpy.dimension_reduction` module. +List of Available Distances +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +All the distances classes below are subclasses of the :class:`.EuclideanDistance` class. Bray-Curtis Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The Bray-Curtis distance between two 1D arrays, `x` and `y`, is given by: + +.. math:: d(x,y) = \dfrac{\sum_i |x_i - y_i|}{\sum_i |x_i + y_i|} + The :class:`.BrayCurtisDistance` class is imported using the following command: >>> from UQpy.utilities.distances.euclidean_distances.BrayCurtisDistance import BrayCurtisDistance -One can use the following command to instantiate the class :class:`.BrayCurtisDistance` +Methods +~~~~~~~~~~ + +One can use the following command to instantiate the :class:`.BrayCurtisDistance` class. .. autoclass:: UQpy.utilities.distances.euclidean_distances.BrayCurtisDistance :members: +Attributes +~~~~~~~~~~ + +.. autoattribute:: UQpy.utilities.distances.BrayCurtisDistance.distance_matrix + Canberra Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The Canberra distance between two 1D arrays, `x` and `y`, is given by: + +.. math:: d(x,y) = \sum_i \dfrac{|x_i - y_i|}{|x_i| + |y_i|} + The :class:`.CanberraDistance` class is imported using the following command: >>> from UQpy.utilities.distances.euclidean_distances.CanberraDistance import CanberraDistance -One can use the following command to instantiate the class :class:`.CanberraDistance` +Methods +~~~~~~~~~~ + +One can use the following command to instantiate the :class:`.CanberraDistance` class. .. autoclass:: UQpy.utilities.distances.euclidean_distances.CanberraDistance :members: +Attributes +~~~~~~~~~~ + +.. autoattribute:: UQpy.utilities.distances.CanberraDistance.distance_matrix + Chebyshev Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The Chebyshev distance between two 1D arrays, `x` and `y`, is given by: + +.. math:: d(x,y) = \max_i |x_i-y_i| + The :class:`.ChebyshevDistance` class is imported using the following command: >>> from UQpy.utilities.distances.euclidean_distances.ChebyshevDistance import ChebyshevDistance -One can use the following command to instantiate the class :class:`.ChebyshevDistance` +Methods +~~~~~~~~~~ + +One can use the following command to instantiate the :class:`.ChebyshevDistance` class: .. autoclass:: UQpy.utilities.distances.euclidean_distances.ChebyshevDistance :members: +Attributes +~~~~~~~~~~ + +.. autoattribute:: UQpy.utilities.distances.ChebyshevDistance.distance_matrix + CityBlock Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The Canberra distance between two 1D arrays, `x` and `y`, is given by: + +.. math:: d(x,y) = \sum_i |x_i - y_i| + The :class:`.CityBlockDistance` class is imported using the following command: >>> from UQpy.utilities.distances.euclidean_distances.CityBlockDistance import CityBlockDistance -One can use the following command to instantiate the class :class:`.CityBlockDistance` +Methods +~~~~~~~~~~ + +One can use the following command to instantiate the :class:`.CityBlockDistance` class .. autoclass:: UQpy.utilities.distances.euclidean_distances.CityBlockDistance :members: +Attributes +~~~~~~~~~~ + +.. autoattribute:: UQpy.utilities.distances.CityBlockDistance.distance_matrix + Correlation Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/UQpy/utilities/distances/baseclass/Distance.py b/src/UQpy/utilities/distances/baseclass/Distance.py index 8acfdb761..aac9f345e 100644 --- a/src/UQpy/utilities/distances/baseclass/Distance.py +++ b/src/UQpy/utilities/distances/baseclass/Distance.py @@ -7,7 +7,9 @@ class Distance(ABC): """ - This class serves as a baseclass under which the distance implementations for all spaces exist. + This is the baseclass for all distances in :py:mod:`UQpy`. + + This serves as a blueprint to show the methods for distances implemented in the :py:mod:`.distances` module . """ def calculate_distance_matrix(self, points): @@ -22,7 +24,7 @@ def calculate_distance_matrix(self, points): @abstractmethod def compute_distance(self, xi, xj) -> float: """ - Given a two points, this method calculates their distance. Each concrete distance implementation + Given two points, this method calculates their distance. Each concrete distance implementation must override this method and provide its own implementation. :param xi: First point. diff --git a/src/UQpy/utilities/distances/baseclass/EuclideanDistance.py b/src/UQpy/utilities/distances/baseclass/EuclideanDistance.py index 3e690d674..513459be5 100644 --- a/src/UQpy/utilities/distances/baseclass/EuclideanDistance.py +++ b/src/UQpy/utilities/distances/baseclass/EuclideanDistance.py @@ -13,7 +13,7 @@ class EuclideanDistance(Distance, ABC): @beartype def calculate_distance_matrix(self, points: list[NumpyFloatArray]): """ - Given a list of cartesian points calculates a matrix that contains the distances between them. + Given a list of cartesian points, calculates a matrix that contains the distances between them. :param points: A list of cartesian points. :return: :class:`.ndarray` diff --git a/src/UQpy/utilities/distances/euclidean_distances/BrayCurtisDistance.py b/src/UQpy/utilities/distances/euclidean_distances/BrayCurtisDistance.py index 1caf725ff..516c2975b 100644 --- a/src/UQpy/utilities/distances/euclidean_distances/BrayCurtisDistance.py +++ b/src/UQpy/utilities/distances/euclidean_distances/BrayCurtisDistance.py @@ -7,4 +7,12 @@ class BrayCurtisDistance(EuclideanDistance): def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: + """ + Given two points, this method calculates the Bray-Curtis distance. + + :param xi: First point. + :param xj: Second point. + :return: A float representing the distance between the points. + """ + return pdist([xi, xj], "braycurtis")[0] \ No newline at end of file diff --git a/src/UQpy/utilities/distances/euclidean_distances/CanberraDistance.py b/src/UQpy/utilities/distances/euclidean_distances/CanberraDistance.py index 248dbbc5f..703ea78ac 100644 --- a/src/UQpy/utilities/distances/euclidean_distances/CanberraDistance.py +++ b/src/UQpy/utilities/distances/euclidean_distances/CanberraDistance.py @@ -8,4 +8,12 @@ class CanberraDistance(EuclideanDistance): def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: + """ + Given two points, this method calculates the Canberra distance. + + :param xi: First point. + :param xj: Second point. + :return: A float representing the distance between the points. + """ + return pdist([xi, xj], "canberra")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/ChebyshevDistance.py b/src/UQpy/utilities/distances/euclidean_distances/ChebyshevDistance.py index 1bdb360fc..c98350ed8 100644 --- a/src/UQpy/utilities/distances/euclidean_distances/ChebyshevDistance.py +++ b/src/UQpy/utilities/distances/euclidean_distances/ChebyshevDistance.py @@ -8,4 +8,11 @@ class ChebyshevDistance(EuclideanDistance): def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: + """ + Given two points, this method calculates the Chebyshev distance. + + :param xi: First point. + :param xj: Second point. + :return: A float representing the distance between the points. + """ return pdist([xi, xj], "chebyshev")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/CityBlockDistance.py b/src/UQpy/utilities/distances/euclidean_distances/CityBlockDistance.py index 8945895a4..4db48527a 100644 --- a/src/UQpy/utilities/distances/euclidean_distances/CityBlockDistance.py +++ b/src/UQpy/utilities/distances/euclidean_distances/CityBlockDistance.py @@ -8,4 +8,12 @@ class CityBlockDistance(EuclideanDistance): def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: + """ + Given two points, this method calculates the City Block (Manhattan) distance. + + :param xi: First point. + :param xj: Second point. + :return: A float representing the distance between the points. + """ + return pdist([xi, xj], "cityblock")[0] diff --git a/src/UQpy/utilities/kernels/baseclass/Kernel.py b/src/UQpy/utilities/kernels/baseclass/Kernel.py index 44cecde0f..f24fd78ce 100644 --- a/src/UQpy/utilities/kernels/baseclass/Kernel.py +++ b/src/UQpy/utilities/kernels/baseclass/Kernel.py @@ -12,7 +12,7 @@ class Kernel(ABC): """ This is the baseclass for all kernels in :py:mod:`UQpy`. - This serves a blueprint to show the methods for kernels implemented in the :py:mod:`.kernels` module . + This serves as a blueprint to show the methods for kernels implemented in the :py:mod:`.kernels` module . """ def __init__(self): self.kernel_matrix: np.ndarray = None From a275ac7c1f12aa94d3c108dd0996344606441d99 Mon Sep 17 00:00:00 2001 From: Michael Shields Date: Thu, 7 Apr 2022 20:34:17 -0400 Subject: [PATCH 2/2] Changes to the Distance module --- .../distances/euclidean_distances.rst | 252 +++--------------- .../CorrelationDistance.py | 7 + .../euclidean_distances/CosineDistance.py | 8 + .../euclidean_distances/DiceDistance.py | 11 - .../euclidean_distances/EuclideanDistance.py | 8 + .../euclidean_distances/HammingDistance.py | 11 - .../euclidean_distances/JaccardDistance.py | 11 - .../JensenShannonDistance.py | 11 - .../euclidean_distances/KulczynskiDistance.py | 11 - .../euclidean_distances/KulsinkiDistance.py | 11 - .../MahalanobisDistance.py | 11 - .../euclidean_distances/MatchingDistance.py | 11 - .../euclidean_distances/MinkowskiDistance.py | 13 +- .../RogersTanimotoDistance.py | 11 - .../euclidean_distances/RussellRaoDistance.py | 11 - .../SokalMichenerDistance.py | 11 - .../SokalSneathDistance.py | 11 - .../SquaredEuclideanDistance.py | 11 - .../StandardizedEuclidean.py | 11 - .../euclidean_distances/YuleDistance.py | 11 - .../distances/euclidean_distances/__init__.py | 15 -- 21 files changed, 79 insertions(+), 389 deletions(-) delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/DiceDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/HammingDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/JaccardDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/JensenShannonDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/KulczynskiDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/KulsinkiDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/MahalanobisDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/MatchingDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/RogersTanimotoDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/RussellRaoDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/SokalMichenerDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/SokalSneathDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/SquaredEuclideanDistance.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/StandardizedEuclidean.py delete mode 100644 src/UQpy/utilities/distances/euclidean_distances/YuleDistance.py diff --git a/docs/source/utilities/distances/euclidean_distances.rst b/docs/source/utilities/distances/euclidean_distances.rst index dbee76cc5..034cc66e4 100644 --- a/docs/source/utilities/distances/euclidean_distances.rst +++ b/docs/source/utilities/distances/euclidean_distances.rst @@ -93,7 +93,7 @@ Attributes CityBlock Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -The Canberra distance between two 1D arrays, `x` and `y`, is given by: +The City Block (Manhattan) distance between two 1D arrays, `x` and `y`, is given by: .. math:: d(x,y) = \sum_i |x_i - y_i| @@ -117,266 +117,102 @@ Attributes Correlation Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The Correlation distance between two 1D arrays, `x` and `y`, is given by: + +.. math:: d(x,y) = 1 - \dfrac{(x-\bar{x})\cdot(y-\bar{y})}{||x-\bar{x}||_2||y-\bar{y}||_2} + +where :math:`\bar{x}` denotes the mean of the elements of :math:`x` and :math:`x\cdot y` denotes the dot product. + The :class:`.CorrelationDistance` class is imported using the following command: >>> from UQpy.utilities.distances.euclidean_distances.CorrelationDistance import CorrelationDistance +Methods +~~~~~~~~~~ + One can use the following command to instantiate the class :class:`.CorrelationDistance` .. autoclass:: UQpy.utilities.distances.euclidean_distances.CorrelationDistance :members: +Attributes +~~~~~~~~~~ + .. autoattribute:: UQpy.utilities.distances.euclidean_distances.CorrelationDistance.distance_matrix Cosine Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The Cosine distance between two 1D arrays, `x` and `y`, is given by: + +.. math:: d(x,y) = 1 - \dfrac{x\cdot y}{||x||_2||y||_2} + +where :math:`x\cdot y` denotes the dot product. + The :class:`.CosineDistance` class is imported using the following command: >>> from UQpy.utilities.distances.euclidean_distances.CosineDistance import CosineDistance +Methods +~~~~~~~~~~ + One can use the following command to instantiate the class :class:`.CosineDistance` .. autoclass:: UQpy.utilities.distances.euclidean_distances.CosineDistance :members: -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.CosineDistance.distance_matrix - -Dice Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.DiceDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.DiceDistance import DiceDistance - -One can use the following command to instantiate the class :class:`.DiceDistance` +Attributes +~~~~~~~~~~ -.. autoclass:: UQpy.utilities.distances.euclidean_distances.DiceDistance - :members: +.. autoattribute:: UQpy.utilities.distances.euclidean_distances.CosineDistance.distance_matrix -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.DiceDistance.distance_matrix Euclidean Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +The Euclidean distance between two 1D arrays, `x` and `y`, is given by: + +.. math:: d(x,y) = ||x - y||_2 + The :class:`UQpy.utilities.distances.euclidean_distances.EuclideanDistance` class is imported using the following command: >>> from UQpy.utilities.distances.euclidean_distances.EuclideanDistance import EuclideanDistance +Methods +~~~~~~~~~~ + One can use the following command to instantiate the class :class:`UQpy.utilities.distances.euclidean_distances.EuclideanDistance` .. autoclass:: UQpy.utilities.distances.euclidean_distances.EuclideanDistance :members: -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.EuclideanDistance.distance_matrix - -Hamming Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.HammingDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.HammingDistance import HammingDistance - -One can use the following command to instantiate the class :class:`.HammingDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.HammingDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.HammingDistance.distance_matrix - -Jaccard Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.JaccardDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.JaccardDistance import JaccardDistance - -One can use the following command to instantiate the class :class:`.JaccardDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.JaccardDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.JaccardDistance.distance_matrix - -Jensen-Shannon Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.JensenShannonDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.JensenShannonDistance import JensenShannonDistance - -One can use the following command to instantiate the class :class:`.JensenShannonDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.JensenShannonDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.JensenShannonDistance.distance_matrix - -Kulczynski Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.KulczynskiDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.KulczynskiDistance import KulczynskiDistance - -One can use the following command to instantiate the class :class:`.KulczynskiDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.KulczynskiDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.KulczynskiDistance.distance_matrix - -Kulsinski Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.KulsinskiDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.KulsinskiDistance import KulsinskiDistance - -One can use the following command to instantiate the class :class:`.KulsinskiDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.KulsinksiDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.KulsinksiDistance.distance_matrix - -Mahalanobis Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.MahalanobisDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.MahalanobisDistance import MahalanobisDistance - -One can use the following command to instantiate the class :class:`.MahalanobisDistance` +Attributes +~~~~~~~~~~ -.. autoclass:: UQpy.utilities.distances.euclidean_distances.MahalanobisDistance - :members: +.. autoattribute:: UQpy.utilities.distances.euclidean_distances.EuclideanDistance.distance_matrix -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.MahalanobisDistance.distance_matrix -Matching Distance +Minkowski Distance ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -The :class:`.MatchingDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.MatchingDistance import MatchingDistance - -One can use the following command to instantiate the class :class:`.MatchingDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.MatchingDistance - :members: +The Euclidean distance between two 1D arrays, `x` and `y`, is given by: -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.MatchingDistance.distance_matrix - -Minkowski Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. math:: d(x,y) = ||x - y||_p = \left(\sum_i |x_i-y_i|^p \right)^{1/p}. The :class:`.MinkowskiDistance` class is imported using the following command: >>> from UQpy.utilities.distances.euclidean_distances.MinkowskiDistance import MinkowskiDistance +Methods +~~~~~~~~~~ + One can use the following command to instantiate the class :class:`.MinkowskiDistance` .. autoclass:: UQpy.utilities.distances.euclidean_distances.MinkowskiDistance :members: -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.MinkowskiDistance.distance_matrix - -Rogers-Tanimoto Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.RogersTanimotoDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.RogersTanimotoDistance import RogersTanimotoDistance - -One can use the following command to instantiate the class :class:`.RogersTanimotoDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.RogersTanimotoDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.RogersTanimotoDistance.distance_matrix - - -Russell-Rao Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.RussellRaoDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.RussellRaoDistance import RussellRaoDistance - -One can use the following command to instantiate the class :class:`.RussellRaoDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.RussellRaoDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.RussellRaoDistance.distance_matrix - -Sokal-Michener Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.SokalMichenerDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.SokalMichenerDistance import SokalMichenerDistance - -One can use the following command to instantiate the class :class:`.SokalMichenerDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.SokalMichenerDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.SokalMichenerDistance.distance_matrix - -Sokal-Sneath Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.SokalSneathDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.SokalSneathDistance import SokalSneathDistance - -One can use the following command to instantiate the class :class:`.SokalSneathDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.SokalSneathDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.SokalSneathDistance.distance_matrix - -Squared Euclidean Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.SquaredEuclideanDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.SquaredEuclideanDistance import SquaredEuclideanDistance - -One can use the following command to instantiate the class :class:`.SquaredEuclideanDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.SquaredEuclideanDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.SquaredEuclideanDistance.distance_matrix - -Standardized Euclidean Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.StandardizedEuclideanDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.StandardizedEuclideanDistance import StandardizedEuclideanDistance - -One can use the following command to instantiate the class :class:`.StandardizedEuclideanDistance` - -.. autoclass:: UQpy.utilities.distances.euclidean_distances.StandardizedEuclideanDistance - :members: - -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.StandardizedEuclideanDistance.distance_matrix - -Yule Distance -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The :class:`.YuleDistance` class is imported using the following command: - ->>> from UQpy.utilities.distances.euclidean_distances.YuleDistance import YuleDistance - -One can use the following command to instantiate the class :class:`.YuleDistance` +Attributes +~~~~~~~~~~ -.. autoclass:: UQpy.utilities.distances.euclidean_distances.YuleDistance - :members: +.. autoattribute:: UQpy.utilities.distances.euclidean_distances.MinkowskiDistance.distance_matrix -.. autoattribute:: UQpy.utilities.distances.euclidean_distances.YuleDistance.distance_matrix \ No newline at end of file diff --git a/src/UQpy/utilities/distances/euclidean_distances/CorrelationDistance.py b/src/UQpy/utilities/distances/euclidean_distances/CorrelationDistance.py index 501a4ec43..d9345e0cc 100644 --- a/src/UQpy/utilities/distances/euclidean_distances/CorrelationDistance.py +++ b/src/UQpy/utilities/distances/euclidean_distances/CorrelationDistance.py @@ -8,4 +8,11 @@ class CorrelationDistance(EuclideanDistance): def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: + """ + Given two points, this method calculates the Correlation distance. + + :param xi: First point. + :param xj: Second point. + :return: A float representing the distance between the points. + """ return pdist([xi, xj], "correlation")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/CosineDistance.py b/src/UQpy/utilities/distances/euclidean_distances/CosineDistance.py index 96649a62c..66c6da347 100644 --- a/src/UQpy/utilities/distances/euclidean_distances/CosineDistance.py +++ b/src/UQpy/utilities/distances/euclidean_distances/CosineDistance.py @@ -8,4 +8,12 @@ class CosineDistance(EuclideanDistance): def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: + """ + Given two points, this method calculates the Cosine distance. + + :param xi: First point. + :param xj: Second point. + :return: A float representing the distance between the points. + """ + return pdist([xi, xj], "cosine")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/DiceDistance.py b/src/UQpy/utilities/distances/euclidean_distances/DiceDistance.py deleted file mode 100644 index 7c82e3a72..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/DiceDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class DiceDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "dice")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/EuclideanDistance.py b/src/UQpy/utilities/distances/euclidean_distances/EuclideanDistance.py index f8bbd97d5..4d5eaab1b 100644 --- a/src/UQpy/utilities/distances/euclidean_distances/EuclideanDistance.py +++ b/src/UQpy/utilities/distances/euclidean_distances/EuclideanDistance.py @@ -6,4 +6,12 @@ class EuclideanDistance: def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: + """ + Given two points, this method calculates the Euclidean distance. + + :param xi: First point. + :param xj: Second point. + :return: A float representing the distance between the points. + """ + return pdist([xi, xj], "euclidean")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/HammingDistance.py b/src/UQpy/utilities/distances/euclidean_distances/HammingDistance.py deleted file mode 100644 index c745d68c0..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/HammingDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class HammingDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "hamming")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/JaccardDistance.py b/src/UQpy/utilities/distances/euclidean_distances/JaccardDistance.py deleted file mode 100644 index daa1550b5..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/JaccardDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class JaccardDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "jaccard")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/JensenShannonDistance.py b/src/UQpy/utilities/distances/euclidean_distances/JensenShannonDistance.py deleted file mode 100644 index 146050529..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/JensenShannonDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class JensenShannonDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "jensenshannon")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/KulczynskiDistance.py b/src/UQpy/utilities/distances/euclidean_distances/KulczynskiDistance.py deleted file mode 100644 index 9176f07bb..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/KulczynskiDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class KulczynskiDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "kulczynski1")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/KulsinkiDistance.py b/src/UQpy/utilities/distances/euclidean_distances/KulsinkiDistance.py deleted file mode 100644 index 2c5167fd3..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/KulsinkiDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class KulsinksiDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "kulsinski")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/MahalanobisDistance.py b/src/UQpy/utilities/distances/euclidean_distances/MahalanobisDistance.py deleted file mode 100644 index 6c5bc8fd7..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/MahalanobisDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class MahalanobisDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "mahalanobis")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/MatchingDistance.py b/src/UQpy/utilities/distances/euclidean_distances/MatchingDistance.py deleted file mode 100644 index bba4276fc..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/MatchingDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class MatchingDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "matching")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/MinkowskiDistance.py b/src/UQpy/utilities/distances/euclidean_distances/MinkowskiDistance.py index e4f6d6a10..e59cb56ed 100644 --- a/src/UQpy/utilities/distances/euclidean_distances/MinkowskiDistance.py +++ b/src/UQpy/utilities/distances/euclidean_distances/MinkowskiDistance.py @@ -6,8 +6,19 @@ class MinkowskiDistance(EuclideanDistance): - def __init__(self, p=2): + def __init__(self, p: float = 2): + """ + :param p: Order of the norm. + """ self.p = p + def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: + """ + Given two points, this method calculates the Minkowski distance. + + :param xi: First point. + :param xj: Second point. + :return: A float representing the distance between the points. + """ return pdist([xi, xj], "minkowski", p=self.p)[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/RogersTanimotoDistance.py b/src/UQpy/utilities/distances/euclidean_distances/RogersTanimotoDistance.py deleted file mode 100644 index 464cb0275..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/RogersTanimotoDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class RogersTanimotoDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "rogerstanimoto")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/RussellRaoDistance.py b/src/UQpy/utilities/distances/euclidean_distances/RussellRaoDistance.py deleted file mode 100644 index af2d9617c..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/RussellRaoDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class RussellRaoDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "russellrao")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/SokalMichenerDistance.py b/src/UQpy/utilities/distances/euclidean_distances/SokalMichenerDistance.py deleted file mode 100644 index 0d8110eb9..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/SokalMichenerDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class SokalMichenerDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "sokalmichener")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/SokalSneathDistance.py b/src/UQpy/utilities/distances/euclidean_distances/SokalSneathDistance.py deleted file mode 100644 index 829137c03..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/SokalSneathDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class SokalSneathDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "sokalsneath")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/SquaredEuclideanDistance.py b/src/UQpy/utilities/distances/euclidean_distances/SquaredEuclideanDistance.py deleted file mode 100644 index 7ae2c3f13..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/SquaredEuclideanDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class SquaredEuclideanDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "sqeuclidean")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/StandardizedEuclidean.py b/src/UQpy/utilities/distances/euclidean_distances/StandardizedEuclidean.py deleted file mode 100644 index 1c3b5ef1d..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/StandardizedEuclidean.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class StandardizedEuclideanDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "seuclidean")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/YuleDistance.py b/src/UQpy/utilities/distances/euclidean_distances/YuleDistance.py deleted file mode 100644 index 7144ff1a9..000000000 --- a/src/UQpy/utilities/distances/euclidean_distances/YuleDistance.py +++ /dev/null @@ -1,11 +0,0 @@ -from typing import Union - -from UQpy.utilities.ValidationTypes import NumpyFloatArray, Numpy2DFloatArray -from UQpy.utilities.distances.baseclass.EuclideanDistance import EuclideanDistance -from scipy.spatial.distance import pdist - - -class YuleDistance(EuclideanDistance): - - def compute_distance(self, xi: NumpyFloatArray, xj: NumpyFloatArray) -> float: - return pdist([xi, xj], "yule")[0] diff --git a/src/UQpy/utilities/distances/euclidean_distances/__init__.py b/src/UQpy/utilities/distances/euclidean_distances/__init__.py index e4d6b9fbc..37514b6bf 100644 --- a/src/UQpy/utilities/distances/euclidean_distances/__init__.py +++ b/src/UQpy/utilities/distances/euclidean_distances/__init__.py @@ -4,20 +4,5 @@ from UQpy.utilities.distances.euclidean_distances.CityBlockDistance import CityBlockDistance from UQpy.utilities.distances.euclidean_distances.CorrelationDistance import CorrelationDistance from UQpy.utilities.distances.euclidean_distances.CosineDistance import CosineDistance -from UQpy.utilities.distances.euclidean_distances.DiceDistance import DiceDistance from UQpy.utilities.distances.euclidean_distances.EuclideanDistance import EuclideanDistance -from UQpy.utilities.distances.euclidean_distances.HammingDistance import HammingDistance -from UQpy.utilities.distances.euclidean_distances.JaccardDistance import JaccardDistance -from UQpy.utilities.distances.euclidean_distances.JensenShannonDistance import JensenShannonDistance -from UQpy.utilities.distances.euclidean_distances.KulczynskiDistance import KulczynskiDistance -from UQpy.utilities.distances.euclidean_distances.KulsinkiDistance import KulsinksiDistance -from UQpy.utilities.distances.euclidean_distances.MahalanobisDistance import MahalanobisDistance -from UQpy.utilities.distances.euclidean_distances.MatchingDistance import MatchingDistance from UQpy.utilities.distances.euclidean_distances.MinkowskiDistance import MinkowskiDistance -from UQpy.utilities.distances.euclidean_distances.RogersTanimotoDistance import RogersTanimotoDistance -from UQpy.utilities.distances.euclidean_distances.RussellRaoDistance import RussellRaoDistance -from UQpy.utilities.distances.euclidean_distances.SokalMichenerDistance import SokalMichenerDistance -from UQpy.utilities.distances.euclidean_distances.SokalSneathDistance import SokalSneathDistance -from UQpy.utilities.distances.euclidean_distances.SquaredEuclideanDistance import SquaredEuclideanDistance -from UQpy.utilities.distances.euclidean_distances.StandardizedEuclidean import StandardizedEuclideanDistance -from UQpy.utilities.distances.euclidean_distances.YuleDistance import YuleDistance