From fa404613f19fe08173f1f44961ba72ed1ea9554c Mon Sep 17 00:00:00 2001 From: Sebastian Echeverria Date: Thu, 3 Oct 2024 15:40:09 -0400 Subject: [PATCH] Demo: updated validator to use new method to more easily build conditions --- demo/scenarios/values/multiple_accuracy.py | 4 +-- demo/scenarios/values/multiple_ranksums.py | 4 +-- .../values/operational_performance.py | 28 ------------------- demo/scenarios/values/ranksums.py | 4 +-- demo/scenarios/values/string.py | 8 ++---- 5 files changed, 5 insertions(+), 43 deletions(-) delete mode 100644 demo/scenarios/values/operational_performance.py diff --git a/demo/scenarios/values/multiple_accuracy.py b/demo/scenarios/values/multiple_accuracy.py index ff284589..c1e02d40 100644 --- a/demo/scenarios/values/multiple_accuracy.py +++ b/demo/scenarios/values/multiple_accuracy.py @@ -14,9 +14,7 @@ class MultipleAccuracy(Array): @classmethod def all_accuracies_more_or_equal_than(cls, threshold: float) -> Condition: """Checks if the accuracy for multiple populations is fair by checking if all of them are over the given threshold.""" - condition: Condition = Condition( - "all_accuracies_more_than", - [threshold], + condition: Condition = Condition.build_condition( lambda value: Success( f"All accuracies are equal to or over threshold {threshold}" ) diff --git a/demo/scenarios/values/multiple_ranksums.py b/demo/scenarios/values/multiple_ranksums.py index 9c8fb6a0..66f869d6 100644 --- a/demo/scenarios/values/multiple_ranksums.py +++ b/demo/scenarios/values/multiple_ranksums.py @@ -47,9 +47,7 @@ def deserialize( @classmethod def all_p_values_greater_or_equal_than(cls, threshold: float) -> Condition: """Checks if the p-value for multiple ranksums is below given threshold.""" - condition: Condition = Condition( - "all_p_values_greater_or_equal_than", - [threshold], + condition: Condition = Condition.build_condition( lambda value: Success( f"All p-values are equal to or over threshold {value.get_total_p_value_threshold(threshold)}" ) diff --git a/demo/scenarios/values/operational_performance.py b/demo/scenarios/values/operational_performance.py deleted file mode 100644 index 6bbf5fbd..00000000 --- a/demo/scenarios/values/operational_performance.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -Implementation of MultipleAccuracy value. -""" -from __future__ import annotations - -from mlte.spec.condition import Condition -from mlte.validation.result import Failure, Success -from mlte.value.types.array import Array - - -class OperationalPerformance(Array): - """An array with multiple accuracies.""" - - @classmethod - def inference_time_less_than(cls, threshold: float) -> Condition: - """Checks if the data processing and inference time are less than a fixed time threshold.""" - condition: Condition = Condition( - "inference_less_than", - [threshold], - lambda value: Success( - f"All accuracies are equal to or over threshold {threshold}" - ) - if sum(g >= threshold for g in value.array) == len(value.array) - else Failure( - f"One or more accuracies are below threshold {threshold}: {value.array}" - ), - ) - return condition diff --git a/demo/scenarios/values/ranksums.py b/demo/scenarios/values/ranksums.py index 9bae360e..fd21c3d9 100644 --- a/demo/scenarios/values/ranksums.py +++ b/demo/scenarios/values/ranksums.py @@ -13,9 +13,7 @@ class RankSums(Array): @classmethod def p_value_greater_or_equal_to(cls, threshold: float) -> Condition: - condition: Condition = Condition( - "p_value_greater_or_equal_to", - [threshold], + condition: Condition = Condition.build_condition( lambda value: Success( f"P-Value {value.array[1]} is greater or equal to {threshold}" ) diff --git a/demo/scenarios/values/string.py b/demo/scenarios/values/string.py index 24571efa..6b7647b1 100644 --- a/demo/scenarios/values/string.py +++ b/demo/scenarios/values/string.py @@ -34,9 +34,7 @@ def deserialize( @classmethod def contains(cls, substring: str) -> Condition: """Checks if the p-value for multiple ranksums is below given threshold.""" - condition: Condition = Condition( - "contains", - [substring], + condition: Condition = Condition.build_condition( lambda value: Success( f"Substring '{substring}' is contained in the string value." ) @@ -50,9 +48,7 @@ def contains(cls, substring: str) -> Condition: @classmethod def equal_to(cls, other_string: str) -> Condition: """Checks if the p-value for multiple ranksums is below given threshold.""" - condition: Condition = Condition( - "equal_to", - [other_string], + condition: Condition = Condition.build_condition( lambda value: Success( f"String '{other_string}' is equal to the internal string value." )