mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-06-10 18:15:59 +00:00
Added a few metrics for measuring performance
This commit is contained in:
parent
33e5eba3a6
commit
4a93fd4ee6
20
spatz/metrics/max_dev.py
Normal file
20
spatz/metrics/max_dev.py
Normal file
@ -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)
|
@ -1,14 +1,19 @@
|
|||||||
|
from abc import abstractmethod
|
||||||
|
|
||||||
|
from numpy.typing import ArrayLike
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class Metric:
|
class Metric:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.__sum = 0
|
self._score = None
|
||||||
|
|
||||||
def get_score():
|
def get_score(self):
|
||||||
pass
|
return self._score
|
||||||
|
|
||||||
def __call__(self, *args) -> Any:
|
@abstractmethod
|
||||||
self.__sum += abs(x - y)
|
def _update(self, x: ArrayLike, y: ArrayLike):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def __call__(self, x: ArrayLike, y: ArrayLike) -> Any:
|
||||||
|
self._update(x, y)
|
15
spatz/metrics/mse.py
Normal file
15
spatz/metrics/mse.py
Normal file
@ -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
|
@ -14,4 +14,6 @@ class Erinome_I(GPS):
|
|||||||
def _sensor_specific_effects(self, x: ArrayLike) -> ArrayLike:
|
def _sensor_specific_effects(self, x: ArrayLike) -> ArrayLike:
|
||||||
# TODO: What's the GPS module's behavior?
|
# TODO: What's the GPS module's behavior?
|
||||||
|
|
||||||
|
# TODO: Only return measurements every second
|
||||||
|
|
||||||
return x
|
return x
|
@ -16,7 +16,7 @@ class GPS(Sensor):
|
|||||||
"""GPS Module which provides the following information:
|
"""GPS Module which provides the following information:
|
||||||
- Longitude (in °)
|
- Longitude (in °)
|
||||||
- Latitiude (in °)
|
- Latitiude (in °)
|
||||||
- Altitude (in °)
|
- Altitude (in m)
|
||||||
"""
|
"""
|
||||||
super().__init__(dataset, logger, transforms)
|
super().__init__(dataset, logger, transforms)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user