summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2025-05-22 11:29:15 +0200
committerBirte Kristina Friesel <birte.friesel@uos.de>2025-05-22 11:29:15 +0200
commitaca042bf6ac5cd8410b108e4397ae4c10ff67427 (patch)
tree1363e05ababafa9179e4b5bd0a10eaddd47f8d77 /lib
parent1d4950905fa13fd3aacbd22ed24ce880b2292faa (diff)
Featured Automata learner: now with actual guards. whoop whoop!
Diffstat (limited to 'lib')
-rw-r--r--lib/functions.py17
-rw-r--r--lib/utils.py8
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/functions.py b/lib/functions.py
index 187e6ff..35b04ef 100644
--- a/lib/functions.py
+++ b/lib/functions.py
@@ -466,6 +466,23 @@ class SplitFunction(ModelFunction):
)
return hyper
+ # SplitFunction only
+ def flatten(self):
+ paths = list()
+ for param_value, subtree in self.child.items():
+ if type(subtree) is SplitFunction:
+ for path, value in subtree.flatten():
+ path = [(self.param_name, param_value)] + path
+ paths.append((path, value))
+ elif type(subtree) is StaticFunction:
+ path = [(self.param_name, param_value)]
+ paths.append((path, subtree.value))
+ else:
+ raise RuntimeError(
+ "flatten is only implemented for RMTs with constant leaves"
+ )
+ return paths
+
@classmethod
def from_json(cls, data):
assert data["type"] == "split"
diff --git a/lib/utils.py b/lib/utils.py
index c148426..48a29d8 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -325,6 +325,14 @@ def param_dict_to_str(param_dict):
return " ".join(ret)
+def param_str_to_dict(param_str):
+ ret = dict()
+ for param_pair in param_str.split():
+ key, value = param_pair.split("=")
+ ret[key] = soft_cast_int_or_float(value)
+ return ret
+
+
def observations_enum_to_bool(observations: list, kconfig=False):
"""
Convert enum / categorical observations to boolean-only ones.