summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-07-26 07:47:53 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-07-26 07:47:53 +0200
commitb0e65124da0330713cd72c42254c153974b710eb (patch)
tree6db0966df5602abadfe5cd5a57f893c08b19be6f
parent8bdf2472791b61f0d6e5f150ef59ca7c68a8c9bb (diff)
add parameter normalization support to YAML DFA models
-rwxr-xr-xlib/automata.py5
-rw-r--r--lib/functions.py12
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/automata.py b/lib/automata.py
index 6437839..3220d81 100755
--- a/lib/automata.py
+++ b/lib/automata.py
@@ -1,6 +1,6 @@
"""Classes and helper functions for PTA and other automata."""
-from functions import AnalyticFunction
+from functions import AnalyticFunction, NormalizationFunction
import itertools
def _dict_to_list(input_dict: dict) -> list:
@@ -310,6 +310,9 @@ class PTA:
if parameter in self.parameter_normalization:
if 'enum' in self.parameter_normalization[parameter] and value in self.parameter_normalization[parameter]['enum']:
normalized_param[parameter] = self.parameter_normalization[parameter]['enum'][value]
+ if 'formula' in self.parameter_normalization[parameter]:
+ normalization_formula = NormalizationFunction(self.parameter_normalization[parameter]['formula'])
+ normalized_param[parameter] = normalization_formula.eval(value)
return normalized_param
@classmethod
diff --git a/lib/functions.py b/lib/functions.py
index ebeb2a2..c30a5f7 100644
--- a/lib/functions.py
+++ b/lib/functions.py
@@ -87,6 +87,18 @@ class ParamFunction:
"""
return self._param_function(P, X) - y
+class NormalizationFunction:
+ """
+ Hi
+ """
+
+ def __init__(self, function_str):
+ self._function_str = function_str
+ self._function = eval('lambda param: ' + function_str)
+
+ def eval(self, param_value):
+ return self._function(param_value)
+
class AnalyticFunction:
"""
A multi-dimensional model function, generated from a string, which can be optimized using regression.