Skip to content

Commit

Permalink
Adds distance matrix attribute in all distances
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtsap committed Apr 7, 2022
1 parent 68cc3a0 commit 4579a68
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 4 deletions.
48 changes: 47 additions & 1 deletion docs/source/utilities/distances/euclidean_distances.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ One can use the following command to instantiate the class :class:`.BrayCurtisDi
.. autoclass:: UQpy.utilities.distances.euclidean_distances.BrayCurtisDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.BrayCurtisDistance.distance_matrix

Canberra Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -40,6 +42,8 @@ One can use the following command to instantiate the class :class:`.CanberraDist
.. autoclass:: UQpy.utilities.distances.euclidean_distances.CanberraDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.CanberraDistance.distance_matrix

Chebyshev Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -52,6 +56,8 @@ One can use the following command to instantiate the class :class:`.ChebyshevDis
.. autoclass:: UQpy.utilities.distances.euclidean_distances.ChebyshevDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.ChebyshevDistance.distance_matrix

CityBlock Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -64,6 +70,8 @@ One can use the following command to instantiate the class :class:`.CityBlockDis
.. autoclass:: UQpy.utilities.distances.euclidean_distances.CityBlockDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.CityBlockDistance.distance_matrix

Correlation Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -76,6 +84,8 @@ One can use the following command to instantiate the class :class:`.CorrelationD
.. autoclass:: UQpy.utilities.distances.euclidean_distances.CorrelationDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.CorrelationDistance.distance_matrix

Cosine Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -88,6 +98,8 @@ One can use the following command to instantiate the class :class:`.CosineDistan
.. autoclass:: UQpy.utilities.distances.euclidean_distances.CosineDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.CosineDistance.distance_matrix

Dice Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -100,6 +112,8 @@ One can use the following command to instantiate the class :class:`.DiceDistance
.. autoclass:: UQpy.utilities.distances.euclidean_distances.DiceDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.DiceDistance.distance_matrix

Euclidean Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -112,6 +126,8 @@ One can use the following command to instantiate the class :class:`UQpy.utilitie
.. autoclass:: UQpy.utilities.distances.euclidean_distances.EuclideanDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.EuclideanDistance.distance_matrix

Hamming Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -124,6 +140,8 @@ One can use the following command to instantiate the class :class:`.HammingDista
.. autoclass:: UQpy.utilities.distances.euclidean_distances.HammingDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.HammingDistance.distance_matrix

Jaccard Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -136,6 +154,8 @@ One can use the following command to instantiate the class :class:`.JaccardDista
.. autoclass:: UQpy.utilities.distances.euclidean_distances.JaccardDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.JaccardDistance.distance_matrix

Jensen-Shannon Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -148,6 +168,8 @@ One can use the following command to instantiate the class :class:`.JensenShanno
.. autoclass:: UQpy.utilities.distances.euclidean_distances.JensenShannonDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.JensenShannonDistance.distance_matrix

Kulczynski Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -160,6 +182,8 @@ One can use the following command to instantiate the class :class:`.KulczynskiDi
.. autoclass:: UQpy.utilities.distances.euclidean_distances.KulczynskiDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.KulczynskiDistance.distance_matrix

Kulsinski Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -172,6 +196,8 @@ One can use the following command to instantiate the class :class:`.KulsinskiDis
.. autoclass:: UQpy.utilities.distances.euclidean_distances.KulsinksiDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.KulsinksiDistance.distance_matrix

Mahalanobis Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -184,6 +210,8 @@ One can use the following command to instantiate the class :class:`.MahalanobisD
.. autoclass:: UQpy.utilities.distances.euclidean_distances.MahalanobisDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.MahalanobisDistance.distance_matrix

Matching Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -196,6 +224,8 @@ One can use the following command to instantiate the class :class:`.MatchingDist
.. autoclass:: UQpy.utilities.distances.euclidean_distances.MatchingDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.MatchingDistance.distance_matrix

Minkowski Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -208,6 +238,8 @@ One can use the following command to instantiate the class :class:`.MinkowskiDis
.. autoclass:: UQpy.utilities.distances.euclidean_distances.MinkowskiDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.MinkowskiDistance.distance_matrix

Rogers-Tanimoto Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -220,6 +252,8 @@ One can use the following command to instantiate the class :class:`.RogersTanimo
.. autoclass:: UQpy.utilities.distances.euclidean_distances.RogersTanimotoDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.RogersTanimotoDistance.distance_matrix


Russell-Rao Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -233,6 +267,8 @@ One can use the following command to instantiate the class :class:`.RussellRaoDi
.. autoclass:: UQpy.utilities.distances.euclidean_distances.RussellRaoDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.RussellRaoDistance.distance_matrix

Sokal-Michener Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -245,6 +281,8 @@ One can use the following command to instantiate the class :class:`.SokalMichene
.. autoclass:: UQpy.utilities.distances.euclidean_distances.SokalMichenerDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.SokalMichenerDistance.distance_matrix

Sokal-Sneath Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -257,6 +295,8 @@ One can use the following command to instantiate the class :class:`.SokalSneathD
.. autoclass:: UQpy.utilities.distances.euclidean_distances.SokalSneathDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.SokalSneathDistance.distance_matrix

Squared Euclidean Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -269,6 +309,8 @@ One can use the following command to instantiate the class :class:`.SquaredEucli
.. autoclass:: UQpy.utilities.distances.euclidean_distances.SquaredEuclideanDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.SquaredEuclideanDistance.distance_matrix

Standardized Euclidean Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -281,6 +323,8 @@ One can use the following command to instantiate the class :class:`.Standardized
.. autoclass:: UQpy.utilities.distances.euclidean_distances.StandardizedEuclideanDistance
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.StandardizedEuclideanDistance.distance_matrix

Yule Distance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -291,4 +335,6 @@ The :class:`.YuleDistance` class is imported using the following command:
One can use the following command to instantiate the class :class:`.YuleDistance`

.. autoclass:: UQpy.utilities.distances.euclidean_distances.YuleDistance
:members:
:members:

.. autoattribute:: UQpy.utilities.distances.euclidean_distances.YuleDistance.distance_matrix
13 changes: 13 additions & 0 deletions docs/source/utilities/distances/grassmann_distances.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ It allows the user to define a set of methods that must be created within any ch




Asimov
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -46,6 +47,7 @@ One can use the following command to instantiate the class :class:`.AsimovDistan
.. autoclass:: UQpy.utilities.distances.grassmannian_distances.AsimovDistance
:members:

.. autoattribute:: UQpy.utilities.distances.grassmannian_distances.AsimovDistance.distance_matrix

Binet-Cauchy
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -60,6 +62,8 @@ One can use the following command to instantiate the class :class:`.BinetCauchyD
.. autoclass:: UQpy.utilities.distances.grassmannian_distances.BinetCauchyDistance
:members:

.. autoattribute:: UQpy.utilities.distances.grassmannian_distances.BinetCauchyDistance.distance_matrix


Fubini-Study
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -74,6 +78,7 @@ One can use the following command to instantiate the class :class:`.FubiniStudyD
.. autoclass:: UQpy.utilities.distances.grassmannian_distances.FubiniStudyDistance
:members:

.. autoattribute:: UQpy.utilities.distances.grassmannian_distances.FubiniStudyDistance.distance_matrix


Geodesic
Expand All @@ -89,6 +94,7 @@ One can use the following command to instantiate the class :class:`.GeodesicDist
.. autoclass:: UQpy.utilities.distances.grassmannian_distances.GeodesicDistance
:members:

.. autoattribute:: UQpy.utilities.distances.grassmannian_distances.GeodesicDistance.distance_matrix

Martin
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -103,6 +109,8 @@ One can use the following command to instantiate the class :class:`.MartinDistan
.. autoclass:: UQpy.utilities.distances.grassmannian_distances.MartinDistance
:members:

.. autoattribute:: UQpy.utilities.distances.grassmannian_distances.MartinDistance.distance_matrix



Procrustes
Expand All @@ -117,6 +125,7 @@ One can use the following command to instantiate the class :class:`.ProcrustesDi
.. autoclass:: UQpy.utilities.distances.grassmannian_distances.ProcrustesDistance
:members:

.. autoattribute:: UQpy.utilities.distances.grassmannian_distances.ProcrustesDistance.distance_matrix

Projection
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -130,6 +139,8 @@ One can use the following command to instantiate the class :class:`.ProjectionDi
.. autoclass:: UQpy.utilities.distances.grassmannian_distances.ProjectionDistance
:members:

.. autoattribute:: UQpy.utilities.distances.grassmannian_distances.ProjectionDistance.distance_matrix


Spectral
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -142,3 +153,5 @@ One can use the following command to instantiate the class :class:`.SpectralDist

.. autoclass:: UQpy.utilities.distances.grassmannian_distances.SpectralDistance
:members:

.. autoattribute:: UQpy.utilities.distances.grassmannian_distances.SpectralDistance.distance_matrix
4 changes: 3 additions & 1 deletion src/UQpy/utilities/distances/baseclass/Distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import numpy as np



class Distance(ABC):
"""
This class serves as a baseclass under which the distance implementations for all spaces exist.
"""
def __init__(self):
self.distance_matrix: np.ndarray = None
"""Distance matrix defining the pairwise distances between the points"""

def calculate_distance_matrix(self, points):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def calculate_distance_matrix(self, points: list[NumpyFloatArray]):

distance_list.append(distance_value)

return distance_list
self.distance_matrix = distance_list
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ def calculate_distance_matrix(self,

distance_list.append(distance_value)

return distance_list
self.distance_matrix = distance_list

0 comments on commit 4579a68

Please sign in to comment.