Skip to content

Commit

Permalink
Adding base metric classes and enums
Browse files Browse the repository at this point in the history
  • Loading branch information
drewoldag committed Nov 8, 2023
1 parent 7c0dcfe commit 2b29e94
Showing 1 changed file with 132 additions and 0 deletions.
132 changes: 132 additions & 0 deletions src/qp/metrics/base_metric_classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import enum

Check warning on line 1 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L1

Added line #L1 was not covered by tests

from abc import ABC

Check warning on line 3 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L3

Added line #L3 was not covered by tests

class MetricInputType(enum.Enum):

Check warning on line 5 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L5

Added line #L5 was not covered by tests
"""Defines the various combinations of input types that metric classes accept.
"""

unknown = -1

Check warning on line 9 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L9

Added line #L9 was not covered by tests

# A single qp.Ensemble
single_ensemble = 0

Check warning on line 12 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L12

Added line #L12 was not covered by tests

# A distribution, or collection of distributions for estimate(s) and a
# single value, or collection of values for reference(s)
dist_to_point = 1

Check warning on line 16 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L16

Added line #L16 was not covered by tests

# A distribution, or collection of distributions for estimate(s) and a
# distribution, or collection of distributions for references(s)
dist_to_dist = 2

Check warning on line 20 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L20

Added line #L20 was not covered by tests

# A single value, or collection of values for estimate(s) and a
# single value, or collection of values for reference(s).
point_to_point = 3

Check warning on line 24 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L24

Added line #L24 was not covered by tests

# A single value, or collection of values for estimate(s) and a
# distribution, or collection of distributions for reference(s).
point_to_dist = 4

Check warning on line 28 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L28

Added line #L28 was not covered by tests


def uses_distribution_for_estimate(self):
return self in [

Check warning on line 32 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L31-L32

Added lines #L31 - L32 were not covered by tests
MetricInputType.single_ensemble,
MetricInputType.dist_to_point,
MetricInputType.dist_to_dist,
]

def uses_distribution_for_reference(self):
return self in [

Check warning on line 39 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L38-L39

Added lines #L38 - L39 were not covered by tests
MetricInputType.dist_to_dist,
MetricInputType.point_to_dist,
]

def uses_point_for_estimate(self):
return self in [

Check warning on line 45 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L44-L45

Added lines #L44 - L45 were not covered by tests
MetricInputType.point_to_dist,
MetricInputType.point_to_dist,
]

def uses_point_for_reference(self):
return self in [

Check warning on line 51 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L50-L51

Added lines #L50 - L51 were not covered by tests
MetricInputType.dist_to_point,
MetricInputType.point_to_point,
]


class MetricOuputType(enum.Enum):

Check warning on line 57 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L57

Added line #L57 was not covered by tests
"""Defines the various output types that metric classes can return.
"""

unknown = -1

Check warning on line 61 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L61

Added line #L61 was not covered by tests

# The metric produces a single value for all input
single_value = 0

Check warning on line 64 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L64

Added line #L64 was not covered by tests

# The metric produces a single distribution for all input
single_distribution = 1

Check warning on line 67 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L67

Added line #L67 was not covered by tests

# The metric produces a value for each input distribution
one_value_per_distribution = 2

Check warning on line 70 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L70

Added line #L70 was not covered by tests


class BaseMetric(ABC):
metric_name = None # The name for this metric, overwritten in subclasses
metric_input_type = MetricInputType.unknown # The type of input data expected for this metric
metric_output_type = MetricOuputType.unknown # The form of the output data from this metric

Check warning on line 76 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L73-L76

Added lines #L73 - L76 were not covered by tests

def __init__(self, limit:tuple=(0.0, 3.0), dx:float=0.01) -> None:

Check warning on line 78 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L78

Added line #L78 was not covered by tests

self._limit = limit
self._dx = dx

Check warning on line 81 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L80-L81

Added lines #L80 - L81 were not covered by tests

def initialize(self) -> None:
pass

Check warning on line 84 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L83-L84

Added lines #L83 - L84 were not covered by tests

def evaluate(self) -> None:
pass

Check warning on line 87 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L86-L87

Added lines #L86 - L87 were not covered by tests

def finalize(self) -> None:
pass

Check warning on line 90 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L89-L90

Added lines #L89 - L90 were not covered by tests

@classmethod
def uses_distribution_for_estimate(cls):
return cls.metric_input_type.uses_distribution_for_estimate()

Check warning on line 94 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L92-L94

Added lines #L92 - L94 were not covered by tests

@classmethod
def uses_distribution_for_reference(cls):
return cls.metric_input_type.uses_distribution_for_reference()

Check warning on line 98 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L96-L98

Added lines #L96 - L98 were not covered by tests

@classmethod
def uses_point_for_estimate(cls):
return cls.metric_input_type.uses_point_for_estimate()

Check warning on line 102 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L100-L102

Added lines #L100 - L102 were not covered by tests

@classmethod
def uses_point_for_reference(cls):
return cls.metric_input_type.uses_point_for_reference()

Check warning on line 106 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L104-L106

Added lines #L104 - L106 were not covered by tests


class SingleEnsembleMetric(BaseMetric):

Check warning on line 109 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L109

Added line #L109 was not covered by tests

metric_input_type = MetricInputType.single_ensemble
metric_output_type = MetricOuputType.one_value_per_distribution

Check warning on line 112 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L111-L112

Added lines #L111 - L112 were not covered by tests


class DistToDistMetric(BaseMetric):

Check warning on line 115 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L115

Added line #L115 was not covered by tests

metric_input_type = MetricInputType.dist_to_dist

Check warning on line 117 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L117

Added line #L117 was not covered by tests


class DistToPointMetric(BaseMetric):

Check warning on line 120 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L120

Added line #L120 was not covered by tests

metric_input_type = MetricInputType.dist_to_point

Check warning on line 122 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L122

Added line #L122 was not covered by tests


class PointToPointMetric(BaseMetric):

Check warning on line 125 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L125

Added line #L125 was not covered by tests

metric_input_type = MetricInputType.point_to_point

Check warning on line 127 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L127

Added line #L127 was not covered by tests


class PointToDistMetric(BaseMetric):

Check warning on line 130 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L130

Added line #L130 was not covered by tests

metric_input_type = MetricInputType.point_to_dist

Check warning on line 132 in src/qp/metrics/base_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L132

Added line #L132 was not covered by tests

0 comments on commit 2b29e94

Please sign in to comment.