Coverage for src/nos/metrics/metric.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-19 11:29 +0000

1from abc import ( 

2 ABC, 

3 abstractmethod, 

4) 

5from typing import ( 

6 Dict, 

7) 

8 

9from continuiti.data import ( 

10 OperatorDataset, 

11) 

12from continuiti.operators import ( 

13 Operator, 

14) 

15 

16 

17class Metric(ABC): 

18 """Base class for all metrics.""" 

19 

20 def __init__(self, name: str): 

21 self.name = name 

22 

23 @abstractmethod 

24 def __call__(self, operator: Operator, dataset: OperatorDataset) -> Dict: 

25 """Evaluates the metric. 

26 

27 Args: 

28 operator: operator for which the metric is evaluated. 

29 dataset: dataset on which the metric is evaluated. 

30 

31 Returns: 

32 dict containing the results of the metric (keys "value" and "unit" should be in the dict). 

33 """ 

34 

35 def __str__(self): 

36 return self.name