-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.py
69 lines (59 loc) · 2.29 KB
/
stats.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright 2022 The GPflow Contributors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from dataclasses import dataclass
import numpy as np
import pandas as pd
@dataclass
class Stats:
with_mean: float
with_std: float
without_mean: float
without_std: float
rel_overhead_mean: float
rel_overhead_std: float
abs_overhead_mean: float
abs_overhead_std: float
@staticmethod
def new(df: pd.DataFrame) -> "Stats":
by_cs = df.groupby("check_shapes")
mean_by_cs = by_cs.time_s.mean()
std_by_cs = by_cs.time_s.std().fillna(0.0)
var_by_cs = by_cs.time_s.var().fillna(0.0)
with_mean = mean_by_cs[True]
with_mean_sq = with_mean ** 2
with_std = std_by_cs[True]
with_var = var_by_cs[True]
without_mean = mean_by_cs[False]
without_mean_sq = without_mean ** 2
without_std = std_by_cs[False]
without_var = var_by_cs[False]
rel_overhead_mean = (with_mean / without_mean) - 1
# https://en.wikipedia.org/wiki/Ratio_distribution#Uncorrelated_noncentral_normal_ratio
rel_overhead_var = (with_mean_sq / without_mean_sq) * (
(with_var / with_mean_sq) + (without_var / without_mean_sq)
)
rel_overhead_std = np.sqrt(rel_overhead_var)
abs_overhead_mean = with_mean - without_mean
abs_overhead_var = with_var + without_var
abs_overhead_std = np.sqrt(abs_overhead_var)
return Stats(
with_mean=with_mean,
with_std=with_std,
without_mean=without_mean,
without_std=without_std,
rel_overhead_mean=rel_overhead_mean,
rel_overhead_std=rel_overhead_std,
abs_overhead_mean=abs_overhead_mean,
abs_overhead_std=abs_overhead_std,
)