diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-11-21 08:17:04 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-11-21 08:17:04 +0100 |
commit | 0d4616db3975919c46b73cfbd4c6054b94e55aa6 (patch) | |
tree | ce3b4eaadb62583d155b804113008794ab2535fd /bin | |
parent | 68c54f846d941ab2bb7367c5ac5dad091b5fde9f (diff) |
flake8
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/analyze-archive.py | 45 | ||||
-rwxr-xr-x | bin/analyze-timing.py | 30 | ||||
-rwxr-xr-x | bin/analyze.py | 40 |
3 files changed, 50 insertions, 65 deletions
diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py index 787510d..8470ab6 100755 --- a/bin/analyze-archive.py +++ b/bin/analyze-archive.py @@ -83,13 +83,14 @@ import plotter import re import sys from dfatool import PTAModel, RawData, pta_trace_to_aggregate -from dfatool import soft_cast_int, is_numeric, gplearn_to_function +from dfatool import gplearn_to_function from dfatool import CrossValidator from utils import filter_aggregate_by_param from automata import PTA opts = {} + def print_model_quality(results): for state_or_tran in results.keys(): print() @@ -101,12 +102,14 @@ def print_model_quality(results): print('{:20s} {:15s} {:.0f}'.format( state_or_tran, key, result['mae'])) + def format_quality_measures(result): if 'smape' in result: return '{:6.2f}% / {:9.0f}'.format(result['smape'], result['mae']) else: return '{:6} {:9.0f}'.format('', result['mae']) + def model_quality_table(result_lists, info_list): for state_or_tran in result_lists[0]['by_name'].keys(): for key in result_lists[0]['by_name'][state_or_tran].keys(): @@ -114,13 +117,14 @@ def model_quality_table(result_lists, info_list): for i, results in enumerate(result_lists): info = info_list[i] buf += ' ||| ' - if info == None or info(state_or_tran, key): + if info is None or info(state_or_tran, key): result = results['by_name'][state_or_tran][key] buf += format_quality_measures(result) else: buf += '{:6}----{:9}'.format('', '') print(buf) + def model_summary_table(result_list): buf = 'transition duration' for results in result_list: @@ -171,6 +175,7 @@ def print_text_model_data(model, pm, pq, lm, lq, am, ai, aq): for arg_index in range(model._num_args[state_or_tran]): print('{} {} {:d} {:.8f}'.format(state_or_tran, attribute, arg_index, model.stats.arg_dependence_ratio(state_or_tran, attribute, arg_index))) + def print_html_model_data(model, pm, pq, lm, lq, am, ai, aq): state_attributes = model.attributes(model.states()[0]) @@ -204,6 +209,7 @@ def print_html_model_data(model, pm, pq, lm, lq, am, ai, aq): print('</tr>') print('</table>') + if __name__ == '__main__': ignored_trace_indexes = [] @@ -282,10 +288,10 @@ if __name__ == '__main__': filter_aggregate_by_param(by_name, parameters, opts['filter-param']) model = PTAModel(by_name, parameters, arg_count, - traces = preprocessed_data, - discard_outliers = discard_outliers, - function_override = function_override, - pta = pta) + traces=preprocessed_data, + discard_outliers=discard_outliers, + function_override=function_override, + pta=pta) if xv_method: xv = CrossValidator(PTAModel, by_name, parameters, arg_count) @@ -299,8 +305,8 @@ if __name__ == '__main__': if 'plot-unparam' in opts: for kv in opts['plot-unparam'].split(';'): state_or_trans, attribute, ylabel = kv.split(':') - fname = 'param_y_{}_{}.pdf'.format(state_or_trans,attribute) - plotter.plot_y(model.by_name[state_or_trans][attribute], xlabel = 'measurement #', ylabel = ylabel, output = fname) + fname = 'param_y_{}_{}.pdf'.format(state_or_trans, attribute) + plotter.plot_y(model.by_name[state_or_trans][attribute], xlabel='measurement #', ylabel=ylabel, output=fname) if len(show_models): print('--- simple static model ---') @@ -361,7 +367,7 @@ if __name__ == '__main__': if len(show_models): print('--- param model ---') - param_model, param_info = model.get_fitted(safe_functions_enabled = safe_functions_enabled) + param_model, param_info = model.get_fitted(safe_functions_enabled=safe_functions_enabled) if 'paramdetection' in show_models or 'all' in show_models: for state in model.states_and_transitions(): @@ -377,7 +383,7 @@ if __name__ == '__main__': print('{:10s} {:10s} {:10s} stddev {:f}'.format( state, attribute, param, model.stats.stats[state][attribute]['std_by_param'][param] )) - if info != None: + if info is not None: for param_name in sorted(info['fit_result'].keys(), key=str): param_fit = info['fit_result'][param_name]['results'] for function_type in sorted(param_fit.keys()): @@ -413,10 +419,20 @@ if __name__ == '__main__': if 'table' in show_quality or 'all' in show_quality: model_quality_table([static_quality, analytic_quality, lut_quality], [None, param_info, None]) + if 'overall' in show_quality or 'all' in show_quality: - print('overall MAE of static model: {} µW'.format(model.assess_states(static_model))) - print('overall MAE of param model: {} µW'.format(model.assess_states(param_model))) - print('overall MAE of LUT model: {} µW'.format(model.assess_states(lut_model))) + print('overall static/param/lut MAE assuming equal state distribution:') + print(' {:6.1f} / {:6.1f} / {:6.1f} µW'.format( + model.assess_states(static_model), + model.assess_states(param_model), + model.assess_states(lut_model))) + print('overall static/param/lut MAE assuming 95% STANDBY1:') + distrib = {'STANDBY1': 0.95, 'POWERDOWN': 0.03, 'TX': 0.01, 'RX': 0.01} + print(' {:6.1f} / {:6.1f} / {:6.1f} µW'.format( + model.assess_states(static_model, distribution=distrib), + model.assess_states(param_model, distribution=distrib), + model.assess_states(lut_model, distribution=distrib))) + if 'summary' in show_quality or 'all' in show_quality: model_summary_table([model.assess_on_traces(static_model), model.assess_on_traces(param_model), model.assess_on_traces(lut_model)]) @@ -435,7 +451,6 @@ if __name__ == '__main__': sys.exit(1) json_model = model.to_json() with open(opts['export-energymodel'], 'w') as f: - json.dump(json_model, f, indent = 2, sort_keys = True) - + json.dump(json_model, f, indent=2, sort_keys=True) sys.exit(0) diff --git a/bin/analyze-timing.py b/bin/analyze-timing.py index 6c84a67..9a3aa41 100755 --- a/bin/analyze-timing.py +++ b/bin/analyze-timing.py @@ -79,14 +79,14 @@ import plotter import re import sys from dfatool import AnalyticModel, TimingData, pta_trace_to_aggregate -from dfatool import soft_cast_int, is_numeric, gplearn_to_function +from dfatool import gplearn_to_function from dfatool import CrossValidator from utils import filter_aggregate_by_param from parameters import prune_dependent_parameters -import utils opts = {} + def print_model_quality(results): for state_or_tran in results.keys(): print() @@ -98,12 +98,14 @@ def print_model_quality(results): print('{:20s} {:15s} {:.0f}'.format( state_or_tran, key, result['mae'])) + def format_quality_measures(result): if 'smape' in result: return '{:6.2f}% / {:9.0f}'.format(result['smape'], result['mae']) else: return '{:6} {:9.0f}'.format('', result['mae']) + def model_quality_table(result_lists, info_list): for state_or_tran in result_lists[0]['by_name'].keys(): for key in result_lists[0]['by_name'][state_or_tran].keys(): @@ -111,7 +113,7 @@ def model_quality_table(result_lists, info_list): for i, results in enumerate(result_lists): info = info_list[i] buf += ' ||| ' - if info == None or info(state_or_tran, key): + if info is None or info(state_or_tran, key): result = results['by_name'][state_or_tran][key] buf += format_quality_measures(result) else: @@ -136,6 +138,7 @@ def print_text_model_data(model, pm, pq, lm, lq, am, ai, aq): for arg_index in range(model._num_args[state_or_tran]): print('{} {} {:d} {:.8f}'.format(state_or_tran, attribute, arg_index, model.stats.arg_dependence_ratio(state_or_tran, attribute, arg_index))) + if __name__ == '__main__': ignored_trace_indexes = [] @@ -215,7 +218,7 @@ if __name__ == '__main__': filter_aggregate_by_param(by_name, parameters, opts['filter-param']) - model = AnalyticModel(by_name, parameters, arg_count, use_corrcoef = opts['corrcoef'], function_override = function_override) + model = AnalyticModel(by_name, parameters, arg_count, use_corrcoef=opts['corrcoef'], function_override=function_override) if xv_method: xv = CrossValidator(AnalyticModel, by_name, parameters, arg_count) @@ -229,8 +232,8 @@ if __name__ == '__main__': if 'plot-unparam' in opts: for kv in opts['plot-unparam'].split(';'): state_or_trans, attribute, ylabel = kv.split(':') - fname = 'param_y_{}_{}.pdf'.format(state_or_trans,attribute) - plotter.plot_y(model.by_name[state_or_trans][attribute], xlabel = 'measurement #', ylabel = ylabel) + fname = 'param_y_{}_{}.pdf'.format(state_or_trans, attribute) + plotter.plot_y(model.by_name[state_or_trans][attribute], xlabel='measurement #', ylabel=ylabel) if len(show_models): print('--- simple static model ---') @@ -247,6 +250,15 @@ if __name__ == '__main__': print('{:24s} co-dependencies: {:s}'.format('', ', '.join(model.stats.codependent_parameters(trans, 'duration', param)))) for param_dict in model.stats.codependent_parameter_value_dicts(trans, 'duration', param): print('{:24s} parameter-aware for {}'.format('', param_dict)) + # import numpy as np + # safe_div = np.vectorize(lambda x,y: 0. if x == 0 else 1 - x/y) + # ratio_by_value = safe_div(model.stats.stats['write']['duration']['lut_by_param_values']['max_retry_count'], model.stats.stats['write']['duration']['std_by_param_values']['max_retry_count']) + # err_mode = np.seterr('warn') + # dep_by_value = ratio_by_value > 0.5 + # np.seterr(**err_mode) + # Eigentlich sollte hier ein paar mal True stehen, ist aber nicht so... + # und warum ist da eine non-power-of-two Zahl von True-Einträgen in der Matrix? 3 stück ist komisch... + # print(dep_by_value) if xv_method == 'montecarlo': static_quality = xv.montecarlo(lambda m: m.get_static(), xv_count) @@ -265,7 +277,7 @@ if __name__ == '__main__': if len(show_models): print('--- param model ---') - param_model, param_info = model.get_fitted(safe_functions_enabled = safe_functions_enabled) + param_model, param_info = model.get_fitted(safe_functions_enabled=safe_functions_enabled) if 'paramdetection' in show_models or 'all' in show_models: for transition in model.names: @@ -289,7 +301,7 @@ if __name__ == '__main__': )) print('{:10s} {:10s} dependence on arg{:d}: {:.2f}'.format( transition, attribute, i, model.stats.arg_dependence_ratio(transition, attribute, i))) - if info != None: + if info is not None: for param_name in sorted(info['fit_result'].keys(), key=str): param_fit = info['fit_result'][param_name]['results'] for function_type in sorted(param_fit.keys()): @@ -325,6 +337,4 @@ if __name__ == '__main__': function = None plotter.plot_param(model, state_or_trans, attribute, model.param_index(param_name), extra_function=function) - - sys.exit(0) diff --git a/bin/analyze.py b/bin/analyze.py deleted file mode 100755 index 57803fe..0000000 --- a/bin/analyze.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python3 - -import json -import numpy as np -import os -from scipy.cluster.vq import kmeans2 -import struct -import sys -import tarfile -from dfatool import running_mean, MIMOSA - -voltage = float(sys.argv[1]) -shunt = float(sys.argv[2]) -filename = sys.argv[3] - -mim = MIMOSA(voltage, shunt) - -charges, triggers = mim.load_data(filename) -trigidx = mim.trigger_edges(triggers) -triggers = [] -cal_edges = mim.calibration_edges(running_mean(mim.currents_nocal(charges[0:trigidx[0]]), 10)) -calfunc, caldata = mim.calibration_function(charges, cal_edges) -vcalfunc = np.vectorize(calfunc, otypes=[np.float64]) - -json_out = { - 'triggers' : len(trigidx), - 'first_trig' : trigidx[0] * 10, - 'calibration' : caldata, - 'trace' : mim.analyze_states(charges, trigidx, vcalfunc) -} - -basename, _ = os.path.splitext(filename) - -# TODO also look for interesting gradients inside each state - -with open(basename + ".json", "w") as f: - json.dump(json_out, f) - f.close() - -#print(kmeans2(charges[:firstidx], np.array([130 * ua_step, 3.6 / 987 * 1000000, 3.6 / 99300 * 1000000]))) |