diff options
author | Laurent Alfonsi <laurent.alfonsi@linaro.org> | 2024-03-27 11:04:42 +0100 |
---|---|---|
committer | Laurent Alfonsi <laurent.alfonsi@linaro.org> | 2024-03-27 11:04:46 +0100 |
commit | 8bcb0020f48cfde23049ccafb87959563cb09c0c (patch) | |
tree | 7986d3c113f8e0cb30a0dbb034789755abfecd83 | |
parent | 91ec84e83ec773be33fe522a11d8961629b235af (diff) |
compute-variability.py: Enhance peak detection for 2-peaks-linear algorithm
Change-Id: I6099890fb71730d7f48782f7ead27a0ca08ec77e
-rwxr-xr-x | compute-variability.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/compute-variability.py b/compute-variability.py index d655142..2bf9a02 100755 --- a/compute-variability.py +++ b/compute-variability.py @@ -6,6 +6,7 @@ import pandas as pd import argparse import numpy as np import math +from scipy.signal import find_peaks import metric_utils @@ -38,17 +39,22 @@ Routine to compute weighted average. """ def compute_weighted_total(values, aggregate_method, aggregate_weights): v = values.iloc[2:-1].astype("float").to_numpy() + # DEBUG print("v = ", v) if aggregate_weights=="linear": w = np.linspace(100, 0, len(v)) elif aggregate_weights=="flat": w = np.linspace(100, 100, len(v)) elif aggregate_weights=="2-peaks-linear": - indexes=[i for i, x in enumerate(v) if x >= 0] + values_interp = pd.Series(v).interpolate() + # DEBUG print("v_interp = ", values_interp.to_numpy()) + peaks = find_peaks(values_interp, height=0) + # DEBUG print("peaks = ", peaks) idx=len(v) - if len(indexes)>=2: - idx=indexes[1]+1 + if len(peaks[0])>=2: + idx=peaks[0][1] w = [*np.linspace(100, 50, idx) , *np.linspace(0, 0, len(v)-idx)] + # DEBUG print("w = ", w) else: raise AssertionError("weights option should be either 'flat, 'linear' or '2-peaks-linear'") @@ -71,8 +77,6 @@ def compute_weighted_total(values, aggregate_method, aggregate_weights): raise AssertionError("method option should be either 'avg' or 'max'") # DEBUG - # print(" ", masked_values) - # print(" x ", w) # print(" = ", round(total,2)) return round(total,2) @@ -140,6 +144,7 @@ def compute_threshold(metric, aggregate_method, aggregate_weights): history_df = pd.merge(compare_df, history_df, how="outer", on=["benchmark", "symbol"]) for i, row in history_df.iterrows(): + # DEBUG print("\n============ ", row["benchmark"], row["symbol"]) total = compute_weighted_total(history_df.loc[i], aggregate_method, aggregate_weights) history_df.loc[i, metric+'_variation_total'] = total |