Skip to content

Commit

Permalink
Adding wrapper for calculate_moment.
Browse files Browse the repository at this point in the history
  • Loading branch information
drewoldag committed Nov 8, 2023
1 parent 49219e3 commit 68963b3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
24 changes: 21 additions & 3 deletions src/qp/metrics/base_metric_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,41 @@ class SingleEnsembleMetric(BaseMetric):
metric_input_type = MetricInputType.single_ensemble
metric_output_type = MetricOuputType.one_value_per_distribution

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L102 - L103 were not covered by tests

def initialize(self):
raise NotImplementedError()

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#L105-L106

Added lines #L105 - L106 were not covered by tests

def evaluate(self, estimate):
raise NotImplementedError()

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#L108-L109

Added lines #L108 - L109 were not covered by tests

def finalize(self):
raise NotImplementedError()

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

def initialize(self):
raise NotImplementedError()

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#L119-L120

Added lines #L119 - L120 were not covered by tests

def evaluate(self, estimate, reference):
raise NotImplementedError()

Check warning on line 123 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-L123

Added lines #L122 - L123 were not covered by tests

def finalize(self):
raise NotImplementedError()

Check warning on line 126 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-L126

Added lines #L125 - L126 were not covered by tests


class DistToPointMetric(BaseMetric):

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

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L129

Added line #L129 was not covered by tests

metric_input_type = MetricInputType.dist_to_point

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

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L131

Added line #L131 was not covered by tests

def initialize(self, **kwargs):
def initialize(self):
raise NotImplementedError()

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

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L133-L134

Added lines #L133 - L134 were not covered by tests

def evaluate(self, estimate, reference, **kwargs):
def evaluate(self, estimate, reference):
raise NotImplementedError()

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

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L136-L137

Added lines #L136 - L137 were not covered by tests

def finalize(self, **kwargs):
def finalize(self):
raise NotImplementedError()

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

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/base_metric_classes.py#L139-L140

Added lines #L139 - L140 were not covered by tests


Expand Down
28 changes: 25 additions & 3 deletions src/qp/metrics/concrete_metric_classes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
from qp.metrics.base_metric_classes import MetricOuputType, DistToDistMetric
from qp.metrics.metrics import calculate_kld
from qp.metrics.base_metric_classes import MetricOuputType, DistToDistMetric, SingleEnsembleMetric
from qp.metrics.metrics import calculate_kld, calculate_moment

Check warning on line 2 in src/qp/metrics/concrete_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/concrete_metric_classes.py#L1-L2

Added lines #L1 - L2 were not covered by tests

class MomentMetric(SingleEnsembleMetric):

Check warning on line 4 in src/qp/metrics/concrete_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/concrete_metric_classes.py#L4

Added line #L4 was not covered by tests
"""Class wrapper around the `calculate_moment` function.
"""

metric_name = "moment"

Check warning on line 8 in src/qp/metrics/concrete_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/concrete_metric_classes.py#L8

Added line #L8 was not covered by tests

def __init__(self, moment_order:int=1, limits:tuple=(0.0, 3.0), dx:float=0.01) -> None:
super().__init__()
self._moment_order = moment_order
self._limits = limits
self._dx = dx

Check warning on line 14 in src/qp/metrics/concrete_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/concrete_metric_classes.py#L10-L14

Added lines #L10 - L14 were not covered by tests

def initialize(self) -> None:
pass

Check warning on line 17 in src/qp/metrics/concrete_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/concrete_metric_classes.py#L16-L17

Added lines #L16 - L17 were not covered by tests

def evalulate(self, estimate) -> list:
return calculate_moment(estimate, self._moment_order, self._limits, self._dx)

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

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/concrete_metric_classes.py#L19-L20

Added lines #L19 - L20 were not covered by tests

def finalize(self) -> None:
pass

Check warning on line 23 in src/qp/metrics/concrete_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/concrete_metric_classes.py#L22-L23

Added lines #L22 - L23 were not covered by tests


class KLDMetric(DistToDistMetric):

Check warning on line 26 in src/qp/metrics/concrete_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/concrete_metric_classes.py#L26

Added line #L26 was not covered by tests
"""Class wrapper around the KLD metric
Expand All @@ -16,7 +38,7 @@ def __init__(self, limits:tuple=(0.0, 3.0), dx:float=0.01) -> None:
def initialize(self) -> None:
pass

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L38 - L39 were not covered by tests

def evaluate(self, estimate, reference) -> None:
def evaluate(self, estimate, reference) -> list:
return calculate_kld(estimate, reference, self._limits, self._dx)

Check warning on line 42 in src/qp/metrics/concrete_metric_classes.py

View check run for this annotation

Codecov / codecov/patch

src/qp/metrics/concrete_metric_classes.py#L41-L42

Added lines #L41 - L42 were not covered by tests

def finalize(self) -> None:
Expand Down

0 comments on commit 68963b3

Please sign in to comment.