11from typing import Literal , Dict , Any
2+
23import numpy .ma as ma # pylint: disable=consider-using-from-import
4+
35from pose_evaluation .metrics .base import Signature
46
57AggregationStrategy = Literal ["max" , "min" , "mean" , "sum" ]
68
9+
710class DistanceMeasureSignature (Signature ):
811 """Signature for distance measure metrics."""
12+
913 def __init__ (self , name : str , args : Dict [str , Any ]) -> None :
1014 super ().__init__ (name = name , args = args )
1115 self .update_abbr ("distance" , "dist" )
@@ -14,6 +18,7 @@ def __init__(self, name: str, args: Dict[str, Any]) -> None:
1418
1519class DistanceMeasure :
1620 """Abstract base class for distance measures."""
21+
1722 _SIGNATURE_TYPE = DistanceMeasureSignature
1823
1924 def __init__ (self , name : str ) -> None :
@@ -22,7 +27,7 @@ def __init__(self, name: str) -> None:
2227 def get_distance (self , hyp_data : ma .MaskedArray , ref_data : ma .MaskedArray ) -> float :
2328 """
2429 Compute the distance between hypothesis and reference data.
25-
30+
2631 This method should be implemented by subclasses.
2732 """
2833 raise NotImplementedError
@@ -37,6 +42,7 @@ def get_signature(self) -> Signature:
3742
3843class PowerDistanceSignature (DistanceMeasureSignature ):
3944 """Signature for power distance measures."""
45+
4046 def __init__ (self , name : str , args : Dict [str , Any ]) -> None :
4147 super ().__init__ (name = name , args = args )
4248 self .update_signature_and_abbr ("order" , "ord" , args )
@@ -46,6 +52,7 @@ def __init__(self, name: str, args: Dict[str, Any]) -> None:
4652
4753class AggregatedPowerDistance (DistanceMeasure ):
4854 """Aggregated power distance metric using a specified aggregation strategy."""
55+
4956 _SIGNATURE_TYPE = PowerDistanceSignature
5057
5158 def __init__ (
@@ -56,7 +63,7 @@ def __init__(
5663 ) -> None :
5764 """
5865 Initialize the aggregated power distance metric.
59-
66+
6067 :param order: The exponent to which differences are raised.
6168 :param default_distance: The value to fill in for masked entries.
6269 :param aggregation_strategy: Strategy to aggregate computed distances.
@@ -69,7 +76,7 @@ def __init__(
6976 def _aggregate (self , distances : ma .MaskedArray ) -> float :
7077 """
7178 Aggregate computed distances using the specified strategy.
72-
79+
7380 :param distances: A masked array of computed distances.
7481 :return: A single aggregated distance value.
7582 """
@@ -82,23 +89,19 @@ def _aggregate(self, distances: ma.MaskedArray) -> float:
8289 if self .aggregation_strategy in aggregation_funcs :
8390 return aggregation_funcs [self .aggregation_strategy ]()
8491
85- raise NotImplementedError (
86- f"Aggregation Strategy { self .aggregation_strategy } not implemented"
87- )
92+ raise NotImplementedError (f"Aggregation Strategy { self .aggregation_strategy } not implemented" )
8893
89- def _calculate_distances (
90- self , hyp_data : ma .MaskedArray , ref_data : ma .MaskedArray
91- ) -> ma .MaskedArray :
94+ def _calculate_distances (self , hyp_data : ma .MaskedArray , ref_data : ma .MaskedArray ) -> ma .MaskedArray :
9295 """
9396 Compute element-wise distances between hypothesis and reference data.
94-
97+
9598 Steps:
9699 1. Compute the absolute differences.
97100 2. Raise the differences to the specified power.
98101 3. Sum the powered differences along the last axis.
99102 4. Extract the root corresponding to the power.
100103 5. Fill masked values with the default distance.
101-
104+
102105 :param hyp_data: Hypothesis data as a masked array.
103106 :param ref_data: Reference data as a masked array.
104107 :return: A masked array of computed distances.
0 commit comments