summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/analyze-archive.py57
-rwxr-xr-xlib/dfatool.py22
2 files changed, 48 insertions, 31 deletions
diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py
index 81d6f54..ca043c5 100755
--- a/bin/analyze-archive.py
+++ b/bin/analyze-archive.py
@@ -3,6 +3,31 @@
import sys
from dfatool import EnergyModel, RawData
+def print_model_quality(results):
+ for state_or_tran in results.keys():
+ print()
+ for key, result in results[state_or_tran].items():
+ if 'smape' in result:
+ print('{:20s} {:15s} {:.2f}% / {:.0f}'.format(
+ state_or_tran, key, result['smape'], result['mae']))
+ else:
+ print('{:20s} {:15s} {:.0f}'.format(
+ state_or_tran, key, result['mae']))
+
+
+def model_quality_table(result_lists):
+ for state_or_tran in result_lists[0].keys():
+ for key in result_lists[0][state_or_tran].keys():
+ buf = '{:20s} {:15s}'.format(state_or_tran, key)
+ for results in result_lists:
+ buf += ' ||| '
+ result = results[state_or_tran][key]
+ if 'smape' in result:
+ buf += '{:6.2f}% / {:9.0f}'.format(result['smape'], result['mae'])
+ else:
+ buf += '{:6} {:9.0f}'.format('', result['mae'])
+ print(buf)
+
if __name__ == '__main__':
filenames = sys.argv[1:]
raw_data = RawData(filenames)
@@ -10,8 +35,8 @@ if __name__ == '__main__':
preprocessed_data = raw_data.get_preprocessed_data()
model = EnergyModel(preprocessed_data)
- #print('--- simple static model ---')
- #static_model = model.get_static()
+ print('--- simple static model ---')
+ static_model = model.get_static()
#for state in model.states():
# print('{:10s}: {:.0f} µW ({:.2f})'.format(
# state,
@@ -31,21 +56,25 @@ if __name__ == '__main__':
# model.generic_param_dependence_ratio(trans, 'rel_energy_prev'),
# model.generic_param_dependence_ratio(trans, 'rel_energy_next')))
# print('{:10s}: {:.0f} µs'.format(trans, static_model(trans, 'duration')))
- #model.assess(static_model)
+ static_quality = model.assess(static_model)
- #print('--- LUT ---')
- #lut_model = model.get_param_lut()
- #model.assess(lut_model)
+ print('--- LUT ---')
+ lut_model = model.get_param_lut()
+ lut_quality = model.assess(lut_model)
print('--- param model ---')
param_model, param_info = model.get_fitted()
- for state in model.states():
- for attribute in ['power']:
- if param_info(state, attribute):
- print('{:10s}: {}'.format(state, param_info(state, attribute)['function']._model_str))
- for trans in model.transitions():
- for attribute in ['energy', 'rel_energy_prev', 'rel_energy_next', 'duration', 'timeout']:
- if param_info(trans, attribute):
- print('{:10s}: {:10s}: {}'.format(trans, attribute, param_info(trans, attribute)['function']._model_str))
+ #for state in model.states():
+ # for attribute in ['power']:
+ # if param_info(state, attribute):
+ # print('{:10s}: {}'.format(state, param_info(state, attribute)['function']._model_str))
+ # print('{:10s} {}'.format('', param_info(state, attribute)['function']._regression_args))
+ #for trans in model.transitions():
+ # for attribute in ['energy', 'rel_energy_prev', 'rel_energy_next', 'duration', 'timeout']:
+ # if param_info(trans, attribute):
+ # print('{:10s}: {:10s}: {}'.format(trans, attribute, param_info(trans, attribute)['function']._model_str))
+ # print('{:10s} {:10s} {}'.format('', '', param_info(trans, attribute)['function']._regression_args))
+ analytic_quality = model.assess(param_model)
+ model_quality_table([static_quality, lut_quality, analytic_quality])
sys.exit(0)
diff --git a/lib/dfatool.py b/lib/dfatool.py
index 3387de0..1699a1d 100755
--- a/lib/dfatool.py
+++ b/lib/dfatool.py
@@ -798,31 +798,19 @@ class EnergyModel:
return self._parameter_names
def assess(self, model_function):
+ results = {}
for name, elem in sorted(self.by_name.items()):
- print('{}:'.format(name))
+ results[name] = {}
if elem['isa'] == 'state':
predicted_data = np.array(list(map(lambda i: model_function(name, 'power', param=elem['param'][i]), range(len(elem['power'])))))
measures = regression_measures(predicted_data, elem['power'])
- if 'smape' in measures:
- print(' power: {:.2f}% / {:.0f} µW'.format(
- measures['smape'], measures['mae']
- ))
- else:
- print(' power: {:.0f} µW'.format(
- measures['mae']
- ))
+ results[name]['power'] = measures
else:
for key in ['duration', 'energy', 'rel_energy_prev', 'rel_energy_next', 'timeout']:
predicted_data = np.array(list(map(lambda i: model_function(name, key, param=elem['param'][i]), range(len(elem[key])))))
measures = regression_measures(predicted_data, elem[key])
- if 'smape' in measures:
- print(' {:15s}: {:.2f}% / {:.0f}'.format(
- key, measures['smape'], measures['mae']
- ))
- else:
- print(' {:15s}: {:.0f}'.format(
- key, measures['mae']
- ))
+ results[name][key] = measures
+ return results