def create_min_max_rescaler(original_min_max, target_min_max):
    """
    Min max rescaler creator. Creates a rescaler that rescales from target range into original range.
    :param original_min_max: tuple of floats, the range of values that is rescaled to
    :param target_min_max: tuple of floats, the range of value used to input to the rescaler
    :return: function, the created min_max_rescaler
    """
    o_min = min(original_min_max)
    o_max = max(original_min_max)
    t_min = min(target_min_max)
    t_max = max(target_min_max)

    def min_max_rescaler(x):
        if (t_min > x) or (x > t_max):
            raise ValueError("x is not within the min and max range of the rescaler. "
                             "\n min/max: {}-{}"
                             "\n x: {}".format(t_min, t_max, x))

        return ((o_max - o_min) * (x - t_min)) / (t_max - t_min) + o_min

    return min_max_rescaler