from core.explanations.validators.BaseExplanationValidator import BaseExplanationValidator


class IndividualExplanationValidator(BaseExplanationValidator):

    def __init__(self, model, label, sample, epsilon):
        super().__init__(model, label, sample.shape)

        if self.model.classify([sample]) != int(label):
            raise ValueError(f"The sample does not match the label {label}.")

        self.epsilon = epsilon

    def _get_bounds(self, sample, explanation, feature):
        if feature in explanation:
            return (sample[feature], sample[feature])
        else:
            return (sample[feature] - self.epsilon, sample[feature] + self.epsilon)
