From f4af48cf398b92b17a9a718416cf18ea1d956375 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 11 Dec 2019 07:51:17 +0100 Subject: PTA: add attribute error measures to JSON model --- lib/automata.py | 27 +++++++++++++++++++++++---- lib/dfatool.py | 6 ++++-- 2 files changed, 27 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/automata.py b/lib/automata.py index 38a2645..f1f2909 100755 --- a/lib/automata.py +++ b/lib/automata.py @@ -14,9 +14,11 @@ def _dict_to_list(input_dict: dict) -> list: class PTAAttribute: - def __init__(self, value: float = 0, function: AnalyticFunction = None): + def __init__(self, value: float = 0, function: AnalyticFunction = None, value_error=None, function_error=None): self.value = value self.function = function + self.value_error = value_error + self.function_error = function_error def __repr__(self): if self.function is not None: @@ -30,13 +32,15 @@ class PTAAttribute: def to_json(self): ret = { - 'static': self.value + 'static': self.value, + 'static_error': self.value_error, } if self.function: ret['function'] = { 'raw': self.function._model_str, 'regression_args': list(self.function._regression_args) } + ret['function_error'] = self.function_error return ret @classmethod @@ -954,13 +958,17 @@ class PTA: return total_energy, total_duration, state, param_dict - def update(self, static_model, param_model): + def update(self, static_model, param_model, static_error=None, analytic_error=None): for state in self.state.values(): if state.name != 'UNINITIALIZED': try: state.power.value = static_model(state.name, 'power') + if static_error is not None: + state.power.value_error = static_error[state.name]['power'] if param_model(state.name, 'power'): state.power.function = param_model(state.name, 'power')['function'] + if analytic_error is not None: + state.power.function_error = analytic_error[state.name]['power'] except KeyError: print('[W] skipping model update of state {} due to missing data'.format(state.name)) pass @@ -969,13 +977,24 @@ class PTA: transition.duration.value = static_model(transition.name, 'duration') if param_model(transition.name, 'duration'): transition.duration.function = param_model(transition.name, 'duration')['function'] + if analytic_error is not None: + transition.duration.function_error = analytic_error[transition.name]['duration'] transition.energy.value = static_model(transition.name, 'energy') if param_model(transition.name, 'energy'): transition.energy.function = param_model(transition.name, 'energy')['function'] + if analytic_error is not None: + transition.energy.function_error = analytic_error[transition.name]['energy'] if transition.is_interrupt: transition.timeout.value = static_model(transition.name, 'timeout') if param_model(transition.name, 'timeout'): transition.timeout.function = param_model(transition.name, 'timeout')['function'] + if analytic_error is not None: + transition.timeout.function_error = analytic_error[transition.name]['timeout'] + + if static_error is not None: + transition.duration.value_error = static_error[transition.name]['duration'] + transition.energy.value_error = static_error[transition.name]['energy'] + transition.timeout.value_error = static_error[transition.name]['timeout'] except KeyError: - print('[W] skipping model update of transition {} due to missing data'.format(state.name)) + print('[W] skipping model update of transition {} due to missing data'.format(transition.name)) pass diff --git a/lib/dfatool.py b/lib/dfatool.py index 9583d73..607028e 100644 --- a/lib/dfatool.py +++ b/lib/dfatool.py @@ -2025,8 +2025,10 @@ class PTAModel: def to_json(self): static_model = self.get_static() - _, param_info = self.get_fitted() - self.pta.update(static_model, param_info) + static_quality = self.assess(static_model) + param_model, param_info = self.get_fitted() + analytic_quality = self.assess(param_model) + self.pta.update(static_model, param_info, static_error=static_quality['by_name'], analytic_error=analytic_quality['by_name']) return self.pta.to_json() def states(self): -- cgit v1.2.3