diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-04-04 15:11:31 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-04-04 15:11:31 +0200 |
commit | 398f3d6d86433c32a5b69b3581b4a32e5d22410d (patch) | |
tree | 3afe91fcaa42e8e75837c5d28f77fa3576761756 /lib/dfatool.py | |
parent | 418111ca15c3949a9a29b5ebbe908571ed601e1b (diff) |
split up rel_energy inte relative energy to previous state and to next state
Diffstat (limited to 'lib/dfatool.py')
-rwxr-xr-x | lib/dfatool.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/dfatool.py b/lib/dfatool.py index 8a07b50..994f8a2 100755 --- a/lib/dfatool.py +++ b/lib/dfatool.py @@ -21,12 +21,23 @@ def is_numeric(n): except ValueError: return False +def append_if_set(aggregate, data, key): + if key in data: + aggregate.append(data[key]) + +def mean_or_none(arr): + if len(arr): + return np.mean(arr) + return -1 + def aggregate_measures(aggregate, actual): aggregate_array = np.array([aggregate] * len(actual)) return regression_measures(aggregate_array, np.array(actual)) def regression_measures(predicted, actual): deviations = predicted - actual + if len(deviations) == 0: + return {} measures = { 'mae' : np.mean(np.abs(deviations), dtype=np.float64), 'msd' : np.mean(deviations**2, dtype=np.float64), @@ -281,8 +292,14 @@ class MIMOSA: if isa == 'transition': # subtract average power of previous state # (that is, the state from which this transition originates) - data['uW_mean_delta'] = data['uW_mean'] - iterdata[-1]['uW_mean'] + data['uW_mean_delta_prev'] = data['uW_mean'] - iterdata[-1]['uW_mean'] + # placeholder to avoid extra cases in the analysis + data['uW_mean_delta_next'] = data['uW_mean'] data['timeout'] = iterdata[-1]['us'] + elif len(iterdata) > 0: + # subtract average power of next state + # (the state into which this transition leads) + iterdata[-1]['uW_mean_delta_next'] = iterdata[-1]['uW_mean'] - data['uW_mean'] iterdata.append(data) |