From 2b479dc993b1d73d236d96a4d57bb69159b1603e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 7 Feb 2019 18:13:34 +0100 Subject: AnalyticModel: Calculate by_param from by_name --- lib/dfatool.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/dfatool.py b/lib/dfatool.py index 42adfc7..e9af2af 100755 --- a/lib/dfatool.py +++ b/lib/dfatool.py @@ -225,6 +225,27 @@ class KeysightCSV: currents[i] = float(row[2]) * -1 return timestamps, currents +def by_name_to_by_param(by_name): + """ + Convert aggregation by name to aggregation by name and parameter values. + """ + by_param = dict() + for name in by_name.keys(): + for i, parameters in enumerate(by_name[name]['param']): + param_key = (name, tuple(parameters)) + if param_key not in by_param: + by_param[param_key] = dict() + for key in by_name[name].keys(): + by_param[param_key][key] = list() + by_param[param_key]['attributes'] = by_name[name]['attributes'] + # special case for PTA models + if 'isa' in by_name[name]: + by_param[param_key]['isa'] = by_name[name]['isa'] + for attribute in by_name[name]['attributes']: + by_param[param_key][attribute].append(by_name[name][attribute][i]) + return by_param + + def _xv_partitions_kfold(length, num_slices): pairs = [] indexes = np.arange(length) @@ -812,11 +833,11 @@ class AnalyticModel: assess -- calculate model quality """ - def __init__(self, by_name, by_param, parameters, verbose = True): + def __init__(self, by_name, parameters, verbose = True): """Create a new AnalyticModel and compute parameter statistics.""" self.cache = dict() self.by_name = by_name - self.by_param = by_param + self.by_param = by_name_to_by_param(by_name) self.names = sorted(by_name.keys()) self.parameters = sorted(parameters) self.verbose = verbose -- cgit v1.2.3