File size: 1,216 Bytes
079c32c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
FLOAT_MAX = 1000000.0
FLOAT_MIN = -float('inf')


class MinMaxStats:

    def __init__(self) -> None:
        self.clear()
        self.value_delta_max = 0

    def set_delta(self, value_delta_max: float) -> None:
        self.value_delta_max = value_delta_max

    def update(self, value: float) -> None:
        if value > self.maximum:
            self.maximum = value
        if value < self.minimum:
            self.minimum = value

    def clear(self) -> None:
        self.minimum = FLOAT_MAX
        self.maximum = FLOAT_MIN

    def normalize(self, value: float) -> float:
        norm_value = value
        delta = self.maximum - self.minimum
        if delta > 0:
            if delta < self.value_delta_max:
                norm_value = (norm_value - self.minimum) / self.value_delta_max
            else:
                norm_value = (norm_value - self.minimum) / delta
        return norm_value


class MinMaxStatsList:

    def __init__(self, num: int) -> None:
        self.num = num
        self.stats_lst = [MinMaxStats() for _ in range(self.num)]

    def set_delta(self, value_delta_max: float) -> None:
        for i in range(self.num):
            self.stats_lst[i].set_delta(value_delta_max)