diff --git a/spatz/metrics/max_dev.py b/spatz/metrics/max_dev.py new file mode 100644 index 0000000..2f465bd --- /dev/null +++ b/spatz/metrics/max_dev.py @@ -0,0 +1,20 @@ +from numpy.typing import ArrayLike +from spatz.metrics import Metric + + +class MaxAbsDeviation(Metric): + def __init__(self) -> None: + """A metric tracking the maximum absolute deviation from the true value.""" + super().__init__() + + def _update(self, x: ArrayLike, y: ArrayLike): + self._score = max(self._score, abs(x - y)) + + +class MaxRelDeviation(Metric): + def __init__(self) -> None: + """A metric tracking the maximum deviation from the true value in percent.""" + super().__init__() + + def _update(self, x: ArrayLike, y: ArrayLike): + self._score = max(self._score, (x - y) / y) diff --git a/spatz/metrics/metric.py b/spatz/metrics/metric.py index 6ebf913..869e93f 100644 --- a/spatz/metrics/metric.py +++ b/spatz/metrics/metric.py @@ -1,14 +1,19 @@ +from abc import abstractmethod - +from numpy.typing import ArrayLike from typing import Any class Metric: def __init__(self) -> None: - self.__sum = 0 + self._score = None - def get_score(): - pass + def get_score(self): + return self._score - def __call__(self, *args) -> Any: - self.__sum += abs(x - y) \ No newline at end of file + @abstractmethod + def _update(self, x: ArrayLike, y: ArrayLike): + raise NotImplementedError() + + def __call__(self, x: ArrayLike, y: ArrayLike) -> Any: + self._update(x, y) \ No newline at end of file diff --git a/spatz/metrics/mse.py b/spatz/metrics/mse.py new file mode 100644 index 0000000..4d43b5b --- /dev/null +++ b/spatz/metrics/mse.py @@ -0,0 +1,15 @@ +from numpy.typing import ArrayLike +from spatz.metrics import Metric + + +class MSEMetric(Metric): + def __init__(self) -> None: + """Mean squared error + """ + super().__init__() + + def _update(self, x: ArrayLike, y: ArrayLike): + if self._score is None: + self._score = 0.5 * (x - y)**2 + else: + self._score += 0.5 * (x - y)**2 diff --git a/spatz/sensors/gps/erinome1.py b/spatz/sensors/gps/erinome1.py index 9a9483b..0b1d48a 100644 --- a/spatz/sensors/gps/erinome1.py +++ b/spatz/sensors/gps/erinome1.py @@ -14,4 +14,6 @@ class Erinome_I(GPS): def _sensor_specific_effects(self, x: ArrayLike) -> ArrayLike: # TODO: What's the GPS module's behavior? + # TODO: Only return measurements every second + return x \ No newline at end of file diff --git a/spatz/sensors/gps/gps.py b/spatz/sensors/gps/gps.py index 99b58e6..37b8c0b 100644 --- a/spatz/sensors/gps/gps.py +++ b/spatz/sensors/gps/gps.py @@ -16,7 +16,7 @@ class GPS(Sensor): """GPS Module which provides the following information: - Longitude (in °) - Latitiude (in °) - - Altitude (in °) + - Altitude (in m) """ super().__init__(dataset, logger, transforms)