xlin 0.1.9__py2.py3-none-any.whl → 0.1.10__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
xlin/__init__.py
CHANGED
xlin/metric.py
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
def stream_average(avg_pre, cur_num_index, cur_num):
|
3
|
+
"""
|
4
|
+
calculate the average of number in a stream
|
5
|
+
given nums: List[float], calculate avg[n] = sum(nums[:n]) / len(nums[:n]) = sum(nums[:n]) / n
|
6
|
+
however, we don't know the length of the stream, so we use a moving average
|
7
|
+
so avg[n-1] = sum(nums[:n-1]) / (n-1)
|
8
|
+
so n * avg[n] = (n-1) * avg[n-1] + nums[n]
|
9
|
+
so avg[n] = avg[n-1] + (nums[n] - avg[n-1]) / n
|
10
|
+
we don't need to remember every nums before n
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
>>> acc = 0
|
14
|
+
>>> nums = [1, 0, 1, 0, 0, 1, 1, 1, 0, 1]
|
15
|
+
>>> for i, num in enumerate(nums):
|
16
|
+
... acc = stream_average(acc, i, num)
|
17
|
+
|
18
|
+
:param avg_pre: (initially 0) average of previous numbers from index 0 to cur_num_index-1, i.e. avg[n-1]
|
19
|
+
:param cur_num_index: current number index starting from 0, i.e. n
|
20
|
+
:param cur_num: current number, i.e. nums[n]
|
21
|
+
:return: average of current number and previous numbers, i.e. avg[n]
|
22
|
+
"""
|
23
|
+
return avg_pre + (cur_num - avg_pre) / (cur_num_index + 1)
|
24
|
+
|
25
|
+
|
26
|
+
class AverageMeter:
|
27
|
+
"""Computes and stores the average and current value"""
|
28
|
+
|
29
|
+
def __init__(self, name, fmt=':f'):
|
30
|
+
self.name = name
|
31
|
+
self.fmt = fmt
|
32
|
+
self.val = 0
|
33
|
+
self.avg = 0
|
34
|
+
self.sum = 0
|
35
|
+
self.count = 0
|
36
|
+
self.reset()
|
37
|
+
|
38
|
+
def reset(self):
|
39
|
+
self.val = 0
|
40
|
+
self.avg = 0
|
41
|
+
self.sum = 0
|
42
|
+
self.count = 0
|
43
|
+
|
44
|
+
def update(self, val, n=1):
|
45
|
+
self.val = val
|
46
|
+
self.sum += val * n
|
47
|
+
self.count += n
|
48
|
+
self.avg = self.sum / self.count
|
49
|
+
|
50
|
+
def __str__(self):
|
51
|
+
fmtstr = '{name} {val' + self.fmt + '} ({avg' + self.fmt + '})'
|
52
|
+
return fmtstr.format(**self.__dict__)
|
53
|
+
|
@@ -1,13 +1,14 @@
|
|
1
|
-
xlin/__init__.py,sha256=
|
1
|
+
xlin/__init__.py,sha256=xH5nS8y2RhQ8IDMM2pVkD5W0lxEFuymUSpzSWKo-358,226
|
2
2
|
xlin/ischinese.py,sha256=Ia9IMQ6q-UHkdLwqS70L1fTnfSPbluFrv_I1UqsKquo,293
|
3
3
|
xlin/jsonl.py,sha256=DvVM241a9VgQlp5WIMPRv-JIolT0RdSxw47IG_fc7xE,6690
|
4
|
+
xlin/metric.py,sha256=N7wJ35y-C-IaBr1I1CJ_37lTG7gA69zmn9Xg6xSwKoI,1690
|
4
5
|
xlin/multiprocess_mapping.py,sha256=pmzyEUYpbpIZ_ezyvWWWRpr7D7n4t3E3jW1nGXBbVck,7652
|
5
6
|
xlin/read_as_dataframe.py,sha256=ir3HUT6dt3crqa3xnlcNn8j3wqjSIGJgiIVLP3KkBaQ,8678
|
6
7
|
xlin/statistic.py,sha256=BLj8hszlbBT5xDIfd70_YtOb8QgZEvYXiFJDGXBwCfw,881
|
7
8
|
xlin/util.py,sha256=SOQUh506GQlljJYLYuI6nScSTOrgRQnMq2xfxSvKIlI,11303
|
8
9
|
xlin/xls2xlsx.py,sha256=5zfcM0gmunFQOcOj9nYd9Dj0HMhU7-cPKnPIy6Ot9iU,930
|
9
10
|
xlin/yaml.py,sha256=kICi7G3Td5q2MaSXXt85qNTWoHMgjzt7pvn7r3C4dME,183
|
10
|
-
xlin-0.1.
|
11
|
-
xlin-0.1.
|
12
|
-
xlin-0.1.
|
13
|
-
xlin-0.1.
|
11
|
+
xlin-0.1.10.dist-info/LICENSE,sha256=KX0dDCYlO4DskqMZY8qeY94EZMrDRNnNqlGLkXVlKyM,1063
|
12
|
+
xlin-0.1.10.dist-info/METADATA,sha256=to4m4VItekZ4FH89aOWoe-RH5KfBkJJMKCX2ApdQAVI,1047
|
13
|
+
xlin-0.1.10.dist-info/WHEEL,sha256=IrRNNNJ-uuL1ggO5qMvT1GGhQVdQU54d6ZpYqEZfEWo,92
|
14
|
+
xlin-0.1.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|