diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2021-03-03 09:36:43 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2021-03-03 09:36:43 +0100 |
commit | f33c69dcaf24ecc7e039dec83a4a5c74908da52f (patch) | |
tree | df5ada7af874161f70d866b4f8c1d878f1a373cc /lib | |
parent | d0d3f335739d9333f15ede487574f78f1eb5e638 (diff) |
Remove ModelInfo; add info to ModelFunction instead
Diffstat (limited to 'lib')
-rw-r--r-- | lib/functions.py | 50 | ||||
-rw-r--r-- | lib/model.py | 8 | ||||
-rw-r--r-- | lib/parameters.py | 11 |
3 files changed, 19 insertions, 50 deletions
diff --git a/lib/functions.py b/lib/functions.py index f3e5ac8..663b65e 100644 --- a/lib/functions.py +++ b/lib/functions.py @@ -153,11 +153,6 @@ class NormalizationFunction: return self._function(param_value) -class ModelInfo: - def __init__(self): - self.error = None - - class ModelFunction: def __init__(self): pass @@ -194,17 +189,6 @@ class StaticFunction(ModelFunction): return {"type": "static", "value": self.value} -class StaticInfo(ModelInfo): - def __init__(self, data): - super() - self.mean = np.mean(data) - self.median = np.median(data) - self.std = np.std(data) - - def to_json(self): - return "FIXME" - - class SplitFunction(ModelFunction): def __init__(self, param_index, child): self.param_index = param_index @@ -237,16 +221,6 @@ class SplitFunction(ModelFunction): } -class SplitInfo(ModelInfo): - def __init__(self, param_index, child): - super() - self.param_index = param_index - self.child = child - - def to_json(self): - return "FIXME" - - class AnalyticFunction(ModelFunction): """ A multi-dimensional model function, generated from a string, which can be optimized using regression. @@ -256,7 +230,14 @@ class AnalyticFunction(ModelFunction): packet length. """ - def __init__(self, function_str, parameters, num_args, regression_args=None): + def __init__( + self, + function_str, + parameters, + num_args, + regression_args=None, + fit_by_param=None, + ): """ Create a new AnalyticFunction object from a function string. @@ -281,6 +262,7 @@ class AnalyticFunction(ModelFunction): rawfunction = function_str self._dependson = [False] * (len(parameters) + num_args) self.fit_success = False + self.fit_by_param = fit_by_param if type(function_str) == str: num_vars_re = re.compile(r"regression_arg\(([0-9]+)\)") @@ -440,16 +422,6 @@ class AnalyticFunction(ModelFunction): } -class AnalyticInfo(ModelInfo): - def __init__(self, fit_result, function): - super() - self.fit_result = fit_result - self.function = function - - def to_json(self): - return "FIXME" - - class analytic: """ Utilities for analytic description of parameter-dependent model attributes and regression analysis. @@ -644,4 +616,6 @@ class analytic: "parameter", function_item[0], function_item[1]["best"] ) ) - return AnalyticFunction(buf, parameter_names, num_args) + return AnalyticFunction( + buf, parameter_names, num_args, fit_by_param=fit_results + ) diff --git a/lib/model.py b/lib/model.py index be63a8a..ccbf719 100644 --- a/lib/model.py +++ b/lib/model.py @@ -4,7 +4,7 @@ import logging import numpy as np import os from .automata import PTA, ModelAttribute -from .functions import StaticInfo +from .functions import StaticFunction from .parameters import ParallelParamStats from .paramfit import ParallelParamFit from .utils import soft_cast_int, by_name_to_by_param, regression_measures @@ -255,10 +255,10 @@ class AnalyticModel: def model_getter(name, key, **kwargs): model_function = self.attr_by_name[name][key].model_function - model_info = self.attr_by_name[name][key].model_info + model_info = self.attr_by_name[name][key].model_function # shortcut - if type(model_info) is StaticInfo: + if type(model_info) is StaticFunction: return static_model[name][key] if "arg" in kwargs and "param" in kwargs: @@ -271,7 +271,7 @@ class AnalyticModel: def info_getter(name, key): try: - return self.attr_by_name[name][key].model_info + return self.attr_by_name[name][key].model_function except KeyError: return None diff --git a/lib/parameters.py b/lib/parameters.py index fa01804..1cad7a5 100644 --- a/lib/parameters.py +++ b/lib/parameters.py @@ -594,7 +594,6 @@ class ModelAttribute: # The best model we have. May be Static, Split, or Param (and later perhaps Substate) self.model_function = None - self.model_info = None def __repr__(self): mean = np.mean(self.data) @@ -605,7 +604,6 @@ class ModelAttribute: "paramNames": self.param_names, "argCount": self.arg_count, "modelFunction": self.model_function.to_json(), - "modelInfo": self.model_info.to_json(), } return ret @@ -784,21 +782,19 @@ class ModelAttribute: for param_value, child in child_by_param_value.items(): child.set_data_from_paramfit(paramfit, prefix + (param_value,)) function_child[param_value] = child.model_function - info_child[param_value] = child.model_info self.model_function = df.SplitFunction(split_param_index, function_child) - self.model_info = df.SplitInfo(split_param_index, info_child) def set_data_from_paramfit_this(self, paramfit, prefix): fit_result = paramfit.get_result((self.name, self.attr) + prefix) self.model_function = df.StaticFunction(self.median) - self.model_info = df.StaticInfo(self.data) if self.function_override is not None: function_str = self.function_override - x = df.AnalyticFunction(function_str, self.param_names, self.arg_count) + x = df.AnalyticFunction( + function_str, self.param_names, self.arg_count, fit_by_param=fit_result + ) x.fit(self.by_param) if x.fit_success: self.model_function = x - self.model_info = df.AnalyticInfo(fit_result, x) elif os.getenv("DFATOOL_NO_PARAM"): pass elif len(fit_result.keys()): @@ -809,4 +805,3 @@ class ModelAttribute: if x.fit_success: self.model_function = x - self.model_info = df.AnalyticInfo(fit_result, x) |