diff --git a/self_correction/self_corrector.py b/self_correction/self_corrector.py index c4f39c687..aa26b65a1 100644 --- a/self_correction/self_corrector.py +++ b/self_correction/self_corrector.py @@ -1,5 +1,6 @@ import random + class SelfCorrector: def __init__(self, feedback_loop, transaction_parameters): self.feedback_loop = feedback_loop @@ -10,16 +11,25 @@ def adjust_parameters(self, user_feedback=None, system_performance=None): Adjusts the transaction parameters based on user feedback or system performance. """ if user_feedback is not None: - if user_feedback == 'increase': - self.feedback_loop.add_correction(IncreaseParameterCorrection(self.transaction_parameters)) - elif user_feedback == 'decrease': - self.feedback_loop.add_correction(DecreaseParameterCorrection(self.transaction_parameters)) + if user_feedback == "increase": + self.feedback_loop.add_correction( + IncreaseParameterCorrection(self.transaction_parameters) + ) + elif user_feedback == "decrease": + self.feedback_loop.add_correction( + DecreaseParameterCorrection(self.transaction_parameters) + ) if system_performance is not None: if system_performance < 0.9: - self.feedback_loop.add_correction(IncreaseParameterCorrection(self.transaction_parameters)) + self.feedback_loop.add_correction( + IncreaseParameterCorrection(self.transaction_parameters) + ) elif system_performance > 0.95: - self.feedback_loop.add_correction(DecreaseParameterCorrection(self.transaction_parameters)) + self.feedback_loop.add_correction( + DecreaseParameterCorrection(self.transaction_parameters) + ) + class IncreaseParameterCorrection: def __init__(self, transaction_parameters): @@ -33,6 +43,7 @@ def apply(self, transaction_parameters): transaction_parameters[parameter_name] += random.uniform(0.1, 0.5) return transaction_parameters + class DecreaseParameterCorrection: def __init__(self, transaction_parameters): self.transaction_parameters = transaction_parameters